Various fixes and advancements in JavaObject and GlobalObject.
This commit is contained in:
parent
1ea945f82a
commit
534bba3d69
4 changed files with 28 additions and 22 deletions
|
@ -40,7 +40,7 @@ public class GlobalObject extends ScriptableObject {
|
|||
*
|
||||
* @throws PropertyException ...
|
||||
*/
|
||||
public GlobalObject(RhinoCore core, Application app)
|
||||
public GlobalObject(RhinoCore core, Application app, Context cx)
|
||||
throws PropertyException {
|
||||
this.core = core;
|
||||
this.app = app;
|
||||
|
@ -52,8 +52,8 @@ public class GlobalObject extends ScriptableObject {
|
|||
};
|
||||
|
||||
defineFunctionProperties(globalFuncs, GlobalObject.class, 0);
|
||||
put("app", this, new ApplicationBean(app));
|
||||
put("Xml", this, new XmlObject(core));
|
||||
put("app", this, cx.toObject(new ApplicationBean(app), this));
|
||||
put("Xml", this, cx.toObject(new XmlObject(core), this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,7 +58,7 @@ public class HopObject extends ScriptableObject {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a new HopObject object.
|
||||
* Creates a new HopObject prototype.
|
||||
*
|
||||
* @param cname ...
|
||||
*/
|
||||
|
@ -66,14 +66,10 @@ public class HopObject extends ScriptableObject {
|
|||
className = cname;
|
||||
}
|
||||
|
||||
// public void jsConstructor () {
|
||||
|
||||
/* Context cx = Context.getCurrentContext ();
|
||||
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal ("engine");
|
||||
core = engine.core;
|
||||
node = new helma.objectmodel.db.Node (null, null, core.app.getWrappedNodeManager ()); */
|
||||
|
||||
// }
|
||||
/**
|
||||
* This method is used as HopObject constructor from JavaScript.
|
||||
*/
|
||||
public static Object hopObjectConstructor(Context cx, Object[] args,
|
||||
Function ctorObj, boolean inNewExpr) {
|
||||
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
||||
|
|
|
@ -39,10 +39,11 @@ public class JavaObject extends NativeJavaObject {
|
|||
/**
|
||||
* Creates a new JavaObject wrapper.
|
||||
*/
|
||||
public JavaObject(Scriptable scope, Object obj, Scriptable prototype) {
|
||||
public JavaObject(Scriptable scope, Object obj, Scriptable prototype, RhinoCore core) {
|
||||
this.parent = scope;
|
||||
this.javaObject = obj;
|
||||
this.prototype = prototype;
|
||||
this.core = core;
|
||||
staticType = obj.getClass();
|
||||
initMembers();
|
||||
}
|
||||
|
@ -56,7 +57,7 @@ public class JavaObject extends NativeJavaObject {
|
|||
*
|
||||
* @return ...
|
||||
*/
|
||||
public boolean jsFunction_renderSkin(Object skin, Object param) {
|
||||
public boolean renderSkin(Object skin, Object param) {
|
||||
// System.err.println ("RENDERSKIN CALLED WITH PARAM "+param);
|
||||
Context cx = Context.getCurrentContext();
|
||||
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
||||
|
@ -97,8 +98,8 @@ public class JavaObject extends NativeJavaObject {
|
|||
*
|
||||
* @return ...
|
||||
*/
|
||||
public String jsFunction_renderSkinAsString(Object skin, Object param) {
|
||||
// System.err.println ("RENDERSKIN CALLED WITH PARAM "+param);
|
||||
public String renderSkinAsString(Object skin, Object param) {
|
||||
// System.err.println ("RENDERSKINASSTRING CALLED WITH skin "+skin);
|
||||
Context cx = Context.getCurrentContext();
|
||||
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
||||
Skin s;
|
||||
|
@ -140,7 +141,7 @@ public class JavaObject extends NativeJavaObject {
|
|||
*
|
||||
* @return ...
|
||||
*/
|
||||
public Object jsFunction_href(Object action) {
|
||||
public Object href(Object action) {
|
||||
if (javaObject == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -159,18 +160,27 @@ public class JavaObject extends NativeJavaObject {
|
|||
}
|
||||
|
||||
public boolean has(String name, Scriptable start) {
|
||||
System.err.println ("HAS: "+name);
|
||||
// System.err.println ("HAS: "+name);
|
||||
if (prototype.has(name, start))
|
||||
return true;
|
||||
return super.has(name, start);
|
||||
}
|
||||
|
||||
public Object get(String name, Scriptable start) {
|
||||
System.err.println ("GET: "+name);
|
||||
// System.err.println ("GET: "+name);
|
||||
Object obj = prototype.get(name, start);
|
||||
if (obj != null && obj != Undefined.instance)
|
||||
if (obj != null && obj != UniqueTag.NOT_FOUND)
|
||||
return obj;
|
||||
return super.get(name, start);
|
||||
|
||||
Method[] m = JavaObject.class.getMethods();
|
||||
for (int i=0; i<m.length; i++) {
|
||||
if (name.equals(m[i].getName())) {
|
||||
obj = new FunctionObject(name, m[i], this);
|
||||
// System.err.println ("GOT: "+obj);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
return super.get(name, start);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public final class RhinoCore implements WrapHandler {
|
|||
context.setOptimizationLevel(optLevel);
|
||||
|
||||
try {
|
||||
GlobalObject g = new GlobalObject(this, app);
|
||||
GlobalObject g = new GlobalObject(this, app, context);
|
||||
|
||||
global = context.initStandardObjects(g);
|
||||
ScriptableObject.defineClass(global, HopObject.class);
|
||||
|
@ -554,7 +554,7 @@ public final class RhinoCore implements WrapHandler {
|
|||
op = getPrototype("hopobject");
|
||||
}
|
||||
|
||||
return new JavaObject(global, e, op);
|
||||
return new JavaObject(global, e, op, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue