jakarta-bsf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r589413 - in /jakarta/bsf/trunk/bsf3: bsf-utils/src/main/java/org/apache/bsf/xml/ bsf-utils/src/main/java/org/mozilla/ bsf-utils/src/main/java/org/mozilla/javascript/ testing/e4x-1.6R7-Axiom/src/test/java/org/apache/bsf/testing/e4x/ testing...
Date Sun, 28 Oct 2007 20:25:29 GMT
Author: antelder
Date: Sun Oct 28 13:25:25 2007
New Revision: 589413

URL: http://svn.apache.org/viewvc?rev=589413&view=rev
Log:
Update to support initialization of axiom e4x. need to find a better way to do this

Added:
    jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/
    jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/javascript/
      - copied from r589346, jakarta/bsf/trunk/bsf3/testing/e4x-1.6R7-Axiom/src/test/java/org/mozilla/javascript/
Removed:
    jakarta/bsf/trunk/bsf3/testing/e4x-1.6R7-Axiom/src/test/java/org/mozilla/
Modified:
    jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XAxiomHelper.java
    jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XHelper.java
    jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/XMLHelper.java
    jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/javascript/ContextHelper.java
    jakarta/bsf/trunk/bsf3/testing/e4x-1.6R7-Axiom/src/test/java/org/apache/bsf/testing/e4x/HelloTestCase.java

Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XAxiomHelper.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XAxiomHelper.java?rev=589413&r1=589412&r2=589413&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XAxiomHelper.java
(original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XAxiomHelper.java
Sun Oct 28 13:25:25 2007
@@ -24,6 +24,7 @@
 import org.apache.axiom.om.OMElement;
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.ContextFactory;
+import org.mozilla.javascript.ContextHelper;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
 import org.mozilla.javascript.xml.XMLLib;
@@ -36,15 +37,6 @@
 
 	private Scriptable scope;
 
-    class AxiomE4XContextFactory extends ContextFactory {
-
-        protected XMLLib.Factory getE4xImplementationFactory() {
-            return org.mozilla.javascript.xml.XMLLib.Factory.create(
-                    "org.wso2.javascript.xmlimpl.XMLLibImpl"
-            );
-        }
-    }
-
     JavaScriptE4XAxiomHelper(ScriptEngine engine) {
 
     	// tell Rhino to use Axiom E4X impl
@@ -71,7 +63,9 @@
             return null;
         }
 
-        return (OMElement) ScriptableObject.callMethod( (Scriptable) scriptXML, "getXmlObject",
new Object[0]);
+        Object o = ScriptableObject.callMethod( (Scriptable) scriptXML, "getXmlObject", new
Object[0]);
+        return (OMElement) o;
+//        return (OMElement) ScriptableObject.callMethod( (Scriptable) scriptXML, "getXmlObject",
new Object[0]);
 	}
 
 	public Object toScriptXML(OMElement om) throws ScriptException {
@@ -81,6 +75,9 @@
         Context cx = Context.enter();
         try {
 
+        	// TODO: why is this needed? A bug in axiom-e4x?
+	      	ContextHelper.setTopCallScope(cx, scope);
+
            return cx.newObject(scope, "XML", new Object[]{om});
 
         } finally {
@@ -88,4 +85,18 @@
         }
 	}
 
+	public static void init() {
+	    ContextFactory.initGlobal(new AxiomE4XContextFactory());
+	}
+}
+
+class AxiomE4XContextFactory extends ContextFactory {
+
+    protected XMLLib.Factory getE4xImplementationFactory() {
+        return org.mozilla.javascript.xml.XMLLib.Factory.create(
+                "org.wso2.javascript.xmlimpl.XMLLibImpl"
+        );
+    }
 }
