You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2006/09/12 10:14:44 UTC
svn commit: r442514 - in
/incubator/tuscany/java/sca/containers/container.ruby: ./
src/main/java/org/apache/tuscany/container/ruby/
src/main/java/org/apache/tuscany/container/ruby/rubyscript/
src/main/resources/META-INF/sca/ src/test/java/org/apache/tu...
Author: antelder
Date: Tue Sep 12 01:14:43 2006
New Revision: 442514
URL: http://svn.apache.org/viewvc?view=rev&rev=442514
Log:
TUSCANY-716, Apply patch from Venkat for Ruby container improvements
Added:
incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyIntrospector.java (with props)
incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubySCAConfig.java (with props)
incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyImplementationLoaderTestCase.java (with props)
incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyScriptIntrospectorTestCase.java (with props)
incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/ScriptInvokeTestCase.java (with props)
incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java (with props)
incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/mock/
incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/mock/Greeting.java (with props)
incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/IntrospectableHelloWorld.rb
incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/jruby/
incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/jruby/helloworld.wsdl (with props)
incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/mock/
incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/mock/test.rb
Removed:
incubator/tuscany/java/sca/containers/container.ruby/src/main/resources/META-INF/sca/js.system.scdl
Modified:
incubator/tuscany/java/sca/containers/container.ruby/pom.xml
incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponent.java
incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentBuilder.java
incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentTypeLoader.java
incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyImplementation.java
incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyImplementationLoader.java
incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScript.java
incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/function/HelloWorldTestCase.java
incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.rb
incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/helloworld.scdl
Modified: incubator/tuscany/java/sca/containers/container.ruby/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/pom.xml?view=diff&rev=442514&r1=442513&r2=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/pom.xml (original)
+++ incubator/tuscany/java/sca/containers/container.ruby/pom.xml Tue Sep 12 01:14:43 2006
@@ -52,6 +52,12 @@
<scope>compile</scope>
</dependency>
<dependency>
+ <groupId>org.apache.tuscany.idl</groupId>
+ <artifactId>wsdl</artifactId>
+ <version>${sca.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.tuscany</groupId>
<artifactId>test</artifactId>
<version>${sca.version}</version>
Modified: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponent.java?view=diff&rev=442514&r1=442513&r2=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponent.java (original)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponent.java Tue Sep 12 01:14:43 2006
@@ -18,9 +18,6 @@
*/
package org.apache.tuscany.container.ruby;
-import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
-
-import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -42,16 +39,19 @@
/**
* The Ruby component implementation.
*/
-public class RubyComponent<T> extends AtomicComponentExtension<T> {
+public class RubyComponent extends AtomicComponentExtension {
private final List<Class<?>> services;
private final Map<String, Object> properties;
private RubyScript rubyScript;
+
+ private String rubyClassName;
public RubyComponent(String name,
RubyScript rubyScript,
+ String rubyClassName,
List<Class<?>> services,
CompositeComponent parent,
ScopeContainer scopeContainer,
@@ -60,6 +60,7 @@
super(name, parent, scopeContainer, wireService, workContext, null, 0);
this.rubyScript = rubyScript;
+ this.rubyClassName = rubyClassName;
this.services = services;
this.scope = scopeContainer.getScope();
this.properties = new HashMap<String, Object>();
@@ -70,7 +71,7 @@
Map<String, Object> context = new HashMap<String, Object>(getProperties());
for (List<OutboundWire> referenceWires : getOutboundWires().values()) {
- for (OutboundWire<?> wire : referenceWires) {
+ 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
@@ -88,16 +89,16 @@
}
}
- Object instance = rubyScript.createScriptInstance();
+ Object instance = rubyScript.createScriptInstance(rubyClassName);
return instance;
}
public TargetInvoker createTargetInvoker(String targetName, Operation operation) {
- Method[] methods = operation.getServiceContract().getInterfaceClass().getMethods();
+ /*Method[] methods = operation.getServiceContract().getInterfaceClass().getMethods();
Method method = findMethod(operation,
- methods);
- return new RubyInvoker(method.getName(), this, method.getReturnType());
+ methods);*/
+ return new RubyInvoker(operation.getName(), this, operation.getOutputType().getPhysical().getClass());
}
// TODO: move all the following up to AtomicComponentExtension?
@@ -114,19 +115,19 @@
return (RubyScriptInstance) scopeContainer.getInstance(this);
}
- public T getServiceInstance() throws TargetException {
+ public Object getServiceInstance() throws TargetException {
return getServiceInstance(null);
}
@SuppressWarnings("unchecked")
- public T getServiceInstance(String service) throws TargetException {
- InboundWire<?> wire = getInboundWire(service);
+ public Object getServiceInstance(String service) throws TargetException {
+ InboundWire wire = getInboundWire(service);
if (wire == null) {
TargetException e = new TargetException("ServiceDefinition not found"); // TODO better error message
e.setIdentifier(service);
throw e;
}
- return (T) wireService.createProxy(wire);
+ return wireService.createProxy(wire);
}
}
Modified: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentBuilder.java?view=diff&rev=442514&r1=442513&r2=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentBuilder.java (original)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentBuilder.java Tue Sep 12 01:14:43 2006
@@ -23,7 +23,6 @@
import java.util.List;
import org.apache.tuscany.container.ruby.rubyscript.RubyScript;
-import org.apache.tuscany.spi.annotation.Autowire;
import org.apache.tuscany.spi.builder.BuilderConfigException;
import org.apache.tuscany.spi.component.Component;
import org.apache.tuscany.spi.component.CompositeComponent;
@@ -33,7 +32,6 @@
import org.apache.tuscany.spi.model.ComponentDefinition;
import org.apache.tuscany.spi.model.Scope;
import org.apache.tuscany.spi.model.ServiceDefinition;
-import org.osoa.sca.annotations.Constructor;
/**
* Extension point for creating {@link RubyComponent}s from an assembly configuration
@@ -51,20 +49,16 @@
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;
- }
-*/
+ /*
+ * XmlInstanceRegistry xmlInstRegistry; @Constructor({"xmlInstRegistry"}) public RubyComponentBuilder(@Autowire XmlInstanceRegistry reg) {
+ * this.xmlInstRegistry = reg; }
+ */
protected Class<RubyImplementation> getImplementationType() {
return RubyImplementation.class;
}
@SuppressWarnings("unchecked")
- public Component<?> build(CompositeComponent<?> parent,
+ public Component build(CompositeComponent parent,
ComponentDefinition<RubyImplementation> componentDefinition,
DeploymentContext deploymentContext) throws BuilderConfigException {
@@ -90,7 +84,13 @@
scopeContainer = scopeRegistry.getScopeContainer(scope);
}
- return new RubyComponent(name, rubyScript, services, parent, scopeContainer, wireService,
- workContext);
+ return new RubyComponent(name,
+ rubyScript,
+ implementation.getRubyClassName(),
+ services,
+ parent,
+ scopeContainer,
+ wireService,
+ workContext);
}
}
Modified: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentTypeLoader.java?view=diff&rev=442514&r1=442513&r2=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentTypeLoader.java (original)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyComponentTypeLoader.java Tue Sep 12 01:14:43 2006
@@ -20,12 +20,16 @@
import java.net.URL;
+import org.apache.tuscany.container.ruby.rubyscript.RubySCAConfig;
+import org.apache.tuscany.container.ruby.rubyscript.RubyScript;
import org.apache.tuscany.spi.annotation.Autowire;
import org.apache.tuscany.spi.component.CompositeComponent;
import org.apache.tuscany.spi.deployer.DeploymentContext;
import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.MissingResourceException;
import org.apache.tuscany.spi.model.ComponentType;
/**
@@ -44,6 +48,26 @@
protected Class<RubyImplementation> getImplementationClass() {
return RubyImplementation.class;
}
+
+ protected RubyComponentType loadByIntrospection(CompositeComponent parent,
+ RubyImplementation implementation,
+ DeploymentContext deploymentContext) throws
+ MissingResourceException,
+ InvalidServiceContractException {
+
+ RubyScript rubyScript = implementation.getRubyScript();
+ RubySCAConfig scaConfig = rubyScript.getSCAConfig();
+ if (!scaConfig.hasSCAConfig()) {
+ throw new IllegalArgumentException(
+ "must use either .componentType side file or Ruby Global variable $SCA definition");
+ }
+
+ // FIXME this should be a system service, not instantiated here
+ RubyComponentType componentType = new RubyIntrospector(null, processorRegistry)
+ .introspectScript(scaConfig, rubyScript.getClassLoader());
+
+ return componentType;
+ }
protected String getResourceName(RubyImplementation implementation) {
return implementation.getRubyScript().getScriptName();
@@ -51,16 +75,25 @@
// TODO: must be possible to move all the following up in to ComponentTypeLoaderExtension
- public void load(CompositeComponent<?> parent,
+ public void load(CompositeComponent parent,
RubyImplementation implementation,
DeploymentContext deploymentContext) throws LoaderException {
- URL resource = implementation.getRubyScript().getClassLoader()
- .getResource(getSideFileName(implementation));
+ URL resource = implementation.getRubyScript().getClassLoader().getResource(getSideFileName(implementation));
RubyComponentType componentType;
- componentType = loadFromSidefile(resource,
- deploymentContext);
+ if (resource == null) {
+ try {
+ componentType = loadByIntrospection(parent, implementation, deploymentContext);
+ } catch (InvalidServiceContractException e) {
+ throw new LoaderException("Invalid service contract", e);
+ }
+ } else {
+ componentType = loadFromSidefile(resource, deploymentContext);
+ }
+
implementation.setComponentType(componentType);
+
+
}
protected RubyComponentType loadFromSidefile(URL url, DeploymentContext deploymentContext) throws LoaderException {
Modified: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyImplementation.java?view=diff&rev=442514&r1=442513&r2=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyImplementation.java (original)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyImplementation.java Tue Sep 12 01:14:43 2006
@@ -27,6 +27,16 @@
public class RubyImplementation extends AtomicImplementation<RubyComponentType> {
private RubyScript rubyScript;
+
+ private String rubyClassName;
+
+ public String getRubyClassName() {
+ return rubyClassName;
+ }
+
+ public void setRubyClassName(String rubyClassName) {
+ this.rubyClassName = rubyClassName;
+ }
public RubyScript getRubyScript() {
return rubyScript;
Modified: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyImplementationLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyImplementationLoader.java?view=diff&rev=442514&r1=442513&r2=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyImplementationLoader.java (original)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyImplementationLoader.java Tue Sep 12 01:14:43 2006
@@ -62,7 +62,9 @@
String script = reader.getAttributeValue(null,
"script");
- if (script == null) {
+ String rubyClassName = reader.getAttributeValue(null,"class");
+
+ if ( script == null ) {
throw new MissingResourceException("No script supplied");
}
@@ -75,6 +77,7 @@
RubyImplementation implementation = new RubyImplementation();
RubyScript rubyScript = new RubyScript(script, source, null, cl);
implementation.setRubyScript(rubyScript);
+ implementation.setRubyClassName(rubyClassName);
registry.loadComponentType(parent,
implementation,
deploymentContext);
Added: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyIntrospector.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyIntrospector.java?view=auto&rev=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyIntrospector.java (added)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyIntrospector.java Tue Sep 12 01:14:43 2006
@@ -0,0 +1,173 @@
+/*
+ * 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.util.Iterator;
+import java.util.Map;
+
+import javax.wsdl.Definition;
+import javax.wsdl.PortType;
+import javax.wsdl.WSDLException;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.container.ruby.rubyscript.RubySCAConfig;
+import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry;
+import org.apache.tuscany.idl.wsdl.WSDLServiceContract;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * Introspects JavaScript files for SCA configuration
+ */
+public class RubyIntrospector {
+
+ private WSDLDefinitionRegistry wsdlRegistry;
+ private JavaInterfaceProcessorRegistry processorRegistry;
+
+ public RubyIntrospector(@Autowire WSDLDefinitionRegistry wsdlRegistry,
+ @Autowire JavaInterfaceProcessorRegistry processorRegistry) {
+ this.wsdlRegistry = wsdlRegistry;
+ this.processorRegistry = processorRegistry;
+ }
+
+ public RubyComponentType introspectScript(RubySCAConfig scaConfig, ClassLoader cl)
+ throws MissingResourceException, InvalidServiceContractException {
+ RubyComponentType componentType = new RubyComponentType();
+ introspectJavaInterface(componentType, cl, scaConfig.getJavaInterface());
+ introspectWSDLInterface(componentType, cl, scaConfig.getWSDLNamespace(), scaConfig.getWSDLPortType(),
+ scaConfig.getWSDLLocation());
+ introspectReferences(componentType, cl, scaConfig.getReferences());
+ introspectProperties(componentType, cl, scaConfig.getProperties());
+ introspectScope(componentType, scaConfig.getScope());
+ return componentType;
+ }
+
+ private void introspectScope(RubyComponentType componentType, Scope scope) {
+ if (scope != null) {
+ componentType.setLifecycleScope(scope);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void introspectJavaInterface(ComponentType componentType, ClassLoader cl, String serviceClass)
+ throws MissingResourceException, InvalidServiceContractException {
+ if (serviceClass != null) {
+ ServiceDefinition service = new ServiceDefinition();
+ try {
+ ServiceContract<?> sc = processorRegistry.introspect(Class.forName(serviceClass));
+ service.setServiceContract(sc);
+ componentType.add(service);
+ } catch (ClassNotFoundException e) {
+ throw new MissingResourceException("Interface not found", e);
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void introspectWSDLInterface(ComponentType componentType, ClassLoader cl, String wsdlNamespace,
+ String wsdlPortType, String wsdlLocation) {
+ if (wsdlNamespace == null && wsdlPortType == null && wsdlLocation == null) {
+ return;
+ }
+
+ PortType portType = null;
+ if (wsdlLocation != null) {
+ portType = readWSDLPortType(wsdlNamespace, wsdlPortType, wsdlLocation, portType);
+ } else {
+ portType = getPortType(wsdlNamespace, wsdlPortType);
+ }
+
+ ServiceDefinition service = new ServiceDefinition();
+ WSDLServiceContract wsdlSC = new WSDLServiceContract();
+ wsdlSC.setPortType(portType);
+ service.setServiceContract(wsdlSC);
+ componentType.add(service);
+ }
+
+ private PortType readWSDLPortType(String wsdlNamespace, String wsdlPortType, String wsdlLocation,
+ PortType portType) {
+ Definition wsdlDefinition;
+ try {
+ WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
+ reader.setFeature("javax.wsdl.verbose", false);
+ wsdlDefinition = reader.readWSDL(wsdlLocation.toString());
+ } catch (WSDLException e) {
+ throw new RuntimeException(e);
+
+ }
+ Map portTypes = wsdlDefinition.getPortTypes();
+ for (Iterator i = portTypes.keySet().iterator(); i.hasNext();) {
+ QName portTypeQN = (QName) i.next();
+ if (wsdlNamespace != null) {
+ if (!portTypeQN.getNamespaceURI().equals(wsdlNamespace)) {
+ continue;
+ }
+ }
+ if (wsdlPortType != null) {
+ if (!portTypeQN.getLocalPart().equals(wsdlPortType)) {
+ continue;
+ }
+ }
+ if (portType != null) {
+ throw new RuntimeException("multiple matching portTypes in wsdl: " + wsdlLocation);
+ }
+ portType = (PortType) portTypes.get(portTypeQN);
+ }
+ if (portType == null) {
+ throw new RuntimeException("portType not found in wsdl: " + wsdlLocation);
+ }
+ return portType;
+ }
+
+ private PortType getPortType(String wsdlNamespace, String wsdlPortType) {
+ if (wsdlPortType == null) {
+ throw new IllegalArgumentException("must specify the wsdlPortType in script SCA config");
+ }
+ PortType portType = null;
+ if (wsdlNamespace != null) {
+ QName portTypeQN = new QName(wsdlNamespace.toString(), wsdlPortType.toString());
+ portType = wsdlRegistry.getPortType(portTypeQN);
+ if (portType == null) {
+ throw new IllegalArgumentException("no WSDL registered for portType: " + portTypeQN);
+ }
+ } else {
+ // wsdlRegistry.getPortType(wsdlPortType.toString());
+ if (portType == null) {
+ throw new IllegalArgumentException("no WSDL registered for portType:" + wsdlPortType);
+ }
+ }
+ return portType;
+ }
+
+
+ private void introspectProperties(ComponentType componentType, ClassLoader cl, Map properties) {
+ }
+
+ private void introspectReferences(ComponentType componentType, ClassLoader cl, Map references) {
+ }
+
+}
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyIntrospector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/RubyIntrospector.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubySCAConfig.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubySCAConfig.java?view=auto&rev=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubySCAConfig.java (added)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubySCAConfig.java Tue Sep 12 01:14:43 2006
@@ -0,0 +1,159 @@
+/*
+ * 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.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.Scope;
+import org.jruby.RubyHash;
+import org.jruby.RubyObject;
+import org.jruby.internal.runtime.GlobalVariables;
+import org.jruby.runtime.builtin.IRubyObject;
+
+/**
+ * Represents the variable defining the SCA aspects of the script
+ * <code>
+ * SCA = {
+ * javaInterface : "my.pkg.ClassName",
+ * wsdlPortType : "wsdlPortTypeName",
+ * wsdlNameSpace : "http://my.namespace.com",
+ * wsdlLocation : "\wsdl\mywsdl.txt",
+ * properties : { "foo" : ["java.lang.String", "defaultValue"],},
+ * references : {},
+ * scope : 'stateless'|'request'|'conversational'|'composite',
+ * }
+ * </code>
+ * The config must define the service with either javaInterface or wsdl. When
+ * using wsdl the three parameters are optional. If wsdlLocation is used that is the
+ * WSDL document used, and the namespace and portType parameters are only required if
+ * the WSDL definition defines multiple portTypes.
+ */
+public class RubySCAConfig {
+
+ private boolean hasSCAConfig;
+
+ private String javaInterface;
+
+ private String wsdlLocation;
+
+ private String wsdlNamespace;
+
+ private String wsdlPortType;
+
+ private Map properties;
+
+ private Map references;
+
+ private Scope scope;
+
+ public RubySCAConfig(GlobalVariables globalVariables) {
+ IRubyObject rubyObject = globalVariables.get("$SCA");
+ if (rubyObject != null && !rubyObject.isNil()) {
+ hasSCAConfig = true;
+ RubyHash scaVar = (RubyHash) rubyObject;
+ Object o = scaVar.get("javaInterface");
+ if ( o != null ) {
+ this.javaInterface = o.toString();
+ }
+ o = scaVar.get("wsdlLocation");
+ if (o != null ) {
+ this.wsdlLocation = o.toString();
+ }
+ o = scaVar.get("wsdlPortType");
+ if (o != null ) {
+ this.wsdlPortType = o.toString();
+ }
+ o = scaVar.get("wsdlNamespace");
+ if (o != null ) {
+ this.wsdlNamespace = o.toString();
+ }
+ if (javaInterface != null) {
+ if (wsdlLocation != null || wsdlPortType != null || wsdlNamespace != null) {
+ throw new IllegalArgumentException("script SCA config defines both Java and WSDL service interface");
+ }
+ } else {
+ if (wsdlLocation == null && wsdlPortType == null && wsdlNamespace == null) {
+ throw new IllegalArgumentException("script SCA config must define either Java or WSDL service interface");
+ }
+ }
+
+ this.properties = new HashMap();
+ o = scaVar.get("properties");
+ if (o != null ) {
+ // TODO parse properties
+ }
+
+ this.references = new HashMap();
+ o = scaVar.get("references");
+ if (o != null ) {
+ // TODO parse references
+ }
+
+ o = scaVar.get("scope");
+ if (o != null ) {
+ if ("stateless".equalsIgnoreCase(String.valueOf(o))) {
+ this.scope = Scope.STATELESS;
+ } else if ("request".equalsIgnoreCase(String.valueOf(o))) {
+ this.scope = Scope.REQUEST;
+ } else if ("conversational".equalsIgnoreCase(String.valueOf(o))) {
+ this.scope = Scope.SESSION; // TODO: where's CONVERSATIONAL?
+ } else if ("composite".equalsIgnoreCase(String.valueOf(o))) {
+ this.scope = Scope.MODULE; // TODO: composite = MODULE for now?
+ } else {
+ throw new IllegalArgumentException("invalid scope value: " + o);
+ }
+ }
+
+ }
+ }
+
+ public boolean hasSCAConfig() {
+ return hasSCAConfig;
+ }
+
+ public String getJavaInterface() {
+ return javaInterface;
+ }
+
+ public Map getProperties() {
+ return properties;
+ }
+
+ public Map getReferences() {
+ return references;
+ }
+
+ public String getWSDLLocation() {
+ return wsdlLocation;
+ }
+
+ public String getWSDLNamespace() {
+ return wsdlNamespace;
+ }
+
+ public String getWSDLPortType() {
+ return wsdlPortType;
+ }
+
+ public Scope getScope() {
+ return scope;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubySCAConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubySCAConfig.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScript.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScript.java?view=diff&rev=442514&r1=442513&r2=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScript.java (original)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/main/java/org/apache/tuscany/container/ruby/rubyscript/RubyScript.java Tue Sep 12 01:14:43 2006
@@ -23,12 +23,15 @@
import java.util.Vector;
import org.jruby.IRuby;
+import org.jruby.RubyString;
import org.jruby.javasupport.JavaEmbedUtils;
+import org.jruby.javasupport.JavaUtil;
/**
* A RhinoScript represents a compiled JavaScript script
*/
public class RubyScript {
+ protected final String NEW = ".new";
protected String scriptName;
@@ -38,7 +41,7 @@
protected ClassLoader classLoader;
- private static IRuby rubyEngine = JavaEmbedUtils.initialize(new Vector());
+ private IRuby rubyEngine = JavaEmbedUtils.initialize(new Vector());
/**
* Create a new RubyScript.
@@ -70,6 +73,13 @@
this.script = script;
this.responseClasses = new HashMap<String, Class>();
this.classLoader = classLoader;
+ rubyEngine.loadScript((RubyString) JavaUtil.convertJavaToRuby(rubyEngine,
+ "MyScript.rb",
+ String.class),
+ (RubyString) JavaUtil.convertJavaToRuby(rubyEngine,
+ this.script,
+ String.class),
+ false);
}
/**
@@ -77,8 +87,13 @@
*
* @return a IRubyObject
*/
- public RubyScriptInstance createScriptInstance() {
- return new RubyScriptInstance(rubyEngine.evalScript(getScript()), responseClasses);
+ public RubyScriptInstance createScriptInstance(String rubyClassName) {
+ if ( rubyClassName == null ) {
+ return new RubyScriptInstance(rubyEngine.evalScript(script), responseClasses);
+ }
+ else {
+ return new RubyScriptInstance(rubyEngine.evalScript(rubyClassName + NEW), responseClasses);
+ }
}
public String getScript() {
@@ -106,9 +121,21 @@
this.responseClasses.put(functionName,
responseClasses);
}
+
+ public RubySCAConfig getSCAConfig() {
+ return new RubySCAConfig(rubyEngine.getGlobalVariables());
+ }
public void setScript(String script) {
this.script = script;
+ }
+
+ public IRuby getRubyEngine() {
+ return rubyEngine;
+ }
+
+ public void setRubyEngine(IRuby rubyEngine) {
+ this.rubyEngine = rubyEngine;
}
}
Added: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyImplementationLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyImplementationLoaderTestCase.java?view=auto&rev=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyImplementationLoaderTestCase.java (added)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyImplementationLoaderTestCase.java Tue Sep 12 01:14:43 2006
@@ -0,0 +1,109 @@
+/*
+ * 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 javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.classextension.EasyMock.createMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+
+/**
+ * Tests for RubyImplementationLoader
+ */
+public class RubyImplementationLoaderTestCase extends TestCase {
+ private CompositeComponent parent;
+
+ private XMLStreamReader reader;
+
+ private DeploymentContext deploymentContext;
+
+ private ClassLoader classLoader;
+
+ private LoaderRegistry registry;
+
+ private RubyImplementationLoader loader;
+
+ public void testNoScriptAttribute() throws LoaderException, XMLStreamException {
+ expect(reader.getAttributeValue(null, "script")).andReturn(null);
+ expect(reader.getAttributeValue(null, "class")).andReturn(null);
+ replay(reader);
+ replay(deploymentContext);
+
+ try {
+ loader.load(parent, reader, deploymentContext);
+ fail();
+ } catch (MissingResourceException e) {
+ // ok
+ }
+ verify(reader);
+ verify(deploymentContext);
+ }
+
+ public void testNoScriptPresent() throws LoaderException, XMLStreamException {
+ expect(reader.getAttributeValue(null, "script")).andReturn("foo.groovy");
+ expect(reader.getAttributeValue(null, "class")).andReturn(null);
+ expect(deploymentContext.getClassLoader()).andReturn(classLoader);
+
+ replay(reader);
+ replay(deploymentContext);
+
+ RubyImplementationLoader mockLoader = new RubyImplementationLoader(registry) {
+ protected String loadSource(ClassLoader cl, String resource) throws LoaderException {
+ assertSame(classLoader, cl);
+ assertEquals("foo.groovy", resource);
+ throw new MissingResourceException(resource);
+ }
+ };
+ try {
+ mockLoader.load(parent, reader, deploymentContext);
+ fail();
+ } catch (MissingResourceException e) {
+ assertEquals("foo.groovy", e.getMessage());
+ }
+ verify(reader);
+ verify(deploymentContext);
+ }
+
+ public void testLoadScript() throws LoaderException {
+ String script =
+ loader.loadSource(getClass().getClassLoader(), "org/apache/tuscany/container/ruby/mock/test.rb");
+ assertEquals("//Test Script", script);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = createMock(LoaderRegistry.class);
+ loader = new RubyImplementationLoader(registry);
+
+ parent = createMock(CompositeComponent.class);
+ reader = createMock(XMLStreamReader.class);
+ deploymentContext = createMock(DeploymentContext.class);
+ classLoader = createMock(ClassLoader.class);
+ }
+}
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyImplementationLoaderTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyImplementationLoaderTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyScriptIntrospectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyScriptIntrospectorTestCase.java?view=auto&rev=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyScriptIntrospectorTestCase.java (added)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyScriptIntrospectorTestCase.java Tue Sep 12 01:14:43 2006
@@ -0,0 +1,130 @@
+/*
+ * 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 helloworld.HelloWorldService;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+
+import javax.wsdl.WSDLException;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.ruby.rubyscript.RubySCAConfig;
+import org.apache.tuscany.container.ruby.rubyscript.RubyScript;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl;
+import org.apache.tuscany.idl.wsdl.WSDLServiceContract;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+public class RubyScriptIntrospectorTestCase extends TestCase {
+
+ private static final WSDLDefinitionRegistryImpl.Monitor NULL_MONITOR = new WSDLDefinitionRegistryImpl.Monitor() {
+ public void readingWSDL(String namespace, URL location) {
+ }
+
+ public void cachingDefinition(String namespace, URL location) {
+ }
+ };
+
+ public void testJavaInterface() throws MissingResourceException,
+ InvalidServiceContractException {
+ RubyScript rs = new RubyScript("javaInterfaceTest",
+ "$SCA = { 'javaInterface' => 'helloworld.HelloWorldService'}",
+ null,
+ getClass().getClassLoader());
+ RubySCAConfig scaConfig = new RubySCAConfig(rs.getRubyEngine().getGlobalVariables());
+ RubyIntrospector introspector = new RubyIntrospector(null,
+ new JavaInterfaceProcessorRegistryImpl());
+ ComponentType comonentType = introspector.introspectScript(scaConfig,
+ rs.getClassLoader());
+ assertNotNull(comonentType);
+ Map services = comonentType.getServices();
+ assertEquals(1,
+ services.size());
+ ServiceDefinition serviceDefinition = (ServiceDefinition) services.values()
+ .iterator()
+ .next();
+ ServiceContract serviceContract = serviceDefinition.getServiceContract();
+ assertTrue(serviceContract instanceof JavaServiceContract);
+ JavaServiceContract javaServiceContract = (JavaServiceContract) serviceContract;
+ assertEquals(HelloWorldService.class,
+ javaServiceContract.getInterfaceClass());
+ }
+
+ public void testWSDLLocation() throws WSDLException {
+ // RhinoScript rs = new RhinoScript("wsdlLocation",
+ // "SCA = { wsdlLocation : 'src/test/resources/org/apache/tuscany/container/javascript/rhino/helloworld.wsdl',};", null, getClass()
+ // .getClassLoader());
+ // RhinoSCAConfig scaConfig = new RhinoSCAConfig(rs.getScriptScope());
+ // JavaScriptIntrospector introspector = new JavaScriptIntrospector(null);
+ // ComponentType comonentType = introspector.introspectScript(scaConfig, rs.getClassLoader());
+ // assertNotNull(comonentType);
+ // Map services = comonentType.getServices();
+ // assertEquals(1, services.size());
+ // ServiceDefinition serviceDefinition = (ServiceDefinition) services.values().iterator().next();
+ // ServiceContract serviceContract = serviceDefinition.getServiceContract();
+ // assertTrue(serviceContract instanceof WSDLServiceContract);
+ // WSDLServiceContract wsdlServiceContract = (WSDLServiceContract) serviceContract;
+ // assertEquals(new QName("http://helloworld", "HelloWorld"), wsdlServiceContract.getPortType().getQName());
+ }
+
+ public void testWSDLPortType() throws WSDLException,
+ IOException,
+ MissingResourceException,
+ InvalidServiceContractException {
+ RubyScript rs = new RubyScript("wsdlPortType",
+ "$SCA = { 'wsdlPortType' => 'HelloWorld', 'wsdlNamespace' => 'http://helloworld'}",
+ null,
+ getClass().getClassLoader());
+ RubySCAConfig scaConfig = new RubySCAConfig(rs.getRubyEngine().getGlobalVariables());
+
+ WSDLDefinitionRegistryImpl wsdlReg = new WSDLDefinitionRegistryImpl();
+ wsdlReg.setMonitor(NULL_MONITOR);
+ URL wsdlURL = getClass().getClassLoader()
+ .getResource("org/apache/tuscany/container/ruby/jruby/helloworld.wsdl");
+ wsdlReg.loadDefinition("http://helloworld",
+ wsdlURL);
+
+ RubyIntrospector introspector = new RubyIntrospector(wsdlReg,
+ new JavaInterfaceProcessorRegistryImpl());
+ ComponentType comonentType = introspector.introspectScript(scaConfig,
+ rs.getClassLoader());
+ assertNotNull(comonentType);
+ Map services = comonentType.getServices();
+ assertEquals(1,
+ services.size());
+ ServiceDefinition serviceDefinition = (ServiceDefinition) services.values()
+ .iterator()
+ .next();
+ ServiceContract serviceContract = serviceDefinition.getServiceContract();
+ assertTrue(serviceContract instanceof WSDLServiceContract);
+ WSDLServiceContract wsdlServiceContract = (WSDLServiceContract) serviceContract;
+ assertEquals(new QName("http://helloworld", "HelloWorld"),
+ wsdlServiceContract.getPortType().getQName());
+ }
+}
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyScriptIntrospectorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/RubyScriptIntrospectorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/ScriptInvokeTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/ScriptInvokeTestCase.java?view=auto&rev=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/ScriptInvokeTestCase.java (added)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/ScriptInvokeTestCase.java Tue Sep 12 01:14:43 2006
@@ -0,0 +1,54 @@
+/*
+ * 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 junit.framework.TestCase;
+
+import org.apache.tuscany.container.ruby.rubyscript.RubyScript;
+
+/**
+ * Tests for invoker JavaScriptComponents
+ */
+public class ScriptInvokeTestCase extends TestCase {
+
+ private static final String SCRIPT = "def greet(name) \n return name \n end \n";
+
+ private RubyScript rubyScript;
+
+ /**
+ * Tests the invocation of a Groovy "script" as opposed to a class
+ */
+ public void testBasicScriptInvocation() throws Exception {
+// ModuleScopeContainer scope = new ModuleScopeContainer(null);
+// scope.start();
+// List<Class<?>> services = new ArrayList<Class<?>>();
+// services.add(Greeting.class);
+// RubyComponent<Greeting> context = new RubyComponent<Greeting>("source", rhinoScript, services, new HashMap<String, Object>(),
+// null, scope, ArtifactFactory.createWireService(), null);
+// scope.register(context);
+// Greeting object = (Greeting) context.getServiceInstance();
+// assertEquals("foo", object.greet("foo"));
+// scope.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ rubyScript = new RubyScript("test", SCRIPT);
+ }
+}
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/ScriptInvokeTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/ScriptInvokeTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java?view=auto&rev=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java (added)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java Tue Sep 12 01:14:43 2006
@@ -0,0 +1,177 @@
+/*
+ * 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 static org.easymock.EasyMock.reportMatcher;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.ruby.mock.Greeting;
+import org.apache.tuscany.container.ruby.rubyscript.RubyScript;
+import org.apache.tuscany.core.component.scope.ModuleScopeContainer;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.test.ArtifactFactory;
+import org.easymock.IArgumentMatcher;
+
+/**
+ * Tests for JavaScript component wiring
+ */
+public class WireTestCase extends TestCase {
+
+ private static final String SCRIPT = " def setWire(ref)\n" + " wire = ref\n"
+ + "end \n" + " def greet(name)\n" + " return wire.greet(name) \n"
+ + " end\n";
+
+ private static final String SCRIPT2 = " def greet(name)\n" + " return name \n"
+ + "end \n";
+
+ private RubyScript implClass1;
+
+ private RubyScript implClass2;
+
+ /**
+ * Tests a basic invocation down a source wire
+ */
+ public void testReferenceWireInvocation() throws Exception {
+ // ModuleScopeContainer scope = new ModuleScopeContainer(null);
+ // scope.start();
+ //
+ // List<Class<?>> services = new ArrayList<Class<?>>();
+ // services.add(Greeting.class);
+ // JavaScriptComponent<Greeting> context = new JavaScriptComponent<Greeting>("source", implClass1, services, properties, null, scope,
+ // ArtifactFactory.createWireService(), null);
+ // OutboundWire<?> wire = ArtifactFactory.createOutboundWire("wire", Greeting.class);
+ // ArtifactFactory.terminateWire(wire);
+ //
+ // TargetInvoker invoker = createMock(TargetInvoker.class);
+ // expect(invoker.isCacheable()).andReturn(false);
+ // Message response = new MessageImpl();
+ // response.setBody("foo");
+ // expect(invoker.invoke(eqMessage())).andReturn(response);
+ // replay(invoker);
+ //
+ // for (OutboundInvocationChain chain : wire.getInvocationChains().values()) {
+ // chain.setTargetInvoker(invoker);
+ // }
+ // scope.register(context);
+ // context.addOutboundWire(wire);
+ // Greeting greeting = context.getServiceInstance();
+ // assertEquals("foo", greeting.greet("foo"));
+ // verify(invoker);
+ //
+ // scope.stop();
+ }
+
+ // todo this could be generalized and moved to test module
+ public static Message eqMessage() {
+ reportMatcher(new IArgumentMatcher() {
+ public boolean matches(Object object) {
+ if (!(object instanceof Message)) {
+ return false;
+ }
+ final Message msg = (Message) object;
+ Object[] body = (Object[]) msg.getBody();
+ return "foo".equals(body[0]);
+ }
+
+ public void appendTo(StringBuffer stringBuffer) {
+ }
+ });
+ return null;
+ }
+
+ /**
+ * Tests a basic invocation to a target
+ */
+ public void testTargetInvocation() throws Exception {
+ ModuleScopeContainer scope = new ModuleScopeContainer(null);
+ scope.start();
+ List<Class<?>> services = new ArrayList<Class<?>>();
+ services.add(Greeting.class);
+ RubyComponent context = new RubyComponent("source",
+ implClass2,
+ null,
+ services,
+ null,
+ scope,
+ ArtifactFactory.createWireService(),
+ null);
+ scope.register(context);
+ DataType<String> returnDataType = new DataType<String>(String.class, String.class.getName());
+// Operation<String> operation = new Operation<String>("greet",
+// returnDataType,
+// null,
+// null,
+// false,
+// null);
+//
+// TargetInvoker invoker = context.createTargetInvoker(null,
+// operation);
+// assertEquals("foo",
+// invoker.invokeTarget(new String[]{"foo"}));
+ scope.stop();
+ }
+
+ /**
+ * Tests a basic invocation down a target wire
+ */
+ public void testTargetWireInvocation() throws Exception {
+ ModuleScopeContainer scope = new ModuleScopeContainer(null);
+ scope.start();
+ List<Class<?>> services = new ArrayList<Class<?>>();
+ services.add(Greeting.class);
+ RubyComponent context = new RubyComponent("source",
+ implClass2,
+ null,
+ services,
+ null,
+ scope,
+ ArtifactFactory.createWireService(),
+ null);
+ scope.register(context);
+
+ InboundWire wire = ArtifactFactory.createInboundWire("Greeting",
+ Greeting.class);
+ ArtifactFactory.terminateWire(wire);
+ for (InboundInvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(context.createTargetInvoker(null,
+ chain.getOperation()));
+ }
+ context.addInboundWire(wire);
+ Greeting greeting = (Greeting) context.getServiceInstance("Greeting");
+ assertEquals("foo",
+ greeting.greet("foo"));
+ scope.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ implClass1 = new RubyScript("script1", SCRIPT);
+ implClass2 = new RubyScript("script2", SCRIPT2);
+ }
+}
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/WireTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/function/HelloWorldTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/function/HelloWorldTestCase.java?view=diff&rev=442514&r1=442513&r2=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/function/HelloWorldTestCase.java (original)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/function/HelloWorldTestCase.java Tue Sep 12 01:14:43 2006
@@ -44,8 +44,13 @@
helloWorldService = context.locateService(HelloWorldService.class, "HelloWorldComponent");
}
- public void testHelloWorld() throws Exception {
+ public void testHelloWorldWithClass() throws Exception {
assertEquals(helloWorldService.sayHello("petra"), "Hello to petra from the Ruby World!");
- System.out.println(helloWorldService.sayHello("petra"));
+ //System.out.println(helloWorldService.sayHello("petra"));
+ }
+
+ public void testHelloWorldGlobal() throws Exception {
+ assertEquals(helloWorldService.sayHello("artep"), "Hello to artep from the Ruby World!");
+ //System.out.println(helloWorldService.sayHello("artep"));
}
}
Added: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/mock/Greeting.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/mock/Greeting.java?view=auto&rev=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/mock/Greeting.java (added)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/mock/Greeting.java Tue Sep 12 01:14:43 2006
@@ -0,0 +1,26 @@
+/*
+ * 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.mock;
+
+public interface Greeting {
+
+ String setWire(Greeting ref);
+
+ String greet(String name);
+}
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/mock/Greeting.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/java/org/apache/tuscany/container/ruby/mock/Greeting.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.rb
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.rb?view=diff&rev=442514&r1=442513&r2=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.rb (original)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/HelloWorld.rb Tue Sep 12 01:14:43 2006
@@ -1,3 +1,13 @@
-def sayHello(s)
- return "Hello to " + s + " from the Ruby World!"
+class Helloworld
+
+ def sayHello(s)
+ return "Hello to " + s + " from the Ruby World!"
+ end
+
+end
+
+class HelloWorldServiceRubyImpl
+ def sayHello(s)
+ return "Hello to " + s + " from the Ruby World!"
+ end
end
Added: incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/IntrospectableHelloWorld.rb
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/IntrospectableHelloWorld.rb?view=auto&rev=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/IntrospectableHelloWorld.rb (added)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/IntrospectableHelloWorld.rb Tue Sep 12 01:14:43 2006
@@ -0,0 +1,13 @@
+$SCA = {
+ 'javaInterface' => 'helloworld.HelloWorldService'
+}
+
+def sayHello(s)
+ return "Hello to " + s + " from the Ruby World!"
+end
+
+class HelloWorldServiceRubyImpl
+ def sayHello(s)
+ return "Hello to " + s + " from the Ruby World!"
+ end
+end
Modified: incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/helloworld.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/helloworld.scdl?view=diff&rev=442514&r1=442513&r2=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/helloworld.scdl (original)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/function/helloworld.scdl Tue Sep 12 01:14:43 2006
@@ -23,6 +23,6 @@
name="HelloWorldComposite">
<component name="HelloWorldComponent">
- <rb:implementation.rb script="org/apache/tuscany/container/ruby/function/HelloWorld.rb"/>
+ <rb:implementation.rb script="org/apache/tuscany/container/ruby/function/HelloWorld.rb" class="HelloWorldServiceRubyImpl"/>
</component>
</composite>
Added: incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/jruby/helloworld.wsdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/jruby/helloworld.wsdl?view=auto&rev=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/jruby/helloworld.wsdl (added)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/jruby/helloworld.wsdl Tue Sep 12 01:14:43 2006
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed 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.
+ -->
+<wsdl:definitions targetNamespace="http://helloworld" xmlns:tns="http://helloworld" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ name="helloworld">
+
+ <wsdl:types>
+ <schema elementFormDefault="qualified" targetNamespace="http://helloworld" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema">
+
+ <element name="getGreetings">
+ <complexType>
+ <sequence>
+ <element name="name" type="xsd:string"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="getGreetingsResponse">
+ <complexType>
+ <sequence>
+ <element name="getGreetingsReturn" type="xsd:string"/>
+ </sequence>
+ </complexType>
+ </element>
+ </schema>
+ </wsdl:types>
+
+ <wsdl:message name="getGreetingsRequest">
+ <wsdl:part element="tns:getGreetings" name="parameters"/>
+ </wsdl:message>
+
+ <wsdl:message name="getGreetingsResponse">
+ <wsdl:part element="tns:getGreetingsResponse" name="parameters"/>
+ </wsdl:message>
+
+ <wsdl:portType name="HelloWorld">
+ <wsdl:operation name="getGreetings">
+ <wsdl:input message="tns:getGreetingsRequest" name="getGreetingsRequest"/>
+ <wsdl:output message="tns:getGreetingsResponse" name="getGreetingsResponse"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+ <wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorld">
+ <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="getGreetings">
+ <wsdlsoap:operation soapAction=""/>
+ <wsdl:input name="getGreetingsRequest">
+ <wsdlsoap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output name="getGreetingsResponse">
+ <wsdlsoap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+
+ <wsdl:service name="HelloWorldService">
+ <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort">
+ <wsdlsoap:address location="http://localhost:8080/sample-helloworldws/services/HelloWorldWebService"/>
+ </wsdl:port>
+ </wsdl:service>
+
+</wsdl:definitions>
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/jruby/helloworld.wsdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/jruby/helloworld.wsdl
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/mock/test.rb
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/mock/test.rb?view=auto&rev=442514
==============================================================================
--- incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/mock/test.rb (added)
+++ incubator/tuscany/java/sca/containers/container.ruby/src/test/resources/org/apache/tuscany/container/ruby/mock/test.rb Tue Sep 12 01:14:43 2006
@@ -0,0 +1 @@
+//Test Script
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org