tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r511484 - in /incubator/tuscany/branches/sca-java-integration/sca/extensions/script: container.bsf/src/main/java/org/apache/tuscany/container/script/ itests/src/main/resources/calculator/ itests/src/test/java/calculator/
Date Sun, 25 Feb 2007 12:18:09 GMT
Author: antelder
Date: Sun Feb 25 04:18:08 2007
New Revision: 511484

URL: http://svn.apache.org/viewvc?view=rev&rev=511484
Log:
Get the script container working with the Ruby calculator sample from the Tuscany C++ runtime

Added:
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/CalculatorImpl.py
      - copied unchanged from r511482, incubator/tuscany/cpp/sca/samples/PythonCalculator/sample.calculator/CalculatorImpl.py
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/DivideImpl.py
      - copied unchanged from r511482, incubator/tuscany/cpp/sca/samples/PythonCalculator/sample.calculator/DivideImpl.py
Modified:
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptImplementationPythonLoader.java
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/DivideImpl.componentType
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/sample.calculator.composite
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/calculator/CalculatorClientTestCase.java

Modified: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java?view=diff&rev=511484&r1=511483&r2=511484
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
(original)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
Sun Feb 25 04:18:08 2007
@@ -75,15 +75,12 @@
         ClassLoader cl = deploymentContext.getClassLoader();
         String scriptSource = loadSource(cl, scriptName);
 
-//        ScriptInstanceFactory instanceFactory = new ScriptInstanceFactory(scriptName, className,
scriptSource, cl);
-
         ScriptImplementation implementation = new ScriptImplementation();
         implementation.setResourceName(scriptName);
         implementation.setScriptSource(scriptSource);
         implementation.setClassName(className);
         implementation.setScriptName(scriptName);
         implementation.setClassLoader(cl);
-        //implementation.setScriptInstanceFactory(instanceFactory);
 
         registry.loadComponentType(parent, implementation, deploymentContext);
 

Modified: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptImplementationPythonLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptImplementationPythonLoader.java?view=diff&rev=511484&r1=511483&r2=511484
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptImplementationPythonLoader.java
(original)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptImplementationPythonLoader.java
Sun Feb 25 04:18:08 2007
@@ -22,9 +22,17 @@
 import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
 
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 
 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.loader.LoaderException;
 import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.ModelObject;
 import org.osoa.sca.annotations.Constructor;
 
 public class ScriptImplementationPythonLoader extends ScriptImplementationLoader {
@@ -38,6 +46,33 @@
 
     public QName getXMLType() {
         return IMPLEMENTATION_PYTHON;
+    }
+
+    @Override
+    public ScriptImplementation load(CompositeComponent parent, ModelObject mo, XMLStreamReader
reader,
+                                     DeploymentContext deploymentContext) throws XMLStreamException,
LoaderException {
+        String scriptName = reader.getAttributeValue(null, "module");
+        if (scriptName == null) {
+            throw new MissingResourceException("implementation element has no 'module' attribute");
+        }
+
+        String className = reader.getAttributeValue(null, "class");
+
+        LoaderUtil.skipToEndElement(reader);
+
+        ClassLoader cl = deploymentContext.getClassLoader();
+        String scriptSource = loadSource(cl, scriptName);
+
+        ScriptImplementation implementation = new ScriptImplementation();
+        implementation.setResourceName(scriptName);
+        implementation.setScriptSource(scriptSource);
+        implementation.setClassName(className);
+        implementation.setScriptName(scriptName);
+        implementation.setClassLoader(cl);
+
+        registry.loadComponentType(parent, implementation, deploymentContext);
+
+        return implementation;
     }
 
 }

Modified: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/DivideImpl.componentType
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/DivideImpl.componentType?view=diff&rev=511484&r1=511483&r2=511484
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/DivideImpl.componentType
(original)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/DivideImpl.componentType
Sun Feb 25 04:18:08 2007
@@ -6,6 +6,7 @@
   </service>
 
   <property name="round" type="xsd:boolean">false</property>
+  <property name="doRounding" type="xsd:boolean">false</property>
 
 </componentType>              
        

Modified: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/sample.calculator.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/sample.calculator.composite?view=diff&rev=511484&r1=511483&r2=511484
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/sample.calculator.composite
(original)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/calculator/sample.calculator.composite
Sun Feb 25 04:18:08 2007
@@ -21,14 +21,25 @@
 <composite xmlns="http://www.osoa.org/xmlns/sca/1.0" 
 	name="sample.calculator">
 
-	<component name="CalculatorComponent">
+	<component name="RubyCalculatorComponent">
 		<implementation.ruby script="calculator/CalculatorImpl.rb" class="CalculatorImpl"/>
-	    <reference name="divideService">DivideComponent</reference>
+	    <reference name="divideService">RubyDivideComponent</reference>
 	</component>
         
-	<component name="DivideComponent">
+	<component name="RubyDivideComponent">
 		<implementation.ruby script="calculator/DivideImpl.rb" class="DivideImpl"/>
 		<property name="round">true</property>
 	</component>
+
+	<component name="PythonCalculatorComponent">
+        <implementation.python module="calculator/CalculatorImpl.py" scope="composite"/>
+	    <reference name="divideService">PythonDivideComponent</reference>
+	</component>
+
+    <component name="PythonDivideComponent">
+        <implementation.python module="calculator/DivideImpl.py" scope="composite"/>
+        <property name="doRounding">false</property>
+     </component>
+
 
 </composite>

Modified: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/calculator/CalculatorClientTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/calculator/CalculatorClientTestCase.java?view=diff&rev=511484&r1=511483&r2=511484
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/calculator/CalculatorClientTestCase.java
(original)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/calculator/CalculatorClientTestCase.java
Sun Feb 25 04:18:08 2007
@@ -32,11 +32,15 @@
 
     private CompositeContext compositeContext;
     
-    public void testHelloWorldRuby() throws Exception {
-        CalculatorService calculatorService = compositeContext.locateService(CalculatorService.class,
"CalculatorComponent");
-
+    public void testCalculatorRuby() throws Exception {
+        CalculatorService calculatorService = compositeContext.locateService(CalculatorService.class,
"RubyCalculatorComponent");
         Assert.assertEquals(3.0, calculatorService.add(1,2));
+        Assert.assertEquals(1.5, calculatorService.div(3,2));
+    }
 
+    public void testCalculatorPython() throws Exception {
+        CalculatorService calculatorService = compositeContext.locateService(CalculatorService.class,
"PythonCalculatorComponent");
+        Assert.assertEquals(3.0, calculatorService.add(1,2));
         Assert.assertEquals(1.5, calculatorService.div(3,2));
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message