Author: svkrish
Date: Sun Oct 8 02:42:32 2006
New Revision: 454110
URL: http://svn.apache.org/viewvc?view=rev&rev=454110
Log:
Updated for supporting component properties and references
Added:
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyRefInvocInterceptor.java
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyReferenceProxy.java
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyUtils.java
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/resources/META-INF/sca/ruby.system.scdl
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/propertyTest.componentType
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/propertyTest.rb
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/pom.xml
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponent.java
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentBuilder.java
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScript.java
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScriptInstance.java
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/helloworld/HelloWorldService.java
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/helloworld/HelloWorldServiceImpl.java
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/function/HelloWorldTestCase.java
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.componentType
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.rb
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/helloworld.scdl
Modified: incubator/tuscany/java/sca/services/containers/container.ruby/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/pom.xml?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.ruby/pom.xml
(original)
+++ incubator/tuscany/java/sca/services/containers/container.ruby/pom.xml Sun
Oct 8 02:42:32 2006
@@ -71,5 +71,19 @@
<groupId>org.easymock</groupId>
<artifactId>easymockclassextension</artifactId>
</dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ <version>2.1_3</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom-impl</artifactId>
+ </dependency>
</dependencies>
</project>
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponent.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponent.java?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponent.java
(original)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponent.java
Sun Oct 8 02:42:32 2006
@@ -19,6 +19,7 @@
package org.apache.tuscany.container.ruby;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -53,6 +54,7 @@
RubyScript rubyScript,
String rubyClassName,
List<Class<?>> services,
+ Map<String, Object> propValues,
CompositeComponent parent,
ScopeContainer scopeContainer,
WireService wireService,
@@ -63,7 +65,8 @@
this.rubyClassName = rubyClassName;
this.services = services;
this.scope = scopeContainer.getScope();
- this.properties = new HashMap<String, Object>();
+ //this.properties = new HashMap<String, Object>();
+ this.properties = propValues;
}
public Object createInstance() throws ObjectCreationException {
@@ -73,23 +76,21 @@
for (List<OutboundWire> referenceWires : getOutboundWires().values()) {
for (OutboundWire wire : referenceWires) {
Object wireProxy = wireService.createProxy(wire);
- // since all types that may be used in the reference interface
may not be known to Rhino
- // using the wireProxy as is will fail result in type
conversion exceptions in cases where
- // Rhino does not know enough of the tpypes used. Hence
introduce a interceptor proxy,
- // with weak typing (java.lang.Object) so that Rhino's call to
the proxy succeeds. Then
- // within this interceptor proxy perform data mediations
required to correctly call the
- // referenced service.
- /*
- * Class<?> businessInterface =
wire.getServiceContract().getInterfaceClass(); /JavaScriptReferenceProxy
interceptingProxy = new
- * JavaScriptReferenceProxy(businessInterface, wireProxy,
rubyScript.createInstanceScope(context));
- * context.put(wire.getReferenceName(),
interceptingProxy.createProxy());
- */
- context.put(wire.getReferenceName(),
- wireProxy);
+ //since all types that may be used in the reference interface
may not be known to Rhino
+ //using the wireProxy as is will fail result in type
conversion exceptions in cases where
+ //Rhino does not know enough of the tpypes used. Hence
introduce a interceptor proxy,
+ //with weak typing (java.lang.Object) so that Rhino's call to
the proxy succeeds. Then
+ //within this interceptor proxy perform data mediations
required to correctly call the
+ //referenced service.
+ Class<?> businessInterface =
wire.getServiceContract().getInterfaceClass();
+ RubyReferenceProxy interceptingProxy = new
RubyReferenceProxy(businessInterface,
+
wireProxy,
+
rubyScript.getRubyEngine());
+ context.put(wire.getReferenceName(),
interceptingProxy.createProxy());
}
}
-
- Object instance = rubyScript.createScriptInstance(rubyClassName);
+
+ Object instance = rubyScript.createScriptInstance(context,
rubyClassName);
return instance;
}
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentBuilder.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentBuilder.java?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentBuilder.java
(original)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentBuilder.java
Sun Oct 8 02:42:32 2006
@@ -20,7 +20,10 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.apache.tuscany.container.ruby.rubyscript.RubyScript;
import org.apache.tuscany.spi.builder.BuilderConfigException;
@@ -30,6 +33,8 @@
import org.apache.tuscany.spi.deployer.DeploymentContext;
import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
import org.apache.tuscany.spi.model.Scope;
import org.apache.tuscany.spi.model.ServiceDefinition;
@@ -38,22 +43,7 @@
*/
public class RubyComponentBuilder extends
ComponentBuilderExtension<RubyImplementation> {
- private static String head = "var xmlInstanceMap = new Array();";
-
- private static String part1 = "xmlInstanceMap[\"";
-
- private static String part2 = "\"] = ";
-
- private static String part3 = ";";
-
- private static String getXmlObjectFunction = "function
getXmlObject(xmlElementNamespace, xmlElementName){\n"
- + "return xmlInstanceMap[xmlElementNamespace + \"#\" +
xmlElementName];\n}";
-
- /*
- * XmlInstanceRegistry xmlInstRegistry; @Constructor({"xmlInstRegistry"})
public RubyComponentBuilder(@Autowire XmlInstanceRegistry reg) {
- * this.xmlInstRegistry = reg; }
- */
- protected Class<RubyImplementation> getImplementationType() {
+ protected Class<RubyImplementation> getImplementationType() {
return RubyImplementation.class;
}
@@ -72,7 +62,14 @@
for (ServiceDefinition serviceDefinition : collection) {
services.add(serviceDefinition.getServiceContract().getInterfaceClass());
}
-
+
+ Map<String, Object> propertyValues = new Hashtable<String, Object>();
+ Collection<PropertyValue<?>> propValueSettings =
componentDefinition.getPropertyValues().values();
+ for (PropertyValue propertyValue : propValueSettings) {
+ propertyValues.put(propertyValue.getName(),
+ propertyValue.getValueFactory().getInstance());
+ }
+
RubyScript rubyScript = implementation.getRubyScript();
// TODO: have ComponentBuilderExtension pass ScopeContainer in on
build method?
@@ -88,9 +85,10 @@
rubyScript,
implementation.getRubyClassName(),
services,
+ propertyValues,
parent,
scopeContainer,
wireService,
- workContext);
+ workContext);
}
}
Added:
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyRefInvocInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyRefInvocInterceptor.java?view=auto&rev=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyRefInvocInterceptor.java
(added)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyRefInvocInterceptor.java
Sun Oct 8 02:42:32 2006
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.ruby;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import org.jruby.IRuby;
+import org.jruby.RubyObject;
+import org.jruby.javasupport.JavaUtil;
+
+/**
+ * This Interceptor encasulates the data mediation required by the
JavaScriptReferenceProxy. The
+ * invocation handler of this class traps the javascript reference calls,
performs data mediation
+ * and calls then calls the actual referred service. This classes
implementation is subject to
+ * review and change when the DataMediation infrastructure of Tuscany is ready.
+ *
+ */
+public class RubyRefInvocInterceptor implements InvocationHandler {
+ private Object actualProxy;
+
+ private Class wireInterface;
+
+ private IRuby rubyEngine;
+
+ RubyRefInvocInterceptor(Object wireProxy, Class wireIfc, IRuby rubyEng) {
+ this.actualProxy = wireProxy;
+ this.wireInterface = wireIfc;
+ this.rubyEngine = rubyEng;
+ }
+
+ public Object invoke(Object arg0, Method method, Object[] args) throws
Throwable {
+ if ( method.getName().equals("hashCode"))
+ return new Integer(1);
+
+ Method invokedMethod = getInvokedMethod(method.getName());
+ Object[] tranformedArgs = new Object[args.length];
+ for (int count = 0; count < args.length; ++count) {
+ tranformedArgs[count] =
fromRubyToJava(invokedMethod.getParameterTypes()[count], args[count]);
+ }
+
+ Object response = invokedMethod.invoke(actualProxy, tranformedArgs);
+ response = fromJavaToRuby(response);
+ return response;
+ }
+
+ private Method getInvokedMethod(String methodName) {
+ Method[] methods = wireInterface.getMethods();
+
+ for (int count = 0; count < methods.length; ++count) {
+ if (methods[count].getName().equals(methodName)) {
+ return methods[count];
+ }
+ }
+ throw new RuntimeException("Unable to find invocation method");
+ }
+
+ protected Object fromRubyToJava(Class reqArgType, Object rubyArg) throws
Exception {
+ Object javaArg = null;
+
+ //for known cases the JRuby runtime handles the conversion before
calling the Java objects
+ //so nothing to do. When it cannot convert it simply passed the
instance of RubyObject
+ if ( rubyArg instanceof RubyObject ) {
+ //need to deal with this
+ } else {
+ javaArg = rubyArg;
+ }
+
+ return javaArg;
+ }
+
+ protected Object fromJavaToRuby(Object retVal) throws RuntimeException {
+ Object rubyRetVal = JavaUtil.convertJavaToRuby(rubyEngine, retVal,
retVal.getClass());
+ return rubyRetVal;
+ }
+}
Added:
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyReferenceProxy.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyReferenceProxy.java?view=auto&rev=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyReferenceProxy.java
(added)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyReferenceProxy.java
Sun Oct 8 02:42:32 2006
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.ruby;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.jruby.IRuby;
+import org.jruby.RubyException;
+
+import net.sf.cglib.asm.ClassWriter;
+import net.sf.cglib.asm.CodeVisitor;
+import net.sf.cglib.asm.Constants;
+import net.sf.cglib.asm.Type;
+
+/**
+ * This is a proxy that will mediate reference calls from the JavaScript. The
mediation code here will be reviewed when the DataMediation
+ * infrastructure is ready. This proxy assmes that there is no verloading of
service methods on the reference interface i.e. there are no two service
+ * methods that have the same method name or operation name.
+ */
+public class RubyReferenceProxy {
+
+ private Class interfaze;
+
+ private Object wireProxy;
+
+ private IRuby rubyEngine;
+
+ public RubyReferenceProxy(Class interfaze, Object wireProxy, IRuby
rubyEng) {
+ this.interfaze = interfaze;
+ this.wireProxy = wireProxy;
+ this.rubyEngine = rubyEng;
+ }
+
+ public Object createProxy() {
+ try {
+ GenericProxyClassLoader classloader = new
GenericProxyClassLoader();
+ final byte[] byteCode = generateGenericInterface(interfaze);
+
+ Class genericInterface = classloader.defineClass(byteCode);
+ InvocationHandler proxyHandler = new
RubyRefInvocInterceptor(wireProxy, interfaze, rubyEngine);
+ // return
genericInterface.cast(Proxy.newProxyInstance(classloader, new
Class[]{genericInterface}, proxyHandler));
+ return Proxy.newProxyInstance(classloader,
+ new Class[]{genericInterface},
+ proxyHandler);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ private static byte[] generateGenericInterface(Class serviceInterface) {
+ String interfazeName = serviceInterface.getCanonicalName();
+ ClassWriter cw = new ClassWriter(false);
+
+ cw.visit(Constants.V1_5,
+ Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT +
Constants.ACC_INTERFACE,
+ interfazeName.replace('.',
+ '/'),
+ "java/lang/Object",
+ null,
+ serviceInterface.getSimpleName() + ".java");
+
+ StringBuffer argsAndReturn = new StringBuffer("(");
+ Method[] methods = serviceInterface.getMethods();
+ for (int count = 0; count < methods.length; ++count) {
+ argsAndReturn = new StringBuffer("(");
+ Class[] paramTypes = methods[count].getParameterTypes();
+ Class returnType = methods[count].getReturnType();
+
+ for (int paramCount = 0; paramCount < paramTypes.length;
++paramCount) {
+ argsAndReturn.append(Type.getType(Object.class));
+ }
+ argsAndReturn.append(")");
+ argsAndReturn.append(Type.getType(Object.class));
+
+ Class[] exceptionTypes = methods[count].getExceptionTypes();
+ String[] exceptions = new String[exceptionTypes.length];
+ for (int excCount = 0; excCount < exceptionTypes.length;
++excCount) {
+ exceptions[excCount] = exceptionTypes[excCount].getName();
+ exceptions[excCount] = exceptions[excCount].replace('.',
+ '/');
+ }
+
+ CodeVisitor cv = cw.visitMethod(Constants.ACC_PUBLIC +
Constants.ACC_ABSTRACT,
+ methods[count].getName(),
+ argsAndReturn.toString(),
+ exceptions,
+ null);
+ cw.visitEnd();
+ }
+
+ cw.visitEnd();
+
+ return cw.toByteArray();
+ }
+
+ private class GenericProxyClassLoader extends ClassLoader {
+ public Class defineClass(byte[] byteArray) {
+ try {
+ return defineClass(null,
+ byteArray,
+ 0,
+ byteArray.length);
+ } catch (Throwable e) {
+ return null;
+ }
+ }
+
+ }
+}
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScript.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScript.java?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScript.java
(original)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScript.java
Sun Oct 8 02:42:32 2006
@@ -19,6 +19,7 @@
package org.apache.tuscany.container.ruby.rubyscript;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
@@ -26,12 +27,14 @@
import org.jruby.RubyString;
import org.jruby.javasupport.JavaEmbedUtils;
import org.jruby.javasupport.JavaUtil;
+import org.jruby.runtime.builtin.IRubyObject;
/**
* A RhinoScript represents a compiled JavaScript script
*/
public class RubyScript {
protected final String NEW = ".new";
+ protected final String EQUAL = "=";
protected String scriptName;
@@ -41,7 +44,7 @@
protected ClassLoader classLoader;
- private IRuby rubyEngine = JavaEmbedUtils.initialize(new Vector());
+ private IRuby rubyEngine = JavaEmbedUtils.initialize(new Vector());
/**
* Create a new RubyScript.
@@ -87,15 +90,31 @@
*
* @return a IRubyObject
*/
- public RubyScriptInstance createScriptInstance(String rubyClassName) {
+public RubyScriptInstance createScriptInstance(Map<String, Object> context,
String rubyClassName) {
if ( rubyClassName == null ) {
return new RubyScriptInstance(rubyEngine.evalScript(script),
responseClasses);
}
else {
- return new RubyScriptInstance(rubyEngine.evalScript(rubyClassName
+ NEW), responseClasses);
+ IRubyObject rubyObject = rubyEngine.evalScript(rubyClassName +
NEW);
+
+ Iterator<String> keyIterator = context.keySet().iterator();
+ String key = null;
+ Object value = null;
+ while ( keyIterator.hasNext()) {
+ key = keyIterator.next();
+ value = JavaUtil.convertJavaToRuby(rubyEngine,
+ context.get(key),
+
context.get(key).getClass());
+
+ JavaEmbedUtils.invokeMethod(rubyEngine,
+ rubyObject,
+ key + EQUAL,
+ new Object[]{value}, null);
+ }
+
+ return new RubyScriptInstance(rubyObject, responseClasses);
}
}
-
public String getScript() {
return script;
}
@@ -121,7 +140,7 @@
this.responseClasses.put(functionName,
responseClasses);
}
-
+
public RubySCAConfig getSCAConfig() {
return new RubySCAConfig(rubyEngine.getGlobalVariables());
}
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScriptInstance.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScriptInstance.java?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScriptInstance.java
(original)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScriptInstance.java
Sun Oct 8 02:42:32 2006
@@ -42,10 +42,20 @@
}
public Object invokeFunction(String functionName, Object[] args, Class
returnType) {
- return JavaEmbedUtils.invokeMethod(rubyInstance.getRuntime(),
- rubyInstance,
- functionName,
- args,
- returnType);
+ Object[] rubyArgs =
RubyUtils.fromJavaToRuby(rubyInstance.getRuntime(), args);
+
+ Object rubyResponse =
JavaEmbedUtils.invokeMethod(rubyInstance.getRuntime(),
+ rubyInstance,
+ functionName,
+ rubyArgs,
+ returnType);
+ Object response = RubyUtils.fromRubyToJava(rubyInstance.getRuntime(),
+ returnType,
+ rubyResponse);
+ return response;
}
+
+
+
+
}
Added:
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyUtils.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyUtils.java?view=auto&rev=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyUtils.java
(added)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyUtils.java
Sun Oct 8 02:42:32 2006
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.ruby.rubyscript;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.util.StAXUtils;
+import org.jruby.IRuby;
+import org.jruby.RubyObject;
+import org.jruby.javasupport.JavaUtil;
+
+/**
+ * @author administrator
+ *
+ */
+public class RubyUtils {
+ public static Object fromRubyToJava(IRuby rubyEngine, Class reqArgType,
Object rubyArg) {
+ Object javaArg = null;
+
+ //for known cases the JRuby runtime handles the conversion before
calling the Java objects
+ //so nothing to do. When it cannot convert it simply passed the
instance of RubyObject
+ if ( rubyArg instanceof RubyObject ) {
+ //need to deal with this
+ } else {
+ javaArg = rubyArg;
+ }
+
+ return javaArg;
+ }
+
+ public static Object[] fromJavaToRuby(IRuby rubyEngine, Object[] arg) {
+ Object[] jsArgs;
+ if (arg == null) {
+ jsArgs = new Object[0];
+ } else {
+ jsArgs = new Object[arg.length];
+ for (int i = 0; i < jsArgs.length; i++) {
+ jsArgs[i] = fromJavaToRuby(rubyEngine, arg[i]);
+ }
+ }
+
+ return jsArgs;
+ }
+
+ public static Object fromJavaToRuby(IRuby rubyEngine, Object javaObj) {
+ Object rubyObj = JavaUtil.convertJavaToRuby(rubyEngine, javaObj,
javaObj.getClass());
+ return rubyObj;
+ }
+
+}
Added:
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/resources/META-INF/sca/ruby.system.scdl
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/main/resources/META-INF/sca/ruby.system.scdl?view=auto&rev=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/resources/META-INF/sca/ruby.system.scdl
(added)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/main/resources/META-INF/sca/ruby.system.scdl
Sun Oct 8 02:42:32 2006
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+-->
+<!--
+ Ruby configuration for the launcher environment.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+
+ name="org.apache.tuscany.launcher.RubyImplementation">
+
+ <component name="ruby.implementationLoader">
+ <system:implementation.system
class="org.apache.tuscany.container.ruby.RubyImplementationLoader"/>
+ </component>
+
+ <component name="ruby.componentTypeLoader">
+ <system:implementation.system
class="org.apache.tuscany.container.ruby.RubyComponentTypeLoader"/>
+ </component>
+
+ <component name="ruby.componentBuilder">
+ <system:implementation.system
class="org.apache.tuscany.container.ruby.RubyComponentBuilder"/>
+ </component>
+
+</composite>
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/helloworld/HelloWorldService.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/helloworld/HelloWorldService.java?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/helloworld/HelloWorldService.java
(original)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/helloworld/HelloWorldService.java
Sun Oct 8 02:42:32 2006
@@ -18,7 +18,7 @@
*/
package helloworld;
-public interface HelloWorldService {
+public interface HelloWorldService {
String sayHello(String s);
}
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/helloworld/HelloWorldServiceImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/helloworld/HelloWorldServiceImpl.java?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/helloworld/HelloWorldServiceImpl.java
(original)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/helloworld/HelloWorldServiceImpl.java
Sun Oct 8 02:42:32 2006
@@ -18,10 +18,25 @@
*/
package helloworld;
+import org.osoa.sca.annotations.Property;
+
public class HelloWorldServiceImpl implements HelloWorldService {
+ @Property
+ public String greeting = "Default hello";
+
+ public String getGreeting() {
+ return greeting;
+ }
+
+
+ public void setGreeting(String greeting) {
+ this.greeting = greeting;
+ }
+
public String sayHello(String s) {
- return "Hello " + s;
+ //return greeting + s + " from the JavaWorld!";
+ return greeting + " from Java Reference " + s ; //+ " from " +
helloSayer.firstName + " " + helloSayer.lastName;
}
}
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java
(original)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java
Sun Oct 8 02:42:32 2006
@@ -22,7 +22,9 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Hashtable;
import java.util.List;
+import java.util.Map;
import junit.framework.TestCase;
@@ -113,10 +115,14 @@
scope.start();
List<Class<?>> services = new ArrayList<Class<?>>();
services.add(Greeting.class);
+ Map<String, Object> properties = new Hashtable<String,Object>();
+ properties.put("greeting","HeyThere");
+
RubyComponent context = new RubyComponent("source",
implClass2,
null,
services,
+
properties,
null,
scope,
ArtifactFactory.createWireService(),
@@ -145,10 +151,13 @@
scope.start();
List<Class<?>> services = new ArrayList<Class<?>>();
services.add(Greeting.class);
+ Map<String, Object> properties = new Hashtable<String,Object>();
+ properties.put("greeting","HeyThere");
RubyComponent context = new RubyComponent("source",
implClass2,
null,
services,
+
properties,
null,
scope,
ArtifactFactory.createWireService(),
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/function/HelloWorldTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/function/HelloWorldTestCase.java?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/function/HelloWorldTestCase.java
(original)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/function/HelloWorldTestCase.java
Sun Oct 8 02:42:32 2006
@@ -32,28 +32,44 @@
public class HelloWorldTestCase extends SCATestCase {
private HelloWorldService helloWorldService;
+ private CompositeContext context = null;
- private HelloWorldService introspectableService;
- private HelloWorldService e4xHelloWorldService;
-
protected void setUp() throws Exception {
- URL base =
getClass().getResource("/org/apache/tuscany/container/ruby/RubyComponent.class");
- addExtension("RubyContainer", new URL(base,
"../../../../../META-INF/sca/default.scdl"));
+ URL base = getClass().getResource("/META-INF/sca/ruby.system.scdl");
+ addExtension("RubyContainer", new URL(base, "default.scdl"));
setApplicationSCDL(getClass().getResource("helloworld.scdl"));
super.setUp();
- CompositeContext context = CurrentCompositeContext.getContext();
- helloWorldService = context.locateService(HelloWorldService.class,
"HelloWorldComponent");
+ context = CurrentCompositeContext.getContext();
+ helloWorldService = context.locateService(HelloWorldService.class,
"HelloWorldRubyComponent");
+
+ //helloWorldService = context.locateService(HelloWorldService.class,
"HelloWorldJavaReference");
}
public void testHelloWorldWithClass() throws Exception {
- assertEquals(helloWorldService.sayHello("petra"), "Hello to petra from
the Ruby World!");
- //System.out.println(helloWorldService.sayHello("petra"));
+ assertEquals(helloWorldService.sayHello("petra"), "Hey Howdy from Java
Reference petra");
+ //System.out.println(helloWorldService.sayHello("petra"));
}
public void testHelloWorldGlobal() throws Exception {
- assertEquals(helloWorldService.sayHello("artep"), "Hello to artep from
the Ruby World!");
+ assertEquals(helloWorldService.sayHello("artep"), "Hey Howdy from Java
Reference artep");
//System.out.println(helloWorldService.sayHello("artep"));
+ }
+
+ public void testHelloWorldProperty() throws Exception {
+ HelloWorldService helloWorldService =
context.locateService(HelloWorldService.class, "HelloWorldProperty");
+ assertEquals(helloWorldService.sayHello("petra"), "Namaskaar petra");
+ //System.out.println(helloWorldService.sayHello("petra"));
+ }
+
+ public void testHelloWorldPropertyDefault() throws Exception {
+ HelloWorldService helloWorldService =
context.locateService(HelloWorldService.class, "HelloWorldPropertyDefault");
+ assertEquals(helloWorldService.sayHello("petra"), "Bow Wow petra");
+ //System.out.println(helloWorldService.sayHello("petra"));
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
}
}
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.componentType
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.componentType?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.componentType
(original)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.componentType
Sun Oct 8 02:42:32 2006
@@ -4,4 +4,8 @@
<service name="HelloWorldService">
<interface.java interface="helloworld.HelloWorldService"/>
</service>
+ <reference name="extHelloWorld">
+ <interface.java interface="helloworld.HelloWorldService"/>
+ </reference>
+ <property name="greeting" type="xsd:string">Hullow</property>
</componentType>
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.rb
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.rb?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.rb
(original)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.rb
Sun Oct 8 02:42:32 2006
@@ -7,7 +7,10 @@
end
class HelloWorldServiceRubyImpl
+ attr_writer :extHelloWorld
+ attr_writer :greeting
+
def sayHello(s)
- return "Hello to " + s + " from the Ruby World!"
+ return @greeting + " " + @extHelloWorld.sayHello(s);
end
end
Modified:
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/helloworld.scdl
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/helloworld.scdl?view=diff&rev=454110&r1=454109&r2=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/helloworld.scdl
(original)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/helloworld.scdl
Sun Oct 8 02:42:32 2006
@@ -22,7 +22,23 @@
name="HelloWorldComposite">
- <component name="HelloWorldComponent">
+ <component name="HelloWorldRubyComponent">
<rb:implementation.rb
script="org/apache/tuscany/container/ruby/function/HelloWorld.rb"
class="HelloWorldServiceRubyImpl"/>
+ <reference name="extHelloWorld"
target="HelloWorldJavaReference">HelloWorldJavaReference</reference>
+ <property name="greeting">Hey</property>
+ </component>
+
+ <component name="HelloWorldJavaReference">
+ <implementation.java class="helloworld.HelloWorldServiceImpl"/>
+ <property name="greeting">Howdy</property>
+ </component>
+
+ <component name="HelloWorldProperty">
+ <rb:implementation.rb
script="org/apache/tuscany/container/ruby/function/propertyTest.rb"
class="HelloWorldPropertyTest"/>
+ <property name="GREETING">Namaskaar</property>
+ </component>
+
+ <component name="HelloWorldPropertyDefault">
+ <rb:implementation.rb
script="org/apache/tuscany/container/ruby/function/propertyTest.rb"
class="HelloWorldPropertyTest"/>
</component>
</composite>
Added:
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/propertyTest.componentType
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/propertyTest.componentType?view=auto&rev=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/propertyTest.componentType
(added)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/propertyTest.componentType
Sun Oct 8 02:42:32 2006
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="ASCII"?>
+
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <service name="HelloWorldService">
+ <interface.java interface="helloworld.HelloWorldService"/>
+ </service>
+ <property name="GREETING" type="xsd:string">Bow Wow</property>
+</componentType>
Added:
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/propertyTest.rb
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/propertyTest.rb?view=auto&rev=454110
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/propertyTest.rb
(added)
+++
incubator/tuscany/java/sca/services/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/propertyTest.rb
Sun Oct 8 02:42:32 2006
@@ -0,0 +1,7 @@
+class HelloWorldPropertyTest
+ attr_writer :GREETING
+
+ def sayHello(s)
+ return @GREETING + " " + s;
+ end
+end
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]