You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by va...@apache.org on 2008/10/22 00:01:58 UTC

svn commit: r706794 - in /ode/trunk: ./ extensions/e4x/src/main/java/org/apache/ode/extension/e4x/ extensions/e4x/src/test/java/org/apache/ode/extension/e4x/ extensions/e4x/src/test/resources/ extensions/e4x/src/test/resources/bpel/TestE4X/ extensions/...

Author: vanto
Date: Tue Oct 21 15:01:58 2008
New Revision: 706794

URL: http://svn.apache.org/viewvc?rev=706794&view=rev
Log:
E4X extension updated.

Added:
    ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/TopLevelFunctions.java
    ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/VariableDelegator.java
    ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/
    ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/TestE4XDirect.bpel
    ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/TestE4XDirect.wsdl
    ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/deploy.xml
    ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/test.properties
    ode/trunk/extensions/e4x/src/test/resources/test.js
Removed:
    ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/ExtensionContextWrapper.java
Modified:
    ode/trunk/Rakefile
    ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/JSExtensionOperation.java
    ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSBPELTest.java
    ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSOperationTest.java
    ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4X/TestE4X.bpel

Modified: ode/trunk/Rakefile
URL: http://svn.apache.org/viewvc/ode/trunk/Rakefile?rev=706794&r1=706793&r2=706794&view=diff
==============================================================================
--- ode/trunk/Rakefile (original)
+++ ode/trunk/Rakefile Tue Oct 21 15:01:58 2008
@@ -545,9 +545,9 @@
 
   desc "E4X Extension"
   define "e4x", :version=>"1.0-beta" do
