diff --git a/src/helma/framework/core/Application.java b/src/helma/framework/core/Application.java index 1ec51dc4..1570e509 100644 --- a/src/helma/framework/core/Application.java +++ b/src/helma/framework/core/Application.java @@ -443,7 +443,7 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat nmgr.replicateCache (add, delete); } - public void ping () { + public void ping () { // do nothing } @@ -455,14 +455,6 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat nmgr.clearCache (); } - /** - * redundant method for clearCache() in order to be able to clear cache from - * self-scripting base app - would otherwise interfere with ESNode.clearCache(). - */ - public void clearAppCache () { - nmgr.clearCache (); - } - /** * Set the application's root element to an arbitrary object. After this is called * with a non-null object, the helma node manager will be bypassed. This function @@ -535,7 +527,7 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat * return the generic hopobject prototype. */ public Prototype getPrototype (Object obj) { - String protoname = getPrototypeName (obj); + String protoname = getPrototypeName (obj); if (protoname == null) return typemgr.getPrototype ("hopobject"); Prototype p = typemgr.getPrototype (protoname); @@ -680,51 +672,48 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat // FIXME: will fail for non-node roots Object root = getDataRoot (); INode users = getUserRoot (); - + // check base uri and optional root prototype from app.properties String base = props.getProperty ("baseURI"); String rootproto = props.getProperty ("rootPrototype"); - + if (base != null || baseURI == null) setBaseURI (base); - + // String href = n.getUrl (root, users, tmpname, siteroot); String divider = "/"; StringBuffer b = new StringBuffer (); Object p = elem; int loopWatch = 0; - + while (p != null && getParentElement (p) != null && p != root) { - + if (rootproto != null && rootproto.equals (getPrototypeName (p))) break; - b.insert (0, divider); - + // users always have a canonical URL like /users/username if ("user".equals (getPrototypeName (p))) { b.insert (0, URLEncoder.encode (getElementName (p))); p = users; break; } - b.insert (0, URLEncoder.encode (getElementName (p))); - p = getParentElement (p); if (loopWatch++ > 20) break; } - + if (p == users) { b.insert (0, divider); b.insert (0, "users"); } - + if (actionName != null) b.append (URLEncoder.encode (actionName)); - + return baseURI + b.toString (); } @@ -850,11 +839,11 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat return null; } - public IPathElement getParentElement() { + public IPathElement getParentElement() { return helma.main.Server.getServer(); } - public String getPrototype() { + public String getPrototype() { return "application"; } @@ -1005,10 +994,13 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat Prototype proto = (Prototype) typemgr.prototypes.get (typename); if (proto != null) { String protoname = m.getExtends (); - if (protoname == null) + // only use hopobject prototype if we're scripting HopObjects, not + // java objects. + boolean isjava = isJavaPrototype (typename); + if (protoname == null && !isjava) protoname = "hopobject"; Prototype parentProto = (Prototype) typemgr.prototypes.get (protoname); - if (parentProto == null) + if (parentProto == null && !isjava) parentProto = (Prototype) typemgr.prototypes.get ("hopobject"); if (parentProto != null) proto.setParentPrototype (parentProto); @@ -1020,6 +1012,18 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat } } + /** + * Check whether a prototype is for scripting a java class, i.e. if there's an entry + * for it in the class.properties file. + */ + protected boolean isJavaPrototype (String typename) { + for (Enumeration en = classMapping.elements(); en.hasMoreElements(); ) { + String value = (String) en.nextElement (); + if (typename.equals (value)) + return true; + } + return false; + } /** * Return a DbSource object for a given name. A DbSource is a relational database defined diff --git a/src/helma/framework/core/Prototype.java b/src/helma/framework/core/Prototype.java index 563c55c7..e2849a12 100644 --- a/src/helma/framework/core/Prototype.java +++ b/src/helma/framework/core/Prototype.java @@ -33,16 +33,16 @@ public class Prototype { Prototype parent; + // Tells us whether this prototype is used to script a generic Java object, + // as opposed to a Helma objectmodel node object. + boolean isJavaPrototype; - public Prototype (String name, Application app) { - + public Prototype (String name, Application app) { // app.logEvent ("Constructing Prototype "+app.getName()+"/"+name); - this.app = app; this.name = name; - + isJavaPrototype = app.isJavaPrototype (name); lastUpdate = 0; // System.currentTimeMillis (); - } /** @@ -52,24 +52,6 @@ public class Prototype { return app; } - /** - * Get an action defined for this prototype - */ - public Action getActionOrTemplate (String aname) { - - Action retval = null; - if (aname == null || "".equals (aname)) - aname = "main"; - retval = (Action) actions.get (aname); - // check if it's allowed to access templates via URL - // this should be cached in the future - if (retval == null && "true".equalsIgnoreCase (app.props.getProperty ("exposetemplates"))) - retval = (Action) templates.get (aname); - // if still not found, check if the action is defined for the generic node prototype - if (retval == null && parent != null) - retval = parent.getActionOrTemplate (aname); - return retval; - } /** * Set the parent prototype of this prototype, i.e. the prototype this one inherits from. @@ -167,7 +149,10 @@ public class Prototype { } } if (!"global".equalsIgnoreCase (name) && !"hopobject".equalsIgnoreCase (name) && opp == null) { - opp = reval.esNodePrototype; + if (isJavaPrototype) + opp = reval.esObjectPrototype; + else + opp = reval.esNodePrototype; } if ("user".equalsIgnoreCase (name)) {