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