+
+

Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XHelper.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XHelper.java?rev=589413&r1=589412&r2=589413&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XHelper.java
(original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XHelper.java
Sun Oct 28 13:25:25 2007
@@ -31,7 +31,7 @@
 			Class.forName("org.wso2.javascript.xmlimpl.XMLLibImpl", true, JavaScriptE4XHelper.class.getClassLoader());
 			return new JavaScriptE4XAxiomHelper(engine);
 		} catch (ClassNotFoundException e) {
-			// TODO: support Rhino 1.6R7 DOM based E4X impl 
+			// TODO: also support Rhino 1.6R7 DOM based E4X impl 
 			return new JavaScriptE4XXmlBeansHelper(engine);
 		}
 	}

Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/XMLHelper.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/XMLHelper.java?rev=589413&r1=589412&r2=589413&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/XMLHelper.java (original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/XMLHelper.java Sun Oct
28 13:25:25 2007
@@ -32,8 +32,20 @@
  */
 public abstract class XMLHelper {
 
+	/**
+	 * Register axiom-e4x if its available
+	 * @deprecated temp approach for beta2 release
+	 */
+	public static void init() {
+		try {
+			Class.forName("org.wso2.javascript.xmlimpl.XMLLibImpl", true, JavaScriptE4XHelper.class.getClassLoader());
+			JavaScriptE4XAxiomHelper.init();
+		} catch (ClassNotFoundException e) {
+		}
+	}
+
 	public static XMLHelper getArgHelper(ScriptEngine engine) {
-		// TODO: better discovery mechanisim than hardcoded class names 
+		// TODO: better discovery mechanisim than hardcoded class names
 		if (engine == null) {
 			return null;
 		}

Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/javascript/ContextHelper.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/javascript/ContextHelper.java?rev=589413&r1=589346&r2=589413&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/javascript/ContextHelper.java
(original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/javascript/ContextHelper.java
Sun Oct 28 13:25:25 2007
@@ -29,7 +29,9 @@
 public class ContextHelper {
 	
 	public static void setTopCallScope(Context cx, Scriptable scope) {
-		cx.topCallScope = scope;
+		if (cx.topCallScope == null) {
+			cx.topCallScope = scope;
+		}
 	}
 
 }

Modified: jakarta/bsf/trunk/bsf3/testing/e4x-1.6R7-Axiom/src/test/java/org/apache/bsf/testing/e4x/HelloTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/testing/e4x-1.6R7-Axiom/src/test/java/org/apache/bsf/testing/e4x/HelloTestCase.java?rev=589413&r1=589412&r2=589413&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/testing/e4x-1.6R7-Axiom/src/test/java/org/apache/bsf/testing/e4x/HelloTestCase.java
(original)
+++ jakarta/bsf/trunk/bsf3/testing/e4x-1.6R7-Axiom/src/test/java/org/apache/bsf/testing/e4x/HelloTestCase.java
Sun Oct 28 13:25:25 2007
@@ -35,16 +35,18 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.bsf.xml.XMLHelper;
-import org.mozilla.javascript.Context;
-import org.mozilla.javascript.ContextHelper;
 
 /**
  * Tests a basic JavaScrip/E4X invocation
  */
 public class HelloTestCase extends TestCase {
-	
+
 	private XMLHelper xmlHelper;
 	private ScriptEngine engine;
+	
+	static {
+        XMLHelper.init();
+	}
 
 	public void testInvokeFunctionInXML() throws ScriptException, XMLStreamException, FactoryConfigurationError,
NoSuchMethodException {
 		engine.eval("function isXML(xml) { return typeof xml == 'xml'; }" );
@@ -91,11 +93,6 @@
     protected void setUp() {
         engine = new ScriptEngineManager().getEngineByExtension("js");
         xmlHelper = XMLHelper.getArgHelper(engine);
-        Context cx = Context.enter();
-      	ContextHelper.setTopCallScope(cx, cx.initStandardObjects());
     }
 
-    protected void tearDown() {
-        Context.exit();
-    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-dev-help@jakarta.apache.org


Mime
View raw message