diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/implementation-python-runtime/src')
7 files changed, 63 insertions, 66 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonImplementationProvider.java b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonImplementationProvider.java index 0c9c1a2240..7d381ac9d9 100644 --- a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonImplementationProvider.java +++ b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonImplementationProvider.java @@ -43,7 +43,7 @@ import org.python.util.PythonInterpreter; /** * Implementation provider for Python component implementations. - * + * * @version $Rev$ $Date$ */ class PythonImplementationProvider implements ImplementationProvider { @@ -52,7 +52,7 @@ class PythonImplementationProvider implements ImplementationProvider { PythonInterpreter python; PyObject callable; ProxyFactory pxFactory; - + PythonImplementationProvider(final RuntimeComponent comp, final PythonImplementation impl, ProxyFactory pxf) { component = comp; implementation = impl; @@ -60,40 +60,40 @@ class PythonImplementationProvider implements ImplementationProvider { } public void start() { - final PySystemState pss = new PySystemState(); - pss.path.insert(0, new PyString(implementation.getLocation())); - pss.path.insert(0, new PyString(getClass().getProtectionDomain().getCodeSource().getLocation().getFile())); - python = new PythonInterpreter(null, pss); - python.exec("from invoker import *"); - - final List<PyObject> px = new ArrayList<PyObject>(); - for (final ComponentReference r: component.getReferences()) { - final PythonEval pe = pxFactory.createProxy(PythonEval.class, (RuntimeEndpointReference)r.getEndpointReferences().get(0)); + final PySystemState pss = new PySystemState(); + pss.path.insert(0, new PyString(implementation.getLocation())); + pss.path.insert(0, new PyString(getClass().getProtectionDomain().getCodeSource().getLocation().getFile())); + python = new PythonInterpreter(null, pss); + python.exec("from invoker import *"); + + final List<PyObject> px = new ArrayList<PyObject>(); + for(final ComponentReference r: component.getReferences()) { + final PythonEval pe = pxFactory.createProxy(PythonEval.class, (RuntimeEndpointReference)r.getEndpointReferences().get(0)); px.add(Py.java2py(new PythonEval() { - @Override - public String eval(final String args) throws Exception { - final String v = pe.eval(args); - return v; - } + @Override + public String eval(final String args) throws Exception { + final String v = pe.eval(args); + return v; + } })); - } - final List<PyObject> pr = new ArrayList<PyObject>(); - for (final ComponentProperty p: component.getProperties()) { - final String v = String.valueOf(p.getValue()); + } + final List<PyObject> pr = new ArrayList<PyObject>(); + for(final ComponentProperty p: component.getProperties()) { + final String v = String.valueOf(p.getValue()); pr.add(Py.java2py(new PythonProperty() { - @Override - public String eval() { - return v; - } - })); - } + @Override + public String eval() { + return v; + } + })); + } - PyObject mkc = python.get("mkcomponent"); - callable = mkc.__call__(new PyString(component.getName()), new PyString(implementation.getScript()), new PyTuple(px.toArray(new PyObject[0])), new PyTuple(pr.toArray(new PyObject[0]))); + PyObject mkc = python.get("mkcomponent"); + callable = mkc.__call__(new PyString(component.getName()), new PyString(implementation.getScript()), new PyTuple(px.toArray(new PyObject[0])), new PyTuple(pr.toArray(new PyObject[0]))); } public void stop() { - python.cleanup(); + python.cleanup(); } public boolean supportsOneWayInvocation() { diff --git a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonImplementationProviderFactory.java b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonImplementationProviderFactory.java index 1a09e1cc99..752e3fd899 100644 --- a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonImplementationProviderFactory.java +++ b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonImplementationProviderFactory.java @@ -29,20 +29,20 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; /** * A factory for Python implementation providers. - * + * * @version $Rev$ $Date$ */ public class PythonImplementationProviderFactory implements ImplementationProviderFactory<PythonImplementation> { - final ProxyFactory pxFactory; - + final ProxyFactory pxFactory; + public PythonImplementationProviderFactory(final ExtensionPointRegistry ep) { - pxFactory = ExtensibleProxyFactory.getInstance(ep); + pxFactory = ExtensibleProxyFactory.getInstance(ep); } public ImplementationProvider createImplementationProvider(final RuntimeComponent comp, final PythonImplementation impl) { return new PythonImplementationProvider(comp, impl, pxFactory); } - + public Class<PythonImplementation> getModelType() { return PythonImplementation.class; } diff --git a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonInvoker.java b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonInvoker.java index da342bd03c..a49e5e3296 100644 --- a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonInvoker.java +++ b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/java/org/apache/tuscany/sca/implementation/python/provider/PythonInvoker.java @@ -28,7 +28,7 @@ import org.python.util.PythonInterpreter; /** * An invoker for Python components. - * + * * @version $Rev$ $Date$ */ class PythonInvoker implements Invoker { @@ -43,15 +43,15 @@ class PythonInvoker implements Invoker { } String apply(final String req) { - PyObject r = callable.__call__(new PyString(req)); - return r.toString(); + PyObject r = callable.__call__(new PyString(req)); + return r.toString(); } public Message invoke(final Message msg) { try { msg.setBody(apply((String)((Object[])msg.getBody())[0])); - } catch (Exception e) { - e.printStackTrace(); + } catch(Exception e) { + e.printStackTrace(); msg.setFaultBody(e.getCause()); } return msg; diff --git a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ClientTest.java b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ClientTest.java index 251364933e..f69ce3284e 100644 --- a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ClientTest.java +++ b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ClientTest.java @@ -20,18 +20,17 @@ package org.apache.tuscany.sca.implementation.python.provider; import org.oasisopen.sca.annotation.Reference; - /** * Test Java component. * * @version $Rev$ $Date$ */ public class ClientTest implements EchoTest { - - @Reference - public EchoTest ref; - public String echo(final String s1, final String s2) { - return ref.echo(s1, s2); - } + @Reference + public EchoTest ref; + + public String echo(final String s1, final String s2) { + return ref.echo(s1, s2); + } } diff --git a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/EchoTest.java b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/EchoTest.java index 366a94a346..557bc968da 100644 --- a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/EchoTest.java +++ b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/EchoTest.java @@ -20,7 +20,6 @@ package org.apache.tuscany.sca.implementation.python.provider; import org.oasisopen.sca.annotation.Remotable; - /** * Test client interface. * @@ -29,5 +28,5 @@ import org.oasisopen.sca.annotation.Remotable; @Remotable public interface EchoTest { - public String echo(String s1, String s2); + public String echo(String s1, String s2); } diff --git a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/InvokeTestCase.java b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/InvokeTestCase.java index b32c931453..0d4b00d49a 100644 --- a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/InvokeTestCase.java +++ b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/InvokeTestCase.java @@ -38,23 +38,23 @@ import org.junit.Test; * @version $Rev$ $Date$ */ public class InvokeTestCase { - static Node node; - + static Node node; + @BeforeClass public static void setUp() throws Exception { - try { - final String loc = getContributionLocation("domain-test.composite"); - node = NodeFactory.newInstance().createNode("domain-test.composite", new Contribution("c", loc)); - node.start(); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } + try { + final String loc = getContributionLocation("domain-test.composite"); + node = NodeFactory.newInstance().createNode("domain-test.composite", new Contribution("c", loc)); + node.start(); + } catch(Exception e) { + e.printStackTrace(); + throw e; + } } @AfterClass public static void tearDown() throws Exception { - node.stop(); + node.stop(); } @Test @@ -62,7 +62,7 @@ public class InvokeTestCase { final Session s = TransportRegistry.i().createSession("http://localhost:8080/python"); final Client c = new Client(s); final Object px = c.openProxy("", EchoTest.class); - final Object r = c.invoke(px, EchoTest.class.getMethod("echo", String.class, String.class), new Object[]{"Hey", "There"}); + final Object r = c.invoke(px, EchoTest.class.getMethod("echo", String.class, String.class), new Object[] {"Hey", "There"}); c.closeProxy(px); s.close(); assertEquals("Hey There", r); @@ -73,7 +73,7 @@ public class InvokeTestCase { final Session s = TransportRegistry.i().createSession("http://localhost:8080/client"); final Client c = new Client(s); final Object px = c.openProxy("", EchoTest.class); - final Object r = c.invoke(px, EchoTest.class.getMethod("echo", String.class, String.class), new Object[]{"Hey", "There"}); + final Object r = c.invoke(px, EchoTest.class.getMethod("echo", String.class, String.class), new Object[] {"Hey", "There"}); c.closeProxy(px); s.close(); assertEquals("Hey There", r); @@ -84,7 +84,7 @@ public class InvokeTestCase { final Session s = TransportRegistry.i().createSession("http://localhost:8080/java-client"); final Client c = new Client(s); final Object px = c.openProxy("", EchoTest.class); - final Object r = c.invoke(px, EchoTest.class.getMethod("echo", String.class, String.class), new Object[]{"Hey", "There"}); + final Object r = c.invoke(px, EchoTest.class.getMethod("echo", String.class, String.class), new Object[] {"Hey", "There"}); c.closeProxy(px); s.close(); assertEquals("Hey There", r); diff --git a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ServerTest.java b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ServerTest.java index 422be15dd6..b0f3b5868f 100644 --- a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ServerTest.java +++ b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ServerTest.java @@ -18,7 +18,6 @@ */ package org.apache.tuscany.sca.implementation.python.provider; - /** * Test Java component. * @@ -26,7 +25,7 @@ package org.apache.tuscany.sca.implementation.python.provider; */ public class ServerTest implements EchoTest { - public String echo(final String s1, final String s2) { - return s1 + " " + s2; - } + public String echo(final String s1, final String s2) { + return s1 + " " + s2; + } } |