diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/implementation-python-runtime')
2 files changed, 38 insertions, 7 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 126dc2807b..0c9c1a2240 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 @@ -22,10 +22,12 @@ package org.apache.tuscany.sca.implementation.python.provider; import java.util.ArrayList; import java.util.List; +import org.apache.tuscany.sca.assembly.ComponentProperty; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.implementation.python.PythonEval; import org.apache.tuscany.sca.implementation.python.PythonImplementation; +import org.apache.tuscany.sca.implementation.python.PythonProperty; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.provider.ImplementationProvider; @@ -65,7 +67,7 @@ class PythonImplementationProvider implements ImplementationProvider { python.exec("from invoker import *"); final List<PyObject> px = new ArrayList<PyObject>(); - for (ComponentReference r: component.getReferences()) { + 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 @@ -75,9 +77,19 @@ class PythonImplementationProvider implements ImplementationProvider { } })); } + 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; + } + })); + } PyObject mkc = python.get("mkcomponent"); - callable = mkc.__call__(new PyString(component.getName()), new PyString(implementation.getScript()), new PyTuple(px.toArray(new PyObject[0]))); + 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() { diff --git a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/resources/invoker.py b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/resources/invoker.py index 730e7c483f..48107671d6 100644 --- a/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/resources/invoker.py +++ b/sca-java-2.x/trunk/modules/implementation-python-runtime/src/main/resources/invoker.py @@ -52,19 +52,37 @@ def mkproxies(jpx): return () return cons(proxy(car(jpx)), mkproxies(cdr(jpx))) +class prop: + def __init__(self, jpy): + self.jpy = jpy + + def __call__(self): + # Eval the property + res = self.jpy.eval() + return res + +def __repr__(self): + return repr((jpy,)) + +def mkprops(jpy): + if isNil(jpy): + return () + return cons(prop(car(jpy)), mkprops(cdr(jpy))) + # Make a callable component class component: - def __init__(self, name, impl, jpx): + def __init__(self, name, impl, jpx, jpy): self.name = name self.impl = impl[0:len(impl) - 3] self.mod = __import__(self.impl) self.proxies = mkproxies(jpx) + self.props = mkprops(jpy) def __call__(self, func, *args): - return self.mod.__getattribute__(func)(*(args + self.proxies)) + return self.mod.__getattribute__(func)(*(args + self.proxies + self.props)) def __repr__(self): - return repr((self.name, self.impl, self.mod, self.svcs, self.refs, self.props, self.proxies)) + return repr((self.name, self.impl, self.mod, self.props, self.proxies)) # Converts the args received in a JSON request to a list of key value pairs def jsonArgs(a): @@ -84,6 +102,7 @@ def apply(jsreq, comp): return jsonResult(jid, v)[0] # Make a component that can be called with a JSON function request -def mkcomponent(name, impl, jpx): - comp = component(name, impl, jpx) +def mkcomponent(name, impl, jpx, jpy): + comp = component(name, impl, jpx, jpy) return lambda jsreq: apply(jsreq, comp) + |