-    compile.with "rhino:js:jar:1.6R7", projects("ode:bpel-api", "ode:runtimes", "ode:engine", 
+    compile.with "rhino:js:jar:1.7R1", COMMONS.logging, projects("ode:bpel-api", "ode:runtimes", "ode:engine", 
                  "ode:bpel-compiler", "ode:utils")
-    test.with "rhino:js:jar:1.6R7", projects("ode:bpel-api", "ode:runtimes", "ode:jacob", "ode:bpel-schemas",
+    test.with "rhino:js:jar:1.7R1", projects("ode:bpel-api", "ode:runtimes", "ode:jacob", "ode:bpel-schemas",
               "ode:bpel-scripts", "ode:scheduler-simple", "ode:bpel-test", "ode:utils", "ode:bpel-compiler",
               "ode:bpel-dao", "ode:engine", "ode:bpel-store", "ode:il-common", "ode:dao-jpa"),
               COMMONS.collections, COMMONS.lang, COMMONS.logging, DERBY, JAVAX.connector,

Modified: ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/JSExtensionOperation.java
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/JSExtensionOperation.java?rev=706794&r1=706793&r2=706794&view=diff
==============================================================================
--- ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/JSExtensionOperation.java (original)
+++ ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/JSExtensionOperation.java Tue Oct 21 15:01:58 2008
@@ -20,13 +20,14 @@
 
 import javax.xml.namespace.QName;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.ode.bpel.common.FaultException;
 import org.apache.ode.bpel.rtrep.common.extension.AbstractSyncExtensionOperation;
 import org.apache.ode.bpel.rtrep.common.extension.ExtensionContext;
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.ContextFactory;
 import org.mozilla.javascript.Scriptable;
-import org.mozilla.javascript.ScriptableObject;
 import org.mozilla.javascript.xml.XMLLib;
 import org.mozilla.javascript.xml.XMLLib.Factory;
 import org.w3c.dom.Element;
@@ -37,19 +38,27 @@
  * @author Tammo van Lessen (University of Stuttgart)
  */
 public class JSExtensionOperation extends AbstractSyncExtensionOperation {
+	private static final Log __logger = LogFactory.getLog(JSExtensionOperation.class);
 	
 	public void runSync(ExtensionContext context, Element element) throws FaultException {
-
 		CustomContextFactory.init();
-		Context ctx = Context.enter();
+        Context ctx = ContextFactory.getGlobal().enterContext();
+        ctx.setOptimizationLevel(-1);
+        ctx.setGeneratingDebug(false);
+        ctx.setGeneratingSource(false);
+        ctx.setDebugger(null, null);
+        
 		try {
-			Scriptable scope = ctx.initStandardObjects();
-			ScriptableObject.defineClass(scope, ExtensionContextWrapper.class);
-			Scriptable wrappedContext = ctx.newObject(scope, "ExtensionContext", new Object[] {context, ctx});
-			ScriptableObject.putProperty(scope, "context", wrappedContext);
+			Scriptable scope = new TopLevelFunctions(context, ctx, context.getDUDir());
 			String source = element.getTextContent();
-			ctx.evaluateString(scope, source, context.getActivityName(), 1, null);
+			VariableDelegator delegator = new VariableDelegator(scope, context, ctx);
+			ctx.evaluateString(delegator, source, context.getActivityName(), 1, null);
+			delegator.writeVariables();
+		} catch (FaultException e) {
+			__logger.error("Fault during JS execution.", e);
+			throw e;
 		} catch (Exception e) {
+			__logger.error("Error during JS execution.", e);
 			throw new FaultException(new QName("ExtensionEvaluationFault", JSExtensionBundle.NS), e.getMessage());
 		} finally {
 			Context.exit();
@@ -67,6 +76,5 @@
 				ContextFactory.initGlobal(new CustomContextFactory());
 			}
 		}
-		
 	}
 }

Added: ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/TopLevelFunctions.java
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/TopLevelFunctions.java?rev=706794&view=auto
==============================================================================
--- ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/TopLevelFunctions.java (added)
+++ ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/TopLevelFunctions.java Tue Oct 21 15:01:58 2008
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.extension.e4x;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URI;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.ode.bpel.rtrep.common.extension.ExtensionContext;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Function;
+import org.mozilla.javascript.ImporterTopLevel;
+import org.mozilla.javascript.NativeJavaObject;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.xml.XMLObject;
+import org.mozilla.javascript.xmlimpl.XMLLibImpl;
+import org.w3c.dom.Node;
+
+/**
+ * Provides (global) top-level functions like "print" and
+ * "load" to our JS/E4X environment.
+ * 
+ * @author Tammo van Lessen (University of Stuttgart)
+ */
+public class TopLevelFunctions extends ImporterTopLevel {
+	private static final long serialVersionUID = 1L;
+	private static final String[] METHODS = { "load", "print", "pid", "js2dom", "dom2js" };
+	private URI _duDir;
+	private ExtensionContext _ectx;
+	
+	public TopLevelFunctions(ExtensionContext ectx, Context cx, URI duDir) throws Exception {
+		super(cx);
+		this._duDir = duDir;
+		this._ectx = ectx;
+		
+		// define toplevel functions
+		defineFunctionProperties(METHODS, TopLevelFunctions.class,
+				ScriptableObject.DONTENUM);
+		
+		// register _context object
+		ScriptableObject.putProperty(this, "_context", _ectx);
+	}
+
+	/**
+	 * Allows printing debug output to the console. Output will be redirected
+	 * to the logger associated with <code>org.apache.ode.extension.e4x.JavaScriptConsole</code>.
+	 * The target log level is INFO.
+	 */
+	public static void print(Context cx, Scriptable thisObj, Object[] args,
+			Function funObj) {
+		StringBuilder sb = new StringBuilder();
+		for (int i = 0; i < args.length; i++) {
+			if (i > 0) {
+				sb.append(' ');
+			}
+			sb.append(Context.toString(args[i]));
+		}
+		
+		TopLevelFunctions thiz = (TopLevelFunctions) getTopLevelScope(thisObj);
+		thiz._ectx.printToConsole(sb.toString());
+	}
+
+	/**
+	 * This methods is exposed to the JS environment and supports loading
+	 * JavaScript libraries from the deployment unit directory. 
+	 */
+	public static void load(Context cx, Scriptable thisObj, Object[] args,
+			Function funObj) {
+		TopLevelFunctions thiz = (TopLevelFunctions) getTopLevelScope(thisObj);
+        for (int i = 0; i < args.length; i++) {
+            // Assumes resource's path is given relative to the service archive
+        	URI uri = thiz._duDir.resolve(Context.toString(args[i]));
+        	try {
+				InputStream is = uri.toURL().openStream();
+				cx.evaluateReader(thiz, new InputStreamReader(is), "<importJS>", 1, null);
+			} catch (MalformedURLException e) {
+				throw Context.throwAsScriptRuntimeEx(e);
+			} catch (IOException e) {
+				throw Context.throwAsScriptRuntimeEx(e);
+			}
+        }
+	}
+	
+	/**
+	 * This method is exposed to the JS environment and returns the process
+	 * instance ID of the running PI.
+	 */
+	public static long pid(Context cx, Scriptable thisObj, Object[] args,
+			Function funObj) {
+		TopLevelFunctions thiz = (TopLevelFunctions) getTopLevelScope(thisObj);
+		return thiz._ectx.getProcessId();
+	}
+
+	/**
+	 * This method is exposed to the JS environment and returns the activity 
+	 * name of the running PI.
+	 */
+	public static String activityName(Context cx, Scriptable thisObj, Object[] args,
+			Function funObj) {
+		TopLevelFunctions thiz = (TopLevelFunctions) getTopLevelScope(thisObj);
+		return thiz._ectx.getActivityName();
+	}
+
+	/**
+	 * This method is exposed to the JS environment and allows converting from
+	 * JavaScript E4X objects to W3C DOM nodes.
+	 */
+	public static Node js2dom(Context cx, Scriptable thisObj, Object[] args,
+			Function funObj) {
+		if (args.length != 1) {
+			Context.reportError("js2dom expects one E4X XML parameter");
+		}
+		return XMLLibImpl.toDomNode(args[0]); 
+	}
+	
+	/**
+	 * This method is exposed to the JS environment and allows converting from
+	 * W3C DOM nodes to JavaScript E4X objects.
+	 */
+	public static XMLObject dom2js(Context cx, Scriptable thisObj, Object[] args,
+			Function funObj) {
+		if (args.length != 1) {
+			Context.reportError("dom2js expects one org.w3c.dom.Node parameter");
+		}
+		TopLevelFunctions thiz = (TopLevelFunctions) getTopLevelScope(thisObj);
+		try {
+			Object n = args[0];
+			if (n instanceof NativeJavaObject && ((NativeJavaObject)n).unwrap() instanceof Node) {
+				n = ((NativeJavaObject)args[0]).unwrap();
+			}
+			String xml = domToString((Node)n);
+			return (XMLObject)cx.newObject(thiz, "XML", new Object[] {Context.javaToJS(xml, thiz)});
+		} catch (TransformerException e) {
+			throw Context.throwAsScriptRuntimeEx(e);
+		}
+	}
+	
+	public static String domToString(Node n) throws TransformerException {
+		TransformerFactory xformFactory	= TransformerFactory.newInstance();
+		Transformer idTransform = xformFactory.newTransformer();
+		idTransform.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+		Source input = new DOMSource(n);
+		StringWriter sw = new StringWriter();
+		Result output = new StreamResult(sw);
+		idTransform.transform(input, output);
+		return sw.toString();
+	}
+}

Added: ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/VariableDelegator.java
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/VariableDelegator.java?rev=706794&view=auto
==============================================================================
--- ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/VariableDelegator.java (added)
+++ ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/VariableDelegator.java Tue Oct 21 15:01:58 2008
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.extension.e4x;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.evar.ExternalVariableModuleException;
+import org.apache.ode.bpel.rtrep.common.extension.ExtensionContext;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Delegator;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.xml.XMLObject;
+import org.mozilla.javascript.xmlimpl.XMLLibImpl;
+import org.w3c.dom.Node;
+
+/**
+ * <code>VariableDelegator</code> is in charge of inserting BPEL variables
+ * into the JS/E4X context.
+ * 
+ * @author Tammo van Lessen (University of Stuttgart)
+ */
+public class VariableDelegator extends Delegator {
+	private static final Log __logger = LogFactory.getLog(VariableDelegator.class);
+	
+	private ExtensionContext _ectx;
+	private Context _sctx;
+	private Map<String, Object> _env = new HashMap<String, Object>();
+	private Set<String> _variables = new HashSet<String>();
+
+	public VariableDelegator(Scriptable obj, ExtensionContext ectx, Context sctx) {
+		super(obj);
+		_ectx = ectx;
+		_sctx = sctx;
+	}
+	
+	public Object get(String name, Scriptable start) {
+        // do not override variables defined in JS
+		if (super.has(name, start)) {
+        	return super.get(name, start);
+        }
+        
+		if (_env.get(name) != null) {
+	        if (__logger.isDebugEnabled()) {
+	        	__logger.debug("Reading JS variable '" + name + "'.");
+	        }
+
+			return _env.get(name);
+		}
+		
+		try {
+	        if (!_ectx.isVariableVisible(name)) { 
+	        	return ScriptableObject.NOT_FOUND;
+	        }
+	        if (__logger.isDebugEnabled()) {
+	        	__logger.debug("Reading BPEL variable '" + name + "'.");
+	        }
+			Node n = _ectx.readVariable(name);
+			XMLObject xmlObj = (XMLObject)_sctx.newObject(start, "XML", new Object[] {Context.javaToJS(TopLevelFunctions.domToString(n), start)});
+			_env.put(name, xmlObj);
+			if (_variables.contains(name)) {
+				_variables.add(name);
+			}
+			return xmlObj;
+		} catch (Exception e) {
+			throw new RuntimeException("Error accessing variable " + name + ".", e);
+		}
+	}
+
+	public boolean has(String name, Scriptable start) {
+		if (super.has(name, start) || _env.containsKey(name)) {
+        	return true;
+        }
+        
+		return (_ectx.isVariableVisible(name));
+	}
+
+	public void put(String name, Scriptable start, Object value) {
+        if (__logger.isDebugEnabled()) {
+        	__logger.debug("Setting JS variable '" + name + "' to '" + value + "'.");
+        }
+
+		_env.put(name, value);
+		if (_ectx.isVariableVisible(name) && !_variables.contains(name)) {
+			_variables.add(name);
+		}
+	}
+
+	/*
+	 * This is needed because we're actually building a nested scope and not 
+	 * purely delegating. Not sure if there's a better solution.
+	 */
+	public Scriptable getParentScope() {
+		return obj;
+	}
+
+	public void writeVariables() throws FaultException, ExternalVariableModuleException {
+		for (String varName : _variables) {
+	        if (__logger.isDebugEnabled()) {
+	        	__logger.debug("Writing BPEL variable '" + varName + "' to '" + _env.get(varName) + "'.");
+	        }
+	        //TODO: only changed variables should be written. Its currently not that easy
+	        //      to detect whether the content has changed without recursively injecting
+	        //      emcaPut implementations.
+			_ectx.writeVariable(varName, XMLLibImpl.toDomNode(_env.get(varName)));
+		}
+	}
+}

Modified: ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSBPELTest.java
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSBPELTest.java?rev=706794&r1=706793&r2=706794&view=diff
==============================================================================
--- ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSBPELTest.java (original)
+++ ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSBPELTest.java Tue Oct 21 15:01:58 2008
@@ -18,6 +18,7 @@
  */
 package org.apache.ode.extension.e4x;
 
+import org.apache.log4j.BasicConfigurator;
 import org.apache.ode.test.BPELTestAbstract;
 import org.junit.Test;
 
@@ -32,4 +33,11 @@
         go("/bpel/TestE4X");
     }
 
+	@Test public void testE4XAssignDirect() throws Throwable {
+        // Test E4X
+		BasicConfigurator.configure();
+		registerExtensionBundle(new JSExtensionBundle());
+        go("/bpel/TestE4XDirect");
+    }
+
 }

Modified: ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSOperationTest.java
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSOperationTest.java?rev=706794&r1=706793&r2=706794&view=diff
==============================================================================
--- ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSOperationTest.java (original)
+++ ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSOperationTest.java Tue Oct 21 15:01:58 2008
@@ -19,9 +19,11 @@
 package org.apache.ode.extension.e4x;
 
 
+import org.apache.log4j.BasicConfigurator;
 import org.apache.ode.test.MockExtensionContext;
 import org.apache.ode.utils.DOMUtils;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 import org.w3c.dom.Element;
 
@@ -29,12 +31,16 @@
  * @author Tammo van Lessen (University of Stuttgart)
  */
 public class JSOperationTest {
+	
+	@Before public void setup() {
+		BasicConfigurator.configure();
+	}
 
 	@Test public void testHelloWorld() throws Exception {
 		StringBuffer s = new StringBuffer();
-		s.append("var request = context.readVariable('request');\n");
+		s.append("var request = dom2js(_context.readVariable('request'));\n");
 		s.append("request.TestPart += ' World';\n");
-		s.append("context.writeVariable('request', request);\n");
+		s.append("_context.writeVariable('request', js2dom(request));\n");
 
 		MockExtensionContext c = new MockExtensionContext();
 		c.getVariables().put("request", DOMUtils.stringToDOM("<message><TestPart>Hello</TestPart></message>"));
@@ -42,18 +48,33 @@
 		Element e = DOMUtils.stringToDOM("<js:script xmlns:js=\"js\"><![CDATA[" + s + "]]></js:script>");
 		jso.run(c, e);
 		String res = DOMUtils.domToString(c.getVariables().get("request"));
-		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<message><TestPart>Hello World</TestPart></message>", res);
 		Assert.assertTrue(c.completed);
 		Assert.assertFalse(c.faulted);
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<message><TestPart>Hello World</TestPart></message>", res);
 	}
 	
+	@Test public void testHelloWorldDirect() throws Exception {
+		StringBuffer s = new StringBuffer();
+		s.append("request.TestPart += ' World';\n");
+
+		MockExtensionContext c = new MockExtensionContext();
+		c.getVariables().put("request", DOMUtils.stringToDOM("<message><TestPart>Hello</TestPart></message>"));
+		JSExtensionOperation jso = new JSExtensionOperation();
+		Element e = DOMUtils.stringToDOM("<js:script xmlns:js=\"js\"><![CDATA[" + s + "]]></js:script>");
+		jso.run(c, e);
+		String res = DOMUtils.domToString(c.getVariables().get("request"));
+		Assert.assertTrue(c.completed);
+		Assert.assertFalse(c.faulted);
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<message><TestPart>Hello World</TestPart></message>", res);
+	}
+
 	@Test public void testArrayCopy() throws Exception {
 		StringBuffer s = new StringBuffer();
-		s.append("var item = context.readVariable('item');\n");
-		s.append("var items = context.readVariable('items');\n");
+		s.append("var item = dom2js(_context.readVariable('item'));\n");
+		s.append("var items = dom2js(_context.readVariable('items'));\n");
 		s.append("items.TestPart.items.item += item.TestPart.item;\n");
 		s.append("items.TestPart.items.item.(@hyped=='true').price *= 2;");
-		s.append("context.writeVariable('items', items);\n");
+		s.append("_context.writeVariable('items', js2dom(items));\n");
 
 		MockExtensionContext c = new MockExtensionContext();
 		c.getVariables().put("item", DOMUtils.stringToDOM("<message><TestPart><item hyped=\"true\"><name>BPEL consulting</name><price>3000</price></item></TestPart></message>"));
@@ -62,9 +83,84 @@
 		Element e = DOMUtils.stringToDOM("<js:script xmlns:js=\"js\"><![CDATA[" + s + "]]></js:script>");
 		jso.run(c, e);
 		String res = DOMUtils.domToString(c.getVariables().get("items"));
+		Assert.assertTrue(c.completed);
+		Assert.assertFalse(c.faulted);
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<message><TestPart><items><item><name>WSDL consulting</name><price>2500</price></item><item hyped=\"true\"><name>BPEL consulting</name><price>6000</price></item></items></TestPart></message>", res);
+	}
+
+	@Test public void testArrayCopyDirect() throws Exception {
+		StringBuffer s = new StringBuffer();
+		s.append("items.TestPart.items.item += item.TestPart.item;\n");
+		s.append("items.TestPart.items.item.(@hyped=='true').price *= 2;");
+
+		MockExtensionContext c = new MockExtensionContext();
+		c.getVariables().put("item", DOMUtils.stringToDOM("<message><TestPart><item hyped=\"true\"><name>BPEL consulting</name><price>3000</price></item></TestPart></message>"));
+		c.getVariables().put("items", DOMUtils.stringToDOM("<message><TestPart><items><item><name>WSDL consulting</name><price>2500</price></item></items></TestPart></message>"));
+		JSExtensionOperation jso = new JSExtensionOperation();
+		Element e = DOMUtils.stringToDOM("<js:script xmlns:js=\"js\"><![CDATA[" + s + "]]></js:script>");
+		jso.run(c, e);
+		String res = DOMUtils.domToString(c.getVariables().get("items"));
+		Assert.assertTrue(c.completed);
+		Assert.assertFalse(c.faulted);
 		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<message><TestPart><items><item><name>WSDL consulting</name><price>2500</price></item><item hyped=\"true\"><name>BPEL consulting</name><price>6000</price></item></items></TestPart></message>", res);
+	}
+
+	@Test public void testVariableNotFoundDirect() throws Exception {
+		StringBuffer s = new StringBuffer();
+		s.append("items1 = item;\n");
+
+		MockExtensionContext c = new MockExtensionContext();
+		JSExtensionOperation jso = new JSExtensionOperation();
+		Element e = DOMUtils.stringToDOM("<js:script xmlns:js=\"js\"><![CDATA[" + s + "]]></js:script>");
+		jso.run(c, e);
+		Assert.assertTrue(c.completed);
+		Assert.assertTrue(c.faulted);
+	}
+	
+	@Test public void testPrint() throws Exception {
+		StringBuffer s = new StringBuffer();
+		s.append("print('Hello World!');\n");
+
+		MockExtensionContext c = new MockExtensionContext();
+		JSExtensionOperation jso = new JSExtensionOperation();
+		Element e = DOMUtils.stringToDOM("<js:script xmlns:js=\"js\"><![CDATA[" + s + "]]></js:script>");
+		jso.run(c, e);
+		Assert.assertTrue(c.completed);
+		Assert.assertFalse(c.faulted);
+		Assert.assertEquals(1, c.msgs.size());
+		Assert.assertEquals("Hello World!", c.msgs.get(0));
+	}
+
+	@Test public void testLoad() throws Exception {
+		StringBuffer s = new StringBuffer();
+		s.append("load('../resources/test.js');\n");
+		s.append("print(myvar);\n");
+
+		MockExtensionContext c = new MockExtensionContext();
+		c.duDir = this.getClass().getResource("/").toURI();
+		JSExtensionOperation jso = new JSExtensionOperation();
+		Element e = DOMUtils.stringToDOM("<js:script xmlns:js=\"js\"><![CDATA[" + s + "]]></js:script>");
+		jso.run(c, e);
+		Assert.assertTrue(c.completed);
+		Assert.assertFalse(c.faulted);
+		Assert.assertEquals(1, c.msgs.size());
+		Assert.assertEquals("Hello Lib!", c.msgs.get(0));
+	}
+
+	@Test public void testPid() throws Exception {
+		StringBuffer s = new StringBuffer();
+		s.append("myvar = pid();\n");
+		s.append("print(myvar);\n");
+
+		MockExtensionContext c = new MockExtensionContext();
+		c.duDir = this.getClass().getResource("/").toURI();
+		JSExtensionOperation jso = new JSExtensionOperation();
+		Element e = DOMUtils.stringToDOM("<js:script xmlns:js=\"js\"><![CDATA[" + s + "]]></js:script>");
+		jso.run(c, e);
 		Assert.assertTrue(c.completed);
 		Assert.assertFalse(c.faulted);
+		Assert.assertEquals(1, c.msgs.size());
+		Assert.assertEquals("4711", c.msgs.get(0));
 	}
 
 }

