Scripted Java objects now have a prototype that only has the
href() and renderSkin() functions, without all the other functions in Helma objectmodel Nodes that don't apply to Java objects. This was a problem because it "covered" methods in the Java objects with the same name, e.g. list(), delete() etc.
This commit is contained in:
parent
f3ea5d79a2
commit
c56befd4d4
2 changed files with 39 additions and 50 deletions
|
@ -443,7 +443,7 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat
|
||||||
nmgr.replicateCache (add, delete);
|
nmgr.replicateCache (add, delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ping () {
|
public void ping () {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,14 +455,6 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat
|
||||||
nmgr.clearCache ();
|
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
|
* 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
|
* 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.
|
* return the generic hopobject prototype.
|
||||||
*/
|
*/
|
||||||
public Prototype getPrototype (Object obj) {
|
public Prototype getPrototype (Object obj) {
|
||||||
String protoname = getPrototypeName (obj);
|
String protoname = getPrototypeName (obj);
|
||||||
if (protoname == null)
|
if (protoname == null)
|
||||||
return typemgr.getPrototype ("hopobject");
|
return typemgr.getPrototype ("hopobject");
|
||||||
Prototype p = typemgr.getPrototype (protoname);
|
Prototype p = typemgr.getPrototype (protoname);
|
||||||
|
@ -680,51 +672,48 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat
|
||||||
// FIXME: will fail for non-node roots
|
// FIXME: will fail for non-node roots
|
||||||
Object root = getDataRoot ();
|
Object root = getDataRoot ();
|
||||||
INode users = getUserRoot ();
|
INode users = getUserRoot ();
|
||||||
|
|
||||||
// check base uri and optional root prototype from app.properties
|
// check base uri and optional root prototype from app.properties
|
||||||
String base = props.getProperty ("baseURI");
|
String base = props.getProperty ("baseURI");
|
||||||
String rootproto = props.getProperty ("rootPrototype");
|
String rootproto = props.getProperty ("rootPrototype");
|
||||||
|
|
||||||
if (base != null || baseURI == null)
|
if (base != null || baseURI == null)
|
||||||
setBaseURI (base);
|
setBaseURI (base);
|
||||||
|
|
||||||
// String href = n.getUrl (root, users, tmpname, siteroot);
|
// String href = n.getUrl (root, users, tmpname, siteroot);
|
||||||
|
|
||||||
String divider = "/";
|
String divider = "/";
|
||||||
StringBuffer b = new StringBuffer ();
|
StringBuffer b = new StringBuffer ();
|
||||||
Object p = elem;
|
Object p = elem;
|
||||||
int loopWatch = 0;
|
int loopWatch = 0;
|
||||||
|
|
||||||
while (p != null && getParentElement (p) != null && p != root) {
|
while (p != null && getParentElement (p) != null && p != root) {
|
||||||
|
|
||||||
if (rootproto != null && rootproto.equals (getPrototypeName (p)))
|
if (rootproto != null && rootproto.equals (getPrototypeName (p)))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
b.insert (0, divider);
|
b.insert (0, divider);
|
||||||
|
|
||||||
// users always have a canonical URL like /users/username
|
// users always have a canonical URL like /users/username
|
||||||
if ("user".equals (getPrototypeName (p))) {
|
if ("user".equals (getPrototypeName (p))) {
|
||||||
b.insert (0, URLEncoder.encode (getElementName (p)));
|
b.insert (0, URLEncoder.encode (getElementName (p)));
|
||||||
p = users;
|
p = users;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
b.insert (0, URLEncoder.encode (getElementName (p)));
|
b.insert (0, URLEncoder.encode (getElementName (p)));
|
||||||
|
|
||||||
p = getParentElement (p);
|
p = getParentElement (p);
|
||||||
|
|
||||||
if (loopWatch++ > 20)
|
if (loopWatch++ > 20)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p == users) {
|
if (p == users) {
|
||||||
b.insert (0, divider);
|
b.insert (0, divider);
|
||||||
b.insert (0, "users");
|
b.insert (0, "users");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionName != null)
|
if (actionName != null)
|
||||||
b.append (URLEncoder.encode (actionName));
|
b.append (URLEncoder.encode (actionName));
|
||||||
|
|
||||||
return baseURI + b.toString ();
|
return baseURI + b.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,11 +839,11 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPathElement getParentElement() {
|
public IPathElement getParentElement() {
|
||||||
return helma.main.Server.getServer();
|
return helma.main.Server.getServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrototype() {
|
public String getPrototype() {
|
||||||
return "application";
|
return "application";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1005,10 +994,13 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat
|
||||||
Prototype proto = (Prototype) typemgr.prototypes.get (typename);
|
Prototype proto = (Prototype) typemgr.prototypes.get (typename);
|
||||||
if (proto != null) {
|
if (proto != null) {
|
||||||
String protoname = m.getExtends ();
|
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";
|
protoname = "hopobject";
|
||||||
Prototype parentProto = (Prototype) typemgr.prototypes.get (protoname);
|
Prototype parentProto = (Prototype) typemgr.prototypes.get (protoname);
|
||||||
if (parentProto == null)
|
if (parentProto == null && !isjava)
|
||||||
parentProto = (Prototype) typemgr.prototypes.get ("hopobject");
|
parentProto = (Prototype) typemgr.prototypes.get ("hopobject");
|
||||||
if (parentProto != null)
|
if (parentProto != null)
|
||||||
proto.setParentPrototype (parentProto);
|
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
|
* Return a DbSource object for a given name. A DbSource is a relational database defined
|
||||||
|
|
|
@ -33,16 +33,16 @@ public class Prototype {
|
||||||
|
|
||||||
Prototype parent;
|
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);
|
// app.logEvent ("Constructing Prototype "+app.getName()+"/"+name);
|
||||||
|
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
isJavaPrototype = app.isJavaPrototype (name);
|
||||||
lastUpdate = 0; // System.currentTimeMillis ();
|
lastUpdate = 0; // System.currentTimeMillis ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,24 +52,6 @@ public class Prototype {
|
||||||
return app;
|
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.
|
* 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) {
|
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)) {
|
if ("user".equalsIgnoreCase (name)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue