tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r453139 - in /incubator/tuscany/java/sca/services/containers/container.javascript/src: main/java/org/apache/tuscany/container/javascript/ test/java/org/apache/tuscany/container/javascript/ test/java/org/apache/tuscany/container/javascript/f...
Date Thu, 05 Oct 2006 08:28:31 GMT
Author: antelder
Date: Thu Oct  5 01:28:30 2006
New Revision: 453139

URL: http://svn.apache.org/viewvc?view=rev&rev=453139
Log:
Support properties in the JavaScript container

Added:
    incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/propertyTest.componentType
    incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/propertyTest.js
Modified:
    incubator/tuscany/java/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/JavaScriptComponent.java
    incubator/tuscany/java/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/JavaScriptComponentBuilder.java
    incubator/tuscany/java/sca/services/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java
    incubator/tuscany/java/sca/services/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java
    incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/helloworld.scdl

Modified: incubator/tuscany/java/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/JavaScriptComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/JavaScriptComponent.java?view=diff&rev=453139&r1=453138&r2=453139
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/JavaScriptComponent.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/JavaScriptComponent.java
Thu Oct  5 01:28:30 2006
@@ -48,7 +48,7 @@
 
     private RhinoScript rhinoScript;
 
-    public JavaScriptComponent(String name, RhinoScript rhinoScript, List<Class<?>>
services,
+    public JavaScriptComponent(String name, RhinoScript rhinoScript, Map<String, Object>
properties, List<Class<?>> services,
                                CompositeComponent parent, ScopeContainer scopeContainer,
WireService wireService,
                                WorkContext workContext) {
         super(name, parent, scopeContainer, wireService, workContext, null, 0);
@@ -56,7 +56,7 @@
         this.rhinoScript = rhinoScript;
         this.services = services;
         this.scope = scopeContainer.getScope();
-        this.properties = new HashMap<String, Object>();
+        this.properties = properties;
     }
 
     public Object createInstance() throws ObjectCreationException {

Modified: incubator/tuscany/java/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/JavaScriptComponentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/JavaScriptComponentBuilder.java?view=diff&rev=453139&r1=453138&r2=453139
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/JavaScriptComponentBuilder.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/JavaScriptComponentBuilder.java
Thu Oct  5 01:28:30 2006
@@ -20,6 +20,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -33,6 +34,7 @@
 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.PropertyValue;
 import org.apache.tuscany.spi.model.Scope;
 import org.apache.tuscany.spi.model.ServiceDefinition;
 import org.apache.xmlbeans.XmlObject;
@@ -44,10 +46,13 @@
 public class JavaScriptComponentBuilder extends ComponentBuilderExtension<JavaScriptImplementation>
{
 
     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}";
@@ -80,6 +85,13 @@
             enhanceRhinoScript(serviceDefinition, implementation);       
         }
 
+        // get the properties for the component
+        Collection<PropertyValue<?>> propertyValues = componentDefinition.getPropertyValues().values();
+        Map<String, Object> properties = new HashMap<String, Object>();
+        for (PropertyValue propertyValue : propertyValues) {
+            properties.put(propertyValue.getName(), propertyValue.getValueFactory().getInstance());
+        }
+
         RhinoScript rhinoScript = implementation.getRhinoScript();
 
         // TODO: have ComponentBuilderExtension pass ScopeContainer in on build method?
@@ -91,7 +103,7 @@
             scopeContainer = scopeRegistry.getScopeContainer(scope);
         }
 
-        return new JavaScriptComponent(name, rhinoScript, services, parent, scopeContainer,
wireService, workContext);
+        return new JavaScriptComponent(name, rhinoScript, properties, services, parent, scopeContainer,
wireService, workContext);
     }
 
     private void enhanceRhinoScript(ServiceDefinition serviceDefn, JavaScriptImplementation
implementation) throws BuilderConfigException {

Modified: incubator/tuscany/java/sca/services/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java?view=diff&rev=453139&r1=453138&r2=453139
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java
Thu Oct  5 01:28:30 2006
@@ -18,22 +18,24 @@
  */
 package org.apache.tuscany.container.javascript;
 
+import static org.easymock.EasyMock.reportMatcher;
+
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.javascript.mock.Greeting;
+import org.apache.tuscany.container.javascript.rhino.RhinoScript;
+import org.apache.tuscany.core.component.scope.ModuleScopeContainer;
 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 junit.framework.TestCase;
-import org.apache.tuscany.container.javascript.mock.Greeting;
-import org.apache.tuscany.container.javascript.rhino.RhinoScript;
-import org.apache.tuscany.core.component.scope.ModuleScopeContainer;
 import org.apache.tuscany.test.ArtifactFactory;
-import static org.easymock.EasyMock.reportMatcher;
 import org.easymock.IArgumentMatcher;
 
 /**
@@ -118,7 +120,7 @@
         List<Class<?>> services = new ArrayList<Class<?>>();
         services.add(Greeting.class);
         JavaScriptComponent context =
-            new JavaScriptComponent("source", implClass2, services, null, scope,
+            new JavaScriptComponent("source", implClass2, new HashMap<String, Object>(),
services, null, scope,
                 ArtifactFactory.createWireService(), null);
         scope.register(context);
         Operation<Type> operation = new Operation<Type>("greet", null, null,
null, false, null);
@@ -136,7 +138,7 @@
         List<Class<?>> services = new ArrayList<Class<?>>();
         services.add(Greeting.class);
         JavaScriptComponent context =
-            new JavaScriptComponent("source", implClass2, services, null, scope,
+            new JavaScriptComponent("source", implClass2, new HashMap<String, Object>(),
services, null, scope,
                 ArtifactFactory.createWireService(), null);
         scope.register(context);
 

Modified: incubator/tuscany/java/sca/services/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java?view=diff&rev=453139&r1=453138&r2=453139
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java
Thu Oct  5 01:28:30 2006
@@ -18,23 +18,17 @@
  */
 package org.apache.tuscany.container.javascript.function;
 
+import helloworld.HelloWorldService;
+
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.util.Hashtable;
 
 import javax.xml.stream.XMLStreamReader;
 
-import helloworld.HelloWorldService;
-
 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.apache.tuscany.container.javascript.utils.xmlfromxsd.XMLGenerator;
-import org.apache.tuscany.container.javascript.utils.xmlfromxsd.XMLGeneratorFactory;
-import org.apache.tuscany.container.javascript.utils.xmlfromxsd.XMLfromXSDConfiguration;
 import org.apache.tuscany.test.SCATestCase;
-import org.apache.xmlbeans.XmlObject;
 import org.osoa.sca.CompositeContext;
 import org.osoa.sca.CurrentCompositeContext;
 
@@ -43,32 +37,28 @@
  */
 public class HelloWorldTestCase extends SCATestCase {
 
-    private HelloWorldService helloWorldService;
-
-    private HelloWorldService introspectableService;
-    
-    private HelloWorldService e4xHelloWorldService;
+    private CompositeContext context;
 
     protected void setUp() throws Exception {
         addExtension("JavaScriptContainer", getClass().getClassLoader().getResource("META-INF/sca/default.scdl"));
         setApplicationSCDL("org/apache/tuscany/container/javascript/function/helloworld.scdl");
         super.setUp();
 
-        CompositeContext context = CurrentCompositeContext.getContext();
-        helloWorldService = context.locateService(HelloWorldService.class, "HelloWorldComponent");
-        introspectableService = context.locateService(HelloWorldService.class, "IntrospectableHelloWorldComponent");
-        e4xHelloWorldService = context.locateService(HelloWorldService.class, "HelloWorldComponentE4X");
+        context = CurrentCompositeContext.getContext();
     }
 
     public void testHelloWorld() throws Exception {
+        HelloWorldService helloWorldService = context.locateService(HelloWorldService.class,
"HelloWorldComponent");
         assertEquals(helloWorldService.sayHello("petra"), "Hello petra");
     }
 
     public void testIntrospectedHelloWorld() throws Exception {
+        HelloWorldService introspectableService = context.locateService(HelloWorldService.class,
"IntrospectableHelloWorldComponent");
         assertEquals(introspectableService.sayHello("petra"), "Hello petra");
     }
     
     public void testE4XImplInvocation() throws Exception {
+        HelloWorldService e4xHelloWorldService = context.locateService(HelloWorldService.class,
"HelloWorldComponentE4X");
         String xmlInput = "<hel:getGreetings xmlns:hel=\"http://helloworld\"> " +
                             "<hel:name>TuscanyWorld</hel:name> " +
                         "</hel:getGreetings>";
@@ -85,6 +75,8 @@
     
     public void testE4XRefInvocation() throws Exception 
     {
+        HelloWorldService e4xHelloWorldService = context.locateService(HelloWorldService.class,
"HelloWorldComponentE4X");
+
         String initialInput = "JavaClient";
         String jsAddition = " thro e4x reference";
         String endSvcImplResponse = "Hello from Java Implementation to ";
@@ -95,4 +87,15 @@
         assertEquals(endSvcImplResponse + initialInput + jsAddition, response.toString());
         //System.out.println(response);
     }
+
+//    public void testHelloWorldProperty() throws Exception {
+//        HelloWorldService helloWorldService = context.locateService(HelloWorldService.class,
"HelloWorldProperty");
+//        assertEquals(helloWorldService.sayHello("petra"), "Kia ora petra");
+//    }
+//
+    public void testHelloWorldPropertyDefault() throws Exception {
+        HelloWorldService helloWorldService = context.locateService(HelloWorldService.class,
"HelloWorldPropertyDefault");
+        assertEquals(helloWorldService.sayHello("petra"), "Hi petra");
+    }
+
 }

Modified: incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/helloworld.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/helloworld.scdl?view=diff&rev=453139&r1=453138&r2=453139
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/helloworld.scdl
(original)
+++ incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/helloworld.scdl
Thu Oct  5 01:28:30 2006
@@ -39,4 +39,14 @@
         <implementation.java class="helloworld.HelloWorldServiceImpl"/>
     </component>
 
+<!--
+  	<component name="HelloWorldProperty">
+		<js:implementation.js script="org/apache/tuscany/container/javascript/function/propertyTest.js"/>
+        <property name="GREETING">Kia ora</property>
+    </component>
+-->
+
+  	<component name="HelloWorldPropertyDefault">
+		<js:implementation.js script="org/apache/tuscany/container/javascript/function/propertyTest.js"/>
+    </component>
 </composite>

Added: incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/propertyTest.componentType
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/propertyTest.componentType?view=auto&rev=453139
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/propertyTest.componentType
(added)
+++ incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/propertyTest.componentType
Thu Oct  5 01:28:30 2006
@@ -0,0 +1,10 @@
+<?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">Hi</property>
+
+</componentType>

Added: incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/propertyTest.js
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/propertyTest.js?view=auto&rev=453139
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/propertyTest.js
(added)
+++ incubator/tuscany/java/sca/services/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/propertyTest.js
Thu Oct  5 01:28:30 2006
@@ -0,0 +1,3 @@
+function sayHello(s) {
+	return GREETING + ' ' + s;
+}
\ 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


Mime
View raw message