Modified: ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4X/TestE4X.bpel
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4X/TestE4X.bpel?rev=706794&r1=706793&r2=706794&view=diff
==============================================================================
--- ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4X/TestE4X.bpel (original)
+++ ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4X/TestE4X.bpel Tue Oct 21 15:01:58 2008
@@ -53,13 +53,12 @@
     <sequence>
         <receive name="start" partnerLink="TestAssignPartnerLink" portType="test:TestAssignPortType"
                  operation="testAssign" variable="myVar" createInstance="yes"/>
-
         <assign name="assign1">
 			<extensionAssignOperation>
 				<js:snippet>
-				var request = context.readVariable('myVar');
+				var request = dom2js(_context.readVariable('myVar'));
 				request.TestPart += ' World';
-				context.writeVariable('otherMsgVar', request);
+				_context.writeVariable('otherMsgVar', js2dom(request));
 				</js:snippet>
 			</extensionAssignOperation>
         </assign>

Added: ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/TestE4XDirect.bpel
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/TestE4XDirect.bpel?rev=706794&view=auto
==============================================================================
--- ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/TestE4XDirect.bpel (added)
+++ ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/TestE4XDirect.bpel Tue Oct 21 15:01:58 2008
@@ -0,0 +1,67 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<process name="TestE4X"
+         targetNamespace="http://ode/bpel/unit-testAssign1"
+         xmlns:ode="http://www.apache.org/ode/type/extension"
+         xmlns:bpws="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
+         xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
+         xmlns:tns="http://ode/bpel/unit-testAssign1"
+         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+         xmlns:test="http://ode/bpel/unit-testAssign1.wsdl"
+         queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"
+         expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"
+         xmlns:js="http://ode.apache.org/extensions/e4x">
+
+    <import location="TestE4XDirect.wsdl"
+            namespace="http://ode/bpel/unit-testAssign1.wsdl"
+            importType="http://schemas.xmlsoap.org/wsdl/" />
+
+    <partnerLinks>
+        <partnerLink name="TestAssignPartnerLink" partnerLinkType="test:TestAssignPartnerLinkType" myRole="me" />
+    </partnerLinks>
+
+	<extensions>
+		<extension namespace="http://ode.apache.org/extensions/e4x" mustUnderstand="yes"/>
+	</extensions>
+	
+    <variables>
+        <variable name="myVar" messageType="test:TestAssignMessage"/>
+        <variable name="otherMsgVar" messageType="test:TestAssignMessage"/>
+        <variable name="strVar" type="xsd:string"/>
+        <variable name="intVar" type="xsd:int"/>
+        <variable name="intVar2" type="xsd:int"/>
+        <variable name="boolVar" type="xsd:boolean"/>
+    </variables>
+
+    <sequence>
+        <receive name="start" partnerLink="TestAssignPartnerLink" portType="test:TestAssignPortType"
+                 operation="testAssign" variable="myVar" createInstance="yes"/>
+        <assign name="assign1">
+			<extensionAssignOperation>
+				<js:snippet>
+				myVar.TestPart += ' World';
+				otherMsgVar = myVar;
+				</js:snippet>
+			</extensionAssignOperation>
+        </assign>
+        <reply name="end" partnerLink="TestAssignPartnerLink" portType="test:TestAssignPortType"
+               operation="testAssign" variable="otherMsgVar"/>
+    </sequence>
+</process>

