Author: antelder
Date: Thu Sep 14 06:36:02 2006
New Revision: 443347
URL: http://svn.apache.org/viewvc?view=rev&rev=443347
Log:
update to match createInstance method now including the service classes
Modified:
incubator/tuscany/sandbox/ant/container.rhino/src/main/java/org/apache/tuscany/container/rhino/RhinoScriptInstanceFactory.java
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoFunctionInvokerTestCase.java
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoScriptInstanceTestCase.java
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoScriptTestCase.java
Modified:
incubator/tuscany/sandbox/ant/container.rhino/src/main/java/org/apache/tuscany/container/rhino/RhinoScriptInstanceFactory.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.rhino/src/main/java/org/apache/tuscany/container/rhino/RhinoScriptInstanceFactory.java?view=diff&rev=443347&r1=443346&r2=443347
==============================================================================
---
incubator/tuscany/sandbox/ant/container.rhino/src/main/java/org/apache/tuscany/container/rhino/RhinoScriptInstanceFactory.java
(original)
+++
incubator/tuscany/sandbox/ant/container.rhino/src/main/java/org/apache/tuscany/container/rhino/RhinoScriptInstanceFactory.java
Thu Sep 14 06:36:02 2006
@@ -18,8 +18,10 @@
*/
package org.apache.tuscany.container.rhino;
+import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.apache.tuscany.container.easy.EasyInstanceFactory;
@@ -68,9 +70,11 @@
}
@Override
- public RhinoScriptInstance createInstance(Map<String, Object> context) {
+ public RhinoScriptInstance createInstance(List<Class> services,
Map<String, Object> context) {
+ // TODO services should really be on the constructor of this class,
not on this method
+ // and the responseClasses done in the constructor/init
Scriptable instanceScope = createInstanceScope(context);
- RhinoScriptInstance rsi = new RhinoScriptInstance(scriptScope,
instanceScope, context, responseClasses);
+ RhinoScriptInstance rsi = new RhinoScriptInstance(scriptScope,
instanceScope, context, getResponseClasses(services));
return rsi;
}
@@ -101,8 +105,8 @@
Context cx = Context.enter();
try {
if (cl != null) {
- // TODO: broken with the way the tuscany launcher now uses class loaders
- // cx.setApplicationClassLoader(cl);
+ // TODO: broken with the way the tuscany launcher now uses
class loaders
+ // cx.setApplicationClassLoader(cl);
}
this.scriptScope = new ImporterTopLevel(cx, true);
Script compiledScript = cx.compileString(scriptCode, fileName, 1,
null);
@@ -137,5 +141,5 @@
public void setResponseClass(String functionName, Class responseClasses) {
this.responseClasses.put(functionName, responseClasses);
}
-
+
}
Modified:
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoFunctionInvokerTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoFunctionInvokerTestCase.java?view=diff&rev=443347&r1=443346&r2=443347
==============================================================================
---
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoFunctionInvokerTestCase.java
(original)
+++
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoFunctionInvokerTestCase.java
Thu Sep 14 06:36:02 2006
@@ -18,7 +18,9 @@
*/
package org.apache.tuscany.container.rhino;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import junit.framework.TestCase;
@@ -38,7 +40,7 @@
public void testNoArgsInvoke() {
RhinoScriptInstanceFactory instanceFactory = new
RhinoScriptInstanceFactory("foo", null, "function getPetra() {return
'petra';}", getClass().getClassLoader());
- RhinoScriptInstance instance = instanceFactory.createInstance(null);
+ RhinoScriptInstance instance = instanceFactory.createInstance(null,
null);
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("getPetra");
assertNotNull(invoker);
assertEquals("petra", invoker.invoke(null));
@@ -46,7 +48,7 @@
public void testOneArgInvoke() {
RhinoScriptInstanceFactory instanceFactory = new
RhinoScriptInstanceFactory("foo", null, "function getS(s) {return s;}",
getClass().getClassLoader());
- RhinoScriptInstance instance = instanceFactory.createInstance(null);
+ RhinoScriptInstance instance = instanceFactory.createInstance(null,
null);
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("getS");
assertNotNull(invoker);
assertEquals("petra", invoker.invoke(new Object[] { "petra" }));
@@ -54,7 +56,7 @@
public void testMultiArgsInvoke() {
RhinoScriptInstanceFactory instanceFactory = new
RhinoScriptInstanceFactory("foo", null, "function concat(x, y) {return x + y}",
getClass().getClassLoader());
- RhinoScriptInstance instance = instanceFactory.createInstance(new
HashMap<String, Object>());
+ RhinoScriptInstance instance = instanceFactory.createInstance(null,
new HashMap<String, Object>());
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("concat");
assertNotNull(invoker);
assertEquals("petrasue", invoker.invoke(new Object[] { "petra", "sue"
}));
@@ -62,7 +64,7 @@
public void testNoResponseInvoke() {
RhinoScriptInstanceFactory instanceFactory = new
RhinoScriptInstanceFactory("foo", null, "function getNull() {}",
getClass().getClassLoader());
- RhinoScriptInstance instance = instanceFactory.createInstance(new
HashMap<String, Object>());
+ RhinoScriptInstance instance = instanceFactory.createInstance(null,
new HashMap<String, Object>());
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("getNull");
assertNotNull(invoker);
assertEquals(null, invoker.invoke(new Object[0]));
@@ -70,7 +72,7 @@
public void testNullResponseInvoke() {
RhinoScriptInstanceFactory instanceFactory = new
RhinoScriptInstanceFactory("foo", null, "function getNull() {return null;}",
getClass().getClassLoader());
- RhinoScriptInstance instance = instanceFactory.createInstance(new
HashMap<String, Object>());
+ RhinoScriptInstance instance = instanceFactory.createInstance(null,
new HashMap<String, Object>());
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("getNull");
assertNotNull(invoker);
assertEquals(null, invoker.invoke(new Object[0]));
@@ -78,7 +80,7 @@
public void testResponseTypeDefaultString() {
RhinoScriptInstanceFactory instanceFactory = new
RhinoScriptInstanceFactory("foo", null, "function getTrue() {return true;}",
getClass().getClassLoader());
- RhinoScriptInstance instance = instanceFactory.createInstance(new
HashMap<String, Object>());
+ RhinoScriptInstance instance = instanceFactory.createInstance(null,
new HashMap<String, Object>());
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("getTrue");
assertNotNull(invoker);
Object o = invoker.invoke(new Object[0]);
@@ -89,16 +91,26 @@
public void testResponseTypeBoolean() {
RhinoScriptInstanceFactory instanceFactory = new
RhinoScriptInstanceFactory("foo", null, "function getTrue() {return true;}",
getClass().getClassLoader());
instanceFactory.setResponseClass("getTrue", Boolean.class);
- RhinoScriptInstance instance = instanceFactory.createInstance(new
HashMap<String, Object>());
+ List<Class> services = new ArrayList<Class>();
+ services.add(TestTypes.class);
+ RhinoScriptInstance instance =
instanceFactory.createInstance(services, new HashMap<String, Object>());
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("getTrue");
assertNotNull(invoker);
assertTrue((Boolean) invoker.invoke(new Object[0]));
}
+
+ interface TestTypes {
+ Boolean getTrue();
+ String[] getAs();
+ Boolean[] getBs();
+ }
public void testResponseTypeStringArray() {
RhinoScriptInstanceFactory instanceFactory = new
RhinoScriptInstanceFactory("foo", null, "function getAs() {var as = new
Array(1);as[0]='petra';return as;}", getClass().getClassLoader());
instanceFactory.setResponseClass("getAs", new String[0].getClass());
- RhinoScriptInstance instance = instanceFactory.createInstance(new
HashMap<String, Object>());
+ List<Class> services = new ArrayList<Class>();
+ services.add(TestTypes.class);
+ RhinoScriptInstance instance =
instanceFactory.createInstance(services, new HashMap<String, Object>());
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("getAs");
assertNotNull(invoker);
Object o = invoker.invoke(new Object[0]);
@@ -110,7 +122,9 @@
public void testResponseTypeBooleanArray() {
RhinoScriptInstanceFactory instanceFactory = new
RhinoScriptInstanceFactory("foo", null, "function getBs() {var bs = new
Array(1);bs[0]=true;return bs;}", getClass().getClassLoader());
instanceFactory.setResponseClass("getBs", new Boolean[0].getClass());
- RhinoScriptInstance instance = instanceFactory.createInstance(new
HashMap<String, Object>());
+ List<Class> services = new ArrayList<Class>();
+ services.add(TestTypes.class);
+ RhinoScriptInstance instance =
instanceFactory.createInstance(services, new HashMap<String, Object>());
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("getBs");
assertNotNull(invoker);
Object o = invoker.invoke(new Object[0]);
@@ -121,7 +135,7 @@
public void testRequestCustomType() {
RhinoScriptInstanceFactory instanceFactory = new
RhinoScriptInstanceFactory("foo", null, "function getFooS(foo) {return
foo.getS();}", getClass().getClassLoader());
- RhinoScriptInstance instance = instanceFactory.createInstance(new
HashMap<String, Object>());
+ RhinoScriptInstance instance = instanceFactory.createInstance(null,
new HashMap<String, Object>());
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("getFooS");
assertNotNull(invoker);
@@ -134,7 +148,7 @@
public void testResponseCustomType() {
RhinoScriptInstanceFactory instanceFactory = new
RhinoScriptInstanceFactory("foo", null,
"importClass(Packages.org.apache.tuscany.container.rhino.mock.Foo);function
getFoo(s) {var foo = new Foo(); foo.setS(s);return foo;}",
getClass().getClassLoader());
- RhinoScriptInstance instance = instanceFactory.createInstance(new
HashMap<String, Object>());
+ RhinoScriptInstance instance = instanceFactory.createInstance(null,
new HashMap<String, Object>());
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("getFoo");
assertNotNull(invoker);
Modified:
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoScriptInstanceTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoScriptInstanceTestCase.java?view=diff&rev=443347&r1=443346&r2=443347
==============================================================================
---
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoScriptInstanceTestCase.java
(original)
+++
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoScriptInstanceTestCase.java
Thu Sep 14 06:36:02 2006
@@ -43,7 +43,7 @@
public void testCreateRhinoFunctionInvoker() {
RhinoScriptInstanceFactory rhinoScript = new
RhinoScriptInstanceFactory("foo", null, "function getPetra() {return
'petra';}", getClass().getClassLoader());
- RhinoScriptInstance instance = rhinoScript.createInstance(new
HashMap<String, Object>());
+ RhinoScriptInstance instance = rhinoScript.createInstance(null, new
HashMap<String, Object>());
RhinoFunctionInvoker invoker =
instance.createRhinoFunctionInvoker("getPetra");
assertNotNull(invoker);
assertEquals("petra", invoker.invoke(new Object[0]));
Modified:
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoScriptTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoScriptTestCase.java?view=diff&rev=443347&r1=443346&r2=443347
==============================================================================
---
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoScriptTestCase.java
(original)
+++
incubator/tuscany/sandbox/ant/container.rhino/src/test/java/org/apache/tuscany/container/rhino/RhinoScriptTestCase.java
Thu Sep 14 06:36:02 2006
@@ -19,9 +19,13 @@
package org.apache.tuscany.container.rhino;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import
org.apache.tuscany.container.rhino.RhinoFunctionInvokerTestCase.TestTypes;
+
import junit.framework.TestCase;
/**
@@ -39,13 +43,13 @@
public void testSimpleConstructor() throws InvocationTargetException {
RhinoScriptInstanceFactory rhinoScript = new
RhinoScriptInstanceFactory("foo", null,"function getPetra() {return 'petra';}",
getClass().getClassLoader());
- RhinoScriptInstance instance = rhinoScript.createInstance(new
HashMap<String, Object>());
+ RhinoScriptInstance instance = rhinoScript.createInstance(null, new
HashMap<String, Object>());
assertEquals("petra", instance.invokeTarget("getPetra", new
Object[0]));
}
public void testCreateInstance() {
RhinoScriptInstanceFactory rhinoScript = new
RhinoScriptInstanceFactory("foo", null,"function getPetra() {return 'petra';}",
getClass().getClassLoader());
- RhinoScriptInstance instance = rhinoScript.createInstance(new
HashMap<String, Object>());
+ RhinoScriptInstance instance = rhinoScript.createInstance(null, new
HashMap<String, Object>());
assertNotNull(instance);
}
@@ -53,23 +57,29 @@
RhinoScriptInstanceFactory rhinoScript = new
RhinoScriptInstanceFactory("foo", null,"function getName() {return name;}",
getClass().getClassLoader());
Map<String, Object> contexts = new HashMap<String, Object>();
contexts.put("name", "petra");
- RhinoScriptInstance instance = rhinoScript.createInstance(contexts);
+ RhinoScriptInstance instance = rhinoScript.createInstance(null,
contexts);
assertEquals("petra", instance.invokeTarget("getName", new Object[0]));
}
public void testDefaultResponseType() throws InvocationTargetException {
RhinoScriptInstanceFactory rhinoScript = new
RhinoScriptInstanceFactory("foo", null,"function getX() {return 42;}",
getClass().getClassLoader());
- RhinoScriptInstance instance = rhinoScript.createInstance(new
HashMap<String, Object>());
+ RhinoScriptInstance instance = rhinoScript.createInstance(null, new
HashMap<String, Object>());
assertEquals("42", instance.invokeTarget("getX", new Object[0]));
}
public void testSetResponseType() throws InvocationTargetException {
RhinoScriptInstanceFactory rhinoScript = new
RhinoScriptInstanceFactory("foo", null,"function getX() {return 42;}",
getClass().getClassLoader());
rhinoScript.setResponseClass("getX", Integer.class);
- RhinoScriptInstance instance = rhinoScript.createInstance(new
HashMap<String, Object>());
+ List<Class> services = new ArrayList<Class>();
+ services.add(TypeTest.class);
+ RhinoScriptInstance instance = rhinoScript.createInstance(services,
new HashMap<String, Object>());
Object x = instance.invokeTarget("getX", new Object[0]);
assertTrue(x instanceof Integer);
assertEquals(new Integer(42), x);
+ }
+
+ interface TypeTest {
+ Integer getX();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]