From bebce2ad3d4dfe019d659eb5db0920bbf0f24d24 Mon Sep 17 00:00:00 2001 From: hns Date: Thu, 7 Aug 2003 11:26:44 +0000 Subject: [PATCH] Make HopObject implement the Rhino Wrapper interface. Replace NativeJavaObject with Wrapper when unwrapping wrapped Java objects. --- src/helma/scripting/rhino/GlobalObject.java | 8 ++++---- src/helma/scripting/rhino/HopObject.java | 22 ++++++++++++--------- src/helma/scripting/rhino/JavaObject.java | 4 ++-- src/helma/scripting/rhino/MapWrapper.java | 10 +++++----- src/helma/scripting/rhino/RhinoCore.java | 18 ++++++++--------- src/helma/scripting/rhino/RhinoEngine.java | 10 ++++------ 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/helma/scripting/rhino/GlobalObject.java b/src/helma/scripting/rhino/GlobalObject.java index 0a9b0e7e..6787e4c9 100644 --- a/src/helma/scripting/rhino/GlobalObject.java +++ b/src/helma/scripting/rhino/GlobalObject.java @@ -295,8 +295,8 @@ public class GlobalObject extends ScriptableObject { public Object getXmlDocument(Object src) { try { Object p = src; - if (p instanceof NativeJavaObject) { - p = ((NativeJavaObject) p).unwrap(); + if (p instanceof Wrapper) { + p = ((Wrapper) p).unwrap(); } Object doc = XmlUtils.parseXml(p); @@ -315,8 +315,8 @@ public class GlobalObject extends ScriptableObject { public Object getHtmlDocument(Object src) { try { Object p = src; - if (p instanceof NativeJavaObject) { - p = ((NativeJavaObject) p).unwrap(); + if (p instanceof Wrapper) { + p = ((Wrapper) p).unwrap(); } Object doc = helma.util.XmlUtils.parseHtml(p); diff --git a/src/helma/scripting/rhino/HopObject.java b/src/helma/scripting/rhino/HopObject.java index 8df2129a..c4fd7d3a 100644 --- a/src/helma/scripting/rhino/HopObject.java +++ b/src/helma/scripting/rhino/HopObject.java @@ -34,7 +34,7 @@ import java.util.Map; /** * */ -public class HopObject extends ScriptableObject { +public class HopObject extends ScriptableObject implements Wrapper { static Method hopObjCtor; static { @@ -152,6 +152,14 @@ public class HopObject extends ScriptableObject { return node; } + /** + * Returns the wrapped Node. Implements unwrap() in interface Wrapper. + * + */ + public Object unwrap() { + return node; + } + /** * * @@ -241,8 +249,8 @@ public class HopObject extends ScriptableObject { String act = null; if (action != null) { - if (action instanceof NativeJavaObject) { - act = ((NativeJavaObject) action).unwrap().toString(); + if (action instanceof Wrapper) { + act = ((Wrapper) action).unwrap().toString(); } else if (!(action instanceof Undefined)) { act = action.toString(); } @@ -465,8 +473,8 @@ public class HopObject extends ScriptableObject { node.setSubnodeRelation(value == null ? null : value.toString()); } - if (value instanceof NativeJavaObject) { - value = ((NativeJavaObject) value).unwrap(); + if (value instanceof Wrapper) { + value = ((Wrapper) value).unwrap(); } if ((value == null) || (value == Undefined.instance)) { @@ -480,8 +488,6 @@ public class HopObject extends ScriptableObject { node.setString(name, ScriptRuntime.toString(s)); } else if (s instanceof MapWrapper) { node.setJavaObject(name, ((MapWrapper) s).unwrap()); - } else if (s instanceof HopObject) { - node.setNode(name, ((HopObject) value).node); } else { node.setJavaObject(name, s); } @@ -495,8 +501,6 @@ public class HopObject extends ScriptableObject { node.setDate(name, (Date) value); } else if (value instanceof INode) { node.setNode(name, (INode) value); - } else if (value instanceof HopObject) { - node.setNode(name, ((HopObject) value).node); } else { node.setJavaObject(name, value); } diff --git a/src/helma/scripting/rhino/JavaObject.java b/src/helma/scripting/rhino/JavaObject.java index 1cdb854f..8dbedf8b 100644 --- a/src/helma/scripting/rhino/JavaObject.java +++ b/src/helma/scripting/rhino/JavaObject.java @@ -142,8 +142,8 @@ public class JavaObject extends NativeJavaObject { String act = null; if (action != null) { - if (action instanceof NativeJavaObject) { - act = ((NativeJavaObject) action).unwrap().toString(); + if (action instanceof Wrapper) { + act = ((Wrapper) action).unwrap().toString(); } else if (!(action instanceof Undefined)) { act = action.toString(); } diff --git a/src/helma/scripting/rhino/MapWrapper.java b/src/helma/scripting/rhino/MapWrapper.java index db1dacc1..2f6a6bcf 100644 --- a/src/helma/scripting/rhino/MapWrapper.java +++ b/src/helma/scripting/rhino/MapWrapper.java @@ -19,7 +19,7 @@ package helma.scripting.rhino; import org.mozilla.javascript.Context; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; -import org.mozilla.javascript.NativeJavaObject; +import org.mozilla.javascript.Wrapper; import java.util.HashMap; import java.util.Map; @@ -59,8 +59,8 @@ public class MapWrapper extends ScriptableObject { if (map == null) { map = new HashMap(); } - if (value instanceof NativeJavaObject) { - map.put(name, ((NativeJavaObject) value).unwrap()); + if (value instanceof Wrapper) { + map.put(name, ((Wrapper) value).unwrap()); } else { map.put(name, value); } @@ -126,8 +126,8 @@ public class MapWrapper extends ScriptableObject { if (map == null) { map = new HashMap(); } - if (value instanceof NativeJavaObject) { - map.put(Integer.toString(idx), ((NativeJavaObject) value).unwrap()); + if (value instanceof Wrapper) { + map.put(Integer.toString(idx), ((Wrapper) value).unwrap()); } else { map.put(Integer.toString(idx), value); } diff --git a/src/helma/scripting/rhino/RhinoCore.java b/src/helma/scripting/rhino/RhinoCore.java index c1e100a0..b1ffdd7d 100644 --- a/src/helma/scripting/rhino/RhinoCore.java +++ b/src/helma/scripting/rhino/RhinoCore.java @@ -53,7 +53,7 @@ public final class RhinoCore { long lastUpdate = 0; // the wrap factory - Wrapper wrapper; + WrapFactory wrapper; // the prototype for path objects PathWrapper pathProto; @@ -70,7 +70,7 @@ public final class RhinoCore { Context context = Context.enter(); context.setCompileFunctionsWithDynamicScope(true); - wrapper = new Wrapper(); + wrapper = new WrapMaker(); context.setWrapFactory(wrapper); int optLevel = 0; @@ -466,8 +466,8 @@ public final class RhinoCore { * convert a JavaScript Object object to a generic Java object stucture. */ public Object processXmlRpcResponse (Object what) throws Exception { - if (what instanceof NativeJavaObject) { - what = ((NativeJavaObject) what).unwrap(); + if (what instanceof Wrapper) { + what = ((Wrapper) what).unwrap(); } if (what instanceof NativeObject) { NativeObject no = (NativeObject) what; @@ -607,8 +607,8 @@ public final class RhinoCore { for (int i=0; i