Author: antelder
Date: Wed May 10 06:23:16 2006
New Revision: 405754

URL: http://svn.apache.org/viewcvs?rev=405754&view=rev
Log:
Fix for TUSCANY-82
Still doesn't work for using E4X XML with SCA service references

Added:
    
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/E4XDataBinding.java
Removed:
    
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/E4XAXIOMUtils.java
Modified:
    incubator/tuscany/java/sca/containers/container.rhino/pom.xml
    
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilder.java
    
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScript.java
    
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoScript.java
    
incubator/tuscany/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.java
    
incubator/tuscany/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java

Modified: incubator/tuscany/java/sca/containers/container.rhino/pom.xml
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/containers/container.rhino/pom.xml?rev=405754&r1=405753&r2=405754&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.rhino/pom.xml (original)
+++ incubator/tuscany/java/sca/containers/container.rhino/pom.xml Wed May 10 
06:23:16 2006
@@ -40,12 +40,12 @@
             <groupId>rhino</groupId>
             <artifactId>js</artifactId>
             <version>1.6R2</version>
-            <scope>provided</scope>
+            <scope>compile</scope>
         </dependency>
 
         <dependency>
-            <groupId>org.apache.tuscany.sca.bindings</groupId>
-            <artifactId>tuscany-binding-axis2</artifactId> <!-- Reqd for E4X 
-->
+            <groupId>org.apache.tuscany.databinding</groupId>
+            <artifactId>tuscany-databinding-sdo</artifactId> <!-- Reqd for E4X 
-->
             <version>${pom.version}</version>
             <scope>compile</scope>
         </dependency>
@@ -54,7 +54,7 @@
             <groupId>xmlbeans</groupId>
             <artifactId>xbean</artifactId>  <!-- Reqd for E4X -->
             <version>2.1.0</version>
-            <scope>provided</scope>
+            <scope>compile</scope>
         </dependency>
 
         <dependency>

Modified: 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilder.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilder.java?rev=405754&r1=405753&r2=405754&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilder.java
 (original)
+++ 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilder.java
 Wed May 10 06:23:16 2006
@@ -17,14 +17,21 @@
 package org.apache.tuscany.container.rhino.builder;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
+import javax.wsdl.Input;
+import javax.wsdl.Message;
+import javax.wsdl.Operation;
+import javax.wsdl.Part;
+import javax.wsdl.PortType;
+
 import org.apache.tuscany.container.rhino.assembly.JavaScriptImplementation;
 import org.apache.tuscany.container.rhino.config.JavaScriptContextFactory;
+import org.apache.tuscany.container.rhino.rhino.E4XDataBinding;
 import org.apache.tuscany.container.rhino.rhino.RhinoE4XScript;
 import org.apache.tuscany.container.rhino.rhino.RhinoScript;
 import org.apache.tuscany.core.builder.BuilderConfigException;
-import org.apache.tuscany.core.builder.BuilderException;
 import org.apache.tuscany.core.builder.ContextFactory;
 import org.apache.tuscany.core.extension.ContextFactoryBuilderSupport;
 import org.apache.tuscany.model.assembly.Scope;
@@ -32,8 +39,6 @@
 import org.apache.tuscany.model.assembly.ServiceContract;
 import org.apache.tuscany.model.types.wsdl.WSDLServiceContract;
 