Added: ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/TestE4XDirect.wsdl
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/TestE4XDirect.wsdl?rev=706794&view=auto
==============================================================================
--- ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/TestE4XDirect.wsdl (added)
+++ ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/TestE4XDirect.wsdl Tue Oct 21 15:01:58 2008
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<wsdl:definitions
+    targetNamespace="http://ode/bpel/unit-testAssign1.wsdl"
+    xmlns="http://schemas.xmlsoap.org/wsdl/"
+    xmlns:tns="http://ode/bpel/unit-testAssign1.wsdl"
+    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+    xmlns:bpws="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
+    xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype">
+
+    <wsdl:message name="TestAssignMessage">
+        <wsdl:part name="TestPart" type="xsd:string"/>
+    </wsdl:message>
+
+    <wsdl:portType name="TestAssignPortType">
+        <wsdl:operation name="testAssign">
+            <wsdl:input message="tns:TestAssignMessage" name="TestIn"/>
+            <wsdl:output message="tns:TestAssignMessage" name="TestOut"/>
+        </wsdl:operation>
+    </wsdl:portType>
+
+     <wsdl:binding name="TestAssignSoapBinding" type="tns:TestAssignPortType">
+        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
+        <wsdl:operation name="testAssign">
+            <soap:operation soapAction="" style="rpc"/>
+            <wsdl:input>
+                <soap:body namespace="http://ode/bpel/unit-test.wsdl" use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap:body namespace="http://ode/bpel/unit-test.wsdl" use="literal"/>
+            </wsdl:output>
+        </wsdl:operation>
+    </wsdl:binding>
+    <wsdl:service name="TestAssignService">
+		<wsdl:port name="TestAssignPort" binding="tns:TestAssignSoapBinding">
+     		<soap:address location="http://localhost:8080/ode/processes/TestAssign"/>
+		</wsdl:port>
+    </wsdl:service>
+
+   <plnk:partnerLinkType name="TestAssignPartnerLinkType">
+       <plnk:role name="me" portType="tns:TestAssignPortType"/>
+       <plnk:role name="you" portType="tns:TestAssignPortType"/>
+   </plnk:partnerLinkType>
+</wsdl:definitions>
+

