diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-29 02:46:21 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-29 02:46:21 +0000 |
commit | 490374326cf57b0161d053aea3a9f0cedd7d2228 (patch) | |
tree | 1a0dc011461aef099bf3fe33165b45a9ba492680 /sca-java-2.x/trunk/modules | |
parent | 460613d0d5e60b9ed43094220b89dd31388463c2 (diff) |
Minor change. Code format and cleanup.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@990478 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
12 files changed, 123 insertions, 130 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; + } } diff --git a/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonEval.java b/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonEval.java index 2ce220f84e..ae9caab7d0 100644 --- a/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonEval.java +++ b/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonEval.java @@ -20,7 +20,6 @@ package org.apache.tuscany.sca.implementation.python; import org.oasisopen.sca.annotation.Remotable; - /** * Python component generic evaluation interface. * @@ -29,5 +28,5 @@ import org.oasisopen.sca.annotation.Remotable; @Remotable public interface PythonEval { - public String eval(String args) throws Exception; + public String eval(String args) throws Exception; } diff --git a/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonImplementation.java b/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonImplementation.java index 7b0867e4cd..058c01a48e 100644 --- a/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonImplementation.java +++ b/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonImplementation.java @@ -49,11 +49,12 @@ public class PythonImplementation extends ImplementationImpl { contract = c; class DynService extends ServiceImpl { - public DynService() { - setName("default"); - setInterfaceContract(contract); - } - }; + public DynService() { + setName("default"); + setInterfaceContract(contract); + } + } + ; service = new DynService(); getServices().add(service); } @@ -61,43 +62,43 @@ public class PythonImplementation extends ImplementationImpl { public String getScript() { return script; } - + public String getLocation() { - return location; - } + return location; + } public Service getService(final String n) { - return service; - } + return service; + } public Reference getReference(final String n) { - final Reference r = super.getReference(n); - if (r != null) - return r; - class DynReference extends ReferenceImpl { - public DynReference() { - setName(n); - setInterfaceContract(contract); - } - } - final Reference nr = new DynReference(); - getReferences().add(nr); - return nr; + final Reference r = super.getReference(n); + if(r != null) + return r; + class DynReference extends ReferenceImpl { + public DynReference() { + setName(n); + setInterfaceContract(contract); + } + } + final Reference nr = new DynReference(); + getReferences().add(nr); + return nr; } - + public Property getProperty(final String n) { - final Property p = super.getProperty(n); - if (p != null) - return p; - class DynProperty extends PropertyImpl { - public DynProperty() { - setName(n); - setDataType(new DataTypeImpl<XMLType>(null, String.class, String.class, XMLType.UNKNOWN)); - setXSDType(new QName("http://www.w3.org/2001/XMLSchema", "string")); - } - } - final Property np = new DynProperty(); - getProperties().add(np); - return np; + final Property p = super.getProperty(n); + if(p != null) + return p; + class DynProperty extends PropertyImpl { + public DynProperty() { + setName(n); + setDataType(new DataTypeImpl<XMLType>(null, String.class, String.class, XMLType.UNKNOWN)); + setXSDType(new QName("http://www.w3.org/2001/XMLSchema", "string")); + } + } + final Property np = new DynProperty(); + getProperties().add(np); + return np; } } diff --git a/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonImplementationProcessor.java b/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonImplementationProcessor.java index 3edfb951ae..b4daab34cd 100644 --- a/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonImplementationProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonImplementationProcessor.java @@ -55,29 +55,29 @@ public class PythonImplementationProcessor extends BaseStAXArtifactProcessor imp final InterfaceContract contract; - public PythonImplementationProcessor(final ExtensionPointRegistry ep) throws InvalidInterfaceException, NoSuchMethodException { + public PythonImplementationProcessor(final ExtensionPointRegistry ep) throws InvalidInterfaceException { final FactoryExtensionPoint fep = ep.getExtensionPoint(FactoryExtensionPoint.class); final JavaInterfaceFactory jf = fep.getFactory(JavaInterfaceFactory.class); final JavaInterface eval = jf.createJavaInterface(PythonEval.class); - + class DynamicInterface extends JavaInterfaceImpl { - DynamicInterface() throws NoSuchMethodException { - setJavaClass(eval.getJavaClass()); - setName(eval.getName()); - setRemotable(eval.isRemotable()); - Operation op = eval.getOperations().get(0); - op.setDynamic(true); - getOperations().add(op); + DynamicInterface() { + setJavaClass(eval.getJavaClass()); + setName(eval.getName()); + setRemotable(eval.isRemotable()); + Operation op = eval.getOperations().get(0); + op.setDynamic(true); + getOperations().add(op); resetDataBinding(JSONDataBinding.NAME); setUnresolved(false); - } - - @Override - public boolean isDynamic() { - return true; - } + } + + @Override + public boolean isDynamic() { + return true; + } } - + contract = jf.createJavaInterfaceContract(); contract.setInterface(new DynamicInterface()); } @@ -92,7 +92,8 @@ public class PythonImplementationProcessor extends BaseStAXArtifactProcessor imp public PythonImplementation read(final XMLStreamReader r, final ProcessorContext ctx) throws ContributionReadException, XMLStreamException { final String scr = r.getAttributeValue(null, "script"); - while (r.hasNext() && !(r.next() == END_ELEMENT && QN.equals(r.getName()))); + while(r.hasNext() && !(r.next() == END_ELEMENT && QN.equals(r.getName()))) + ; return new PythonImplementation(QN, scr, URI.create(ctx.getContribution().getLocation()).getPath(), contract); } @@ -100,10 +101,7 @@ public class PythonImplementationProcessor extends BaseStAXArtifactProcessor imp } public void write(final PythonImplementation impl, final XMLStreamWriter w, final ProcessorContext ctx) throws ContributionWriteException, XMLStreamException { - writeStart(w, - QN.getNamespaceURI(), - QN.getLocalPart(), - new XAttr("script", impl.getScript())); + writeStart(w, QN.getNamespaceURI(), QN.getLocalPart(), new XAttr("script", impl.getScript())); writeEnd(w); } } diff --git a/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonProperty.java b/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonProperty.java index 4b5a1c7382..6efee36ab3 100644 --- a/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonProperty.java +++ b/sca-java-2.x/trunk/modules/implementation-python/src/main/java/org/apache/tuscany/sca/implementation/python/PythonProperty.java @@ -20,7 +20,6 @@ package org.apache.tuscany.sca.implementation.python; import org.oasisopen.sca.annotation.Remotable; - /** * Python component property evaluation interface. * @@ -29,5 +28,5 @@ import org.oasisopen.sca.annotation.Remotable; @Remotable public interface PythonProperty { - public String eval(); + public String eval(); } diff --git a/sca-java-2.x/trunk/modules/implementation-python/src/test/java/org/apache/tuscany/sca/implementation/python/ReadWriteTestCase.java b/sca-java-2.x/trunk/modules/implementation-python/src/test/java/org/apache/tuscany/sca/implementation/python/ReadWriteTestCase.java index 2f5f8b16dc..388df1d210 100644 --- a/sca-java-2.x/trunk/modules/implementation-python/src/test/java/org/apache/tuscany/sca/implementation/python/ReadWriteTestCase.java +++ b/sca-java-2.x/trunk/modules/implementation-python/src/test/java/org/apache/tuscany/sca/implementation/python/ReadWriteTestCase.java @@ -43,7 +43,6 @@ import org.apache.tuscany.sca.monitor.Monitor; import org.junit.BeforeClass; import org.junit.Test; - /** * Test reading/writing Python implementations. * @@ -71,7 +70,7 @@ public class ReadWriteTestCase { @Test public void testRead() throws Exception { final InputStream is = getClass().getClassLoader().getResourceAsStream("domain-test.composite"); - final Composite c = (Composite) xproc.read(xif.createXMLStreamReader(is), ctx); + final Composite c = (Composite)xproc.read(xif.createXMLStreamReader(is), ctx); assertNotNull(c); assertEquals("server_test.py", ((PythonImplementation)c.getComponents().get(0).getImplementation()).getScript()); } @@ -79,7 +78,7 @@ public class ReadWriteTestCase { @Test public void testReadWrite() throws Exception { final InputStream is = getClass().getClassLoader().getResourceAsStream("domain-test.composite"); - final Composite c = (Composite) xproc.read(xif.createXMLStreamReader(is), ctx); + final Composite c = (Composite)xproc.read(xif.createXMLStreamReader(is), ctx); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); xproc.write(c, xof.createXMLStreamWriter(bos), ctx); assertTrue(bos.toString().contains("script=\"server_test.py\"")); |