-import commonj.sdo.helper.TypeHelper;
-
 /**
  * Builds [EMAIL PROTECTED] 
org.apache.tuscany.container.rhino.config.JavaScriptContextFactory}s from a 
JavaScript component type
  * 
@@ -44,23 +49,10 @@
 
     @Override
     protected ContextFactory createContextFactory(String componentName, 
JavaScriptImplementation jsImplementation, Scope scope) {
-        Map<String, Class> services = new HashMap<String, Class>();
 
-        Boolean isWSDLService = null;
+        Map<String, Class> services = new HashMap<String, Class>();
         for (Service service : 
jsImplementation.getComponentType().getServices()) {
-            ServiceContract sc = service.getServiceContract();
-            if (sc instanceof WSDLServiceContract) {
-                if (isWSDLService != null && !isWSDLService.booleanValue()) {
-                    BuilderException e = new BuilderConfigException("mixed 
service interface types not supportted");
-                    e.setIdentifier(componentName);
-                    throw e;
-                }
-                isWSDLService = Boolean.TRUE;
-            } else {
-                isWSDLService = Boolean.FALSE;
-            }
-
-            services.put(service.getName(), sc.getInterface());
+            services.put(service.getName(), 
service.getServiceContract().getInterface());
         }
 
         Map<String, Object> defaultProperties = new HashMap<String, Object>();
@@ -72,9 +64,9 @@
         ClassLoader cl = jsImplementation.getResourceLoader().getClassLoader();
 
         RhinoScript invoker;
-        if (Boolean.TRUE.equals(isWSDLService)) {
-            TypeHelper typeHelper = jsImplementation.getTypeHelper();
-            invoker = new RhinoE4XScript(componentName, script, 
defaultProperties, cl, typeHelper);
+        if (isE4XStyle(componentName, 
jsImplementation.getComponentType().getServices())) {
+            E4XDataBinding dataBinding = createDataBinding(jsImplementation);
+            invoker = new RhinoE4XScript(componentName, script, 
defaultProperties, cl, dataBinding);
         } else {
             invoker = new RhinoScript(componentName, script, 
defaultProperties, cl);
         }
@@ -84,4 +76,53 @@
 
         return contextFactory;
     }
+
+    /**
+     * Tests if this should be an E4X style service
+     * Its E4X if the JavaScript component uses WSDL to define its interface
+     */
+    protected boolean isE4XStyle(String componentName, List<Service> services) 
{
+        Boolean isE4XStyle = null;
+        for (Service service : services) {
+            ServiceContract sc = service.getServiceContract();
+            if (sc instanceof WSDLServiceContract) {
+                if (isE4XStyle != null && !isE4XStyle.booleanValue()) {
+                    throw new BuilderConfigException("mixed service interface 
types not supportted");
+                }
+                isE4XStyle = Boolean.TRUE;
+            } else {
+                isE4XStyle = Boolean.FALSE;
+            }
+        }
+        return isE4XStyle.booleanValue();
+    }
+
+    /**
+     * Create the data binding for the component initialized for each 
operation in the service
+     */
+    protected E4XDataBinding createDataBinding(JavaScriptImplementation 
jsImplementation) {
+        E4XDataBinding dataBinding = new 
E4XDataBinding(jsImplementation.getTypeHelper());
+        for (Service service : 
jsImplementation.getComponentType().getServices()) {
+            ServiceContract sc = service.getServiceContract();
+            if (sc instanceof WSDLServiceContract) {
+                PortType pt = ((WSDLServiceContract) sc).getPortType();
+                for (Object o : pt.getOperations()) {
+                    Operation operation = (Operation) o;
+                    Input input = operation.getInput();
+                    if (input != null) {
+                        Message message = input.getMessage();
+                        if (message != null) {
+                            List parts = message.getOrderedParts(null);
+                            if (parts != null && parts.size() > 0) {
+                                Part part = (Part) parts.get(0);
+                                
dataBinding.addElementQName(operation.getName(), part.getElementName());
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return dataBinding;
+    }
+
 }

Added: 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/E4XDataBinding.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/E4XDataBinding.java?rev=405754&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/E4XDataBinding.java
 (added)
+++ 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/E4XDataBinding.java
 Wed May 10 06:23:16 2006
@@ -0,0 +1,105 @@
+/**
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as 
applicable.
+ *
+ *  Licensed 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.tuscany.container.rhino.rhino;
+
+import java.io.ByteArrayInputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.core.wire.InvocationRuntimeException;
+import org.apache.tuscany.databinding.sdo.SDOXMLHelper;
+import org.apache.xmlbeans.XmlObject;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Scriptable;
+
+import commonj.sdo.helper.TypeHelper;
+
+/**
+ * DataBinding to convert between Java objects and JavaScript E4X XML objects. 
This uses SDO to do the conversion between XML and Java so WSDL/XSDs
+ * need to have be registered with the SDO runtime.
+ * 
+ * TODO: suport non-wrapped WSDL 
+ */
+public class E4XDataBinding {
+
+    private TypeHelper typeHelper;
+
+    private Map<String, QName> function2ElementMap;
+
+    private static final boolean IS_WRAPPED = true;
+
+    public E4XDataBinding(TypeHelper typeHelper) {
+        this.typeHelper = typeHelper;
+        this.function2ElementMap = new HashMap<String, QName>();
+    }
+
+    /**
+     * Convert E4X XML to Java objects
+     * 
+     * @param e4xXML
+     * @return the array of Objects
+     */
+    public Object[] toObjects(Scriptable e4xXML) {
+        byte[] xmlBytes = e4xXML.toString().getBytes();
+        Object[] os = SDOXMLHelper.toObjects(typeHelper, xmlBytes, IS_WRAPPED);
+        return os;
+    }
+
+    /**
+     * Convert request Java objects to XML 
+     * 
+     * @param functionName
+     * @param os
+     * @param scope
+     * @return a JavaScript E4X XML object
+     */
+    public Scriptable toE4X(String functionName, Object[] os, Scriptable 
scope) {
+        QName elementQN = function2ElementMap.get(functionName);
+        byte[] xmlBytes = SDOXMLHelper.toXMLBytes(typeHelper, os, elementQN, 
IS_WRAPPED);
+
+        XmlObject xmlObject;
+        try {
+            xmlObject = XmlObject.Factory.parse(new 
ByteArrayInputStream(xmlBytes));
+        } catch (Exception e) {
+            throw new InvocationRuntimeException(e);
+        }
+
+        Context cx = Context.enter();
+        try {
+
+            Object xml = cx.getWrapFactory().wrap(cx, scope, xmlObject, 
XmlObject.class);
+            Scriptable jsXML = cx.newObject(scope, "XML", new Object[] { xml 
});
+
+            return jsXML;
+
+        } finally {
+            Context.exit();
+        }
+    }
+
+    /**
+     * Add the XML element name to use for an operation when converting from 
+     * Java objects to XML. 
+     *  
+     * @param functionName
+     * @param elementQN
+     */
+    public void addElementQName(String functionName, QName elementQN) {
+        function2ElementMap.put(functionName, elementQN);
+    }
+}

Modified: 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScript.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScript.java?rev=405754&r1=405753&r2=405754&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScript.java
 (original)
+++ 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScript.java
 Wed May 10 06:23:16 2006
@@ -1,70 +1,70 @@
+/**
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as 
applicable.
+ *
+ *  Licensed 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.tuscany.container.rhino.rhino;
 
 import java.util.Map;
 
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.tuscany.binding.axis2.databinding.AxiomHelper;
-import org.apache.xmlbeans.XmlException;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.xml.XMLObject;
-import org.osoa.sca.ServiceRuntimeException;
-
-import commonj.sdo.helper.TypeHelper;
 
 /**
- * Invokes a JavaScript/E4X function with argument and return values that may 
be E4X XML objects. When calling the script from Java request arguments
- * that are AXIOM OMElements are converted to E4X XML objects. If the response 
from the script is an E4X XML object it is converted to an AXIOM
- * OMElement.
+ * Invokes a JavaScript/E4X function with argument and return values that may 
be E4X XML objects. 
  */
 public class RhinoE4XScript extends RhinoScript {
 
-    private TypeHelper typeHelper;
-
-    private String serviceNS = "http://helloworld.samples.tuscany.apache.org";; 
// TODO can't hardcode this!
+    private E4XDataBinding dataBinding;
 
-    public RhinoE4XScript(String scriptName, String script, Map context, 
ClassLoader cl, TypeHelper typeHelper) {
+    public RhinoE4XScript(String scriptName, String script, Map context, 
ClassLoader cl, E4XDataBinding dataBinding) {
         super(scriptName, script, context, cl);
-        this.typeHelper = typeHelper;
+        this.dataBinding = dataBinding;
     }
 
-    protected RhinoE4XScript(String scriptName, String script, Scriptable 
scriptScope, TypeHelper typeHelper) {
+    protected RhinoE4XScript(String scriptName, String script, Scriptable 
scriptScope, E4XDataBinding dataBinding) {
         super(scriptName, script, scriptScope);
-        this.typeHelper = typeHelper;
+        this.dataBinding = dataBinding;
     }
 
     /**
      * Turn args to JS objects and convert any OMElement to E4X XML
      */
     @Override
-    protected Object[] processArgs(String functionName, Object arg, Scriptable 
scope) {
-        QName operationQN = new QName(serviceNS, functionName);
-        OMElement om = AxiomHelper.toOMElement(typeHelper, (Object[]) arg, 
operationQN, true);
-        try {
-            return new Object[] { E4XAXIOMUtils.toScriptableObject(om, scope) 
};
-        } catch (XmlException e) {
-            throw new ServiceRuntimeException(e);
-        }
+    protected Object[] processArgs(String functionName, Object[] args, 
Scriptable scope) {
+        return new Object[] { dataBinding.toE4X(functionName, args, scope) };
     }
 
     /**
-     * Unwrap and convert response
+     * Unwrap and convert response converting any E4X XML into Java objects
      */
     @Override
-    protected Object processResponse(Object response, Class responseClass) {
+    protected Object processResponse(String functionName, Object response, 
Class responseClass) {
         if (response instanceof XMLObject) {
-            OMElement om = E4XAXIOMUtils.toOMElement((XMLObject) response);
-            Object[] resp = AxiomHelper.toObjects(typeHelper, om, true);
-            return resp[0];
+            Object[] os = dataBinding.toObjects((XMLObject) response);
+            if (os == null || os.length < 1) {
+                return null;
+            } else {
+                return os[0];
+            }
         } else {
-            return super.processResponse(response, responseClass);
+            return super.processResponse(functionName, response, 
responseClass);
         }
     }
 
     @Override
     public RhinoE4XScript copy() {
-        return new RhinoE4XScript(scriptName, script, scriptScope, typeHelper);
+        return new RhinoE4XScript(scriptName, script, scriptScope, 
dataBinding);
     }
 
 }

Modified: 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoScript.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoScript.java?rev=405754&r1=405753&r2=405754&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoScript.java
 (original)
+++ 
incubator/tuscany/java/sca/containers/container.rhino/src/main/java/org/apache/tuscany/container/rhino/rhino/RhinoScript.java
 Wed May 10 06:23:16 2006
@@ -101,7 +101,7 @@
      * @param arg arguments to the function, may be a single object or an 
array of objects.
      * @return the function return value.
      */
-    public Object invoke(String functionName, Object args) {
+    public Object invoke(String functionName, Object[] args) {
         return invoke(functionName, args, null, null);
     }
 
@@ -114,7 +114,7 @@
      *        the values by using the variable in name.
      * @return the function return value.
      */
-    public Object invoke(String functionName, Object args, Map contexts) {
+    public Object invoke(String functionName, Object[] args, Map contexts) {
         return invoke(functionName, args, null, contexts);
     }
 
@@ -128,14 +128,14 @@
      *        the values by using the variable in name.
      * @return the function return value.
      */
-    public Object invoke(String functionName, Object arg, Class responseClass, 
Map contexts) {
+    public Object invoke(String functionName, Object[] arg, Class 
responseClass, Map contexts) {
         Context cx = Context.enter();
         try {
             Function function = getFunction(scriptScope, functionName);
             Scriptable invocationScope = getInvocationScope(cx, contexts);
             Object[] args = processArgs(functionName, arg, invocationScope);
             Object jsResponse = function.call(cx, invocationScope, 
invocationScope, args);
-            Object response = processResponse(jsResponse, responseClass);
+            Object response = processResponse(functionName, jsResponse, 
responseClass);
             return response;
         } finally {
             Context.exit();
@@ -145,7 +145,7 @@
     /**
      * Turn args to JS objects and convert any OMElement to E4X XML
      */
-    protected Object[] processArgs(String functionName, Object arg, Scriptable 
scope) {
+    protected Object[] processArgs(String functionName, Object[] arg, 
Scriptable scope) {
         Object[] args;
         if (arg == null) {
             args = new Object[] { null };
@@ -163,7 +163,7 @@
     /**
      * Unwrap and convert response
      */
-    protected Object processResponse(Object response, Class responseClass) {
+    protected Object processResponse(String functionName, Object response, 
Class responseClass) {
         if (Context.getUndefinedValue().equals(response)) {
             response = null;
         } else if (response instanceof Wrapper) {
@@ -285,10 +285,6 @@
         } finally {
             Context.exit();
         }
-    }
-
-    public Object invoke(String methodName, Object[] args) {
-        return invoke(methodName, (Object) args);
     }
 
 }

Modified: 
incubator/tuscany/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.java?rev=405754&r1=405753&r2=405754&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.java
 (original)
+++ 
incubator/tuscany/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoE4XScriptTestCase.java
 Wed May 10 06:23:16 2006
@@ -19,9 +19,10 @@
 import java.io.InputStream;
 import java.net.URL;
 
+import javax.xml.namespace.QName;
+
 import junit.framework.TestCase;
 
-import org.apache.tuscany.container.rhino.rhino.RhinoE4XScript;
 import org.apache.tuscany.sdo.helper.XSDHelperImpl;
 import org.apache.tuscany.sdo.util.SDOUtil;
 
@@ -37,19 +38,22 @@
 
     private String script;
 
-    private TypeHelper th;
+    private E4XDataBinding dataBinding;
 
     protected void setUp() throws Exception {
         super.setUp();
         this.script = readResource(scriptName);
-        this.th = SDOUtil.createTypeHelper();
+        TypeHelper th = SDOUtil.createTypeHelper();
         XSDHelper xsdHelper = new XSDHelperImpl(th);
         URL url = getClass().getResource("helloworld.wsdl");
         xsdHelper.define(url.openStream(), null);
+
+        dataBinding = new E4XDataBinding(th);
+        dataBinding.addElementQName("getGreetings", new 
QName("http://helloworld.samples.tuscany.apache.org";, "getGreetings"));
     }
 
     public void testSimpleInvocation() throws IOException {
-        RhinoE4XScript ri = new RhinoE4XScript(scriptName, script, null, null, 
th);
+        RhinoE4XScript ri = new RhinoE4XScript(scriptName, script, null, null, 
dataBinding);
         Object x = ri.invoke("getGreetings", new Object[] { "petra" }, null);
         assertEquals(x, "hello petra");
     }

Modified: 
incubator/tuscany/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java?rev=405754&r1=405753&r2=405754&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java
 (original)
+++ 
incubator/tuscany/java/sca/containers/container.rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java
 Wed May 10 06:23:16 2006
@@ -32,8 +32,9 @@
 public class RhinoScriptTestCase extends TestCase {
 
     private static final String scriptName = "RhinoScriptTestCase.js";
+
     private String script;
-    
+
     protected void setUp() throws Exception {
         super.setUp();
         this.script = readResource(scriptName);
@@ -41,17 +42,17 @@
 
     public void testSimpleInvocation() {
         RhinoScript ri = new RhinoScript(scriptName, script);
-        Object x = ri.invoke("echo", "petra", null);
+        Object x = ri.invoke("echo", new Object[] { "petra" }, null);
         assertEquals("petra", x);
     }
 
     public void testCopy() {
         RhinoScript ri = new RhinoScript(scriptName, script);
-        Object x = ri.invoke("echo", "petra", null);
+        Object x = ri.invoke("echo", new Object[] { "petra" }, null);
         assertEquals("petra", x);
 
         ri = ri.copy();
-        x = ri.invoke("echo", "sue", null);
+        x = ri.invoke("echo", new Object[] { "sue" }, null);
         assertEquals("sue", x);
 
     }
@@ -87,7 +88,7 @@
      */
     public void testScopes1() {
         RhinoScript ri = new RhinoScript(scriptName, script);
-        ri.invoke("setGlobalVarY", "petra", null);
+        ri.invoke("setGlobalVarY", new Object[] { "petra" }, null);
 
         Object x = ri.invoke("getGlobalVarY", null, null);
         assertEquals("petra", x);
@@ -98,7 +99,7 @@
      */
     public void testScopes2() {
         RhinoScript ri = new RhinoScript(scriptName, script);
-        ri.invoke("setLocalVarY", "petra", null);
+        ri.invoke("setLocalVarY", new Object[] { "petra" }, null);
 
         try {
             ri.invoke("getGlobalVarY", null, null);
@@ -113,7 +114,7 @@
      */
     public void testScopes3() {
         RhinoScript ri = new RhinoScript(scriptName, script);
-        ri.invoke("setGlobalVarY", "petra", null);
+        ri.invoke("setGlobalVarY", new Object[] { "petra" }, null);
 
         Map<String, Object> contexts = new HashMap<String, Object>();
         contexts.put("a", "sue");
@@ -130,7 +131,7 @@
      */
     public void testScopes4() {
         RhinoScript ri = new RhinoScript(scriptName, script);
-        ri.invoke("setGlobalVarY", "petra", null);
+        ri.invoke("setGlobalVarY", new Object[] { "petra" }, null);
 
         ri = ri.copy();
         try {
@@ -159,14 +160,14 @@
      */
     private String readResource(String name) {
         try {
-        URL url = getClass().getResource(name);
-        if (url == null) {
-            throw new RuntimeException("resource not found: " + name);
-        }
-        InputStream inputStream = url.openStream();
+            URL url = getClass().getResource(name);
+            if (url == null) {
+                throw new RuntimeException("resource not found: " + name);
+            }
+            InputStream inputStream = url.openStream();
 
-        StringBuffer resource = new StringBuffer();
-        int n = 0;
+            StringBuffer resource = new StringBuffer();
+            int n = 0;
 
             while ((n = inputStream.read()) != -1) {
                 resource.append((char) n);
@@ -174,8 +175,8 @@
 
             inputStream.close();
 
-        String s = resource.toString();
-        return s;
+            String s = resource.toString();
+            return s;
 
         } catch (IOException e) {
             throw new RuntimeException("IOException reading resource " + name, 
e);


Reply via email to