Added: ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/deploy.xml
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/deploy.xml?rev=706794&view=auto
==============================================================================
--- ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/deploy.xml (added)
+++ ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/deploy.xml Tue Oct 21 15:01:58 2008
@@ -0,0 +1,32 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<deploy xmlns="http://www.apache.org/ode/schemas/dd/2007/03"
+  xmlns:pns="http://ode/bpel/unit-testAssign1"
+  xmlns:wns="http://ode/bpel/unit-testAssign1.wsdl">
+
+
+	<process name="pns:TestE4X">
+		<active>true</active>
+		<provide partnerLink="TestAssignPartnerLink">
+			<service name="wns:TestAssignService" port="TestAssignPort"/>
+			<service name="wns:TestAssignService" port="TestAssignPort"/>
+		</provide>
+	</process>
+</deploy>

Added: ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/test.properties
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/test.properties?rev=706794&view=auto
==============================================================================
--- ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/test.properties (added)
+++ ode/trunk/extensions/e4x/src/test/resources/bpel/TestE4XDirect/test.properties Tue Oct 21 15:01:58 2008
@@ -0,0 +1,22 @@
+#
+#    Licensed to the Apache Software Foundation (ASF) under one or more
+#    contributor license agreements.  See the NOTICE file distributed with
+#    this work for additional information regarding copyright ownership.
+#    The ASF licenses this file to You under the Apache License, Version 2.0
+#    (the "License"); you may not use this file except in compliance with
+#    the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+
+namespace=http://ode/bpel/unit-testAssign1.wsdl
+service=TestAssignService
+operation=testAssign
+request1=<message><TestPart>Hello</TestPart></message>
+response1=.*Hello World.*
\ No newline at end of file

Added: ode/trunk/extensions/e4x/src/test/resources/test.js
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/test/resources/test.js?rev=706794&view=auto
==============================================================================
--- ode/trunk/extensions/e4x/src/test/resources/test.js (added)
+++ ode/trunk/extensions/e4x/src/test/resources/test.js Tue Oct 21 15:01:58 2008
@@ -0,0 +1,5 @@
+myvar = test()
+
+function test() {
+	return "Hello Lib!";
+}
\ No newline at end of file