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 2007/05/04 14:24:33 UTC

svn commit: r535202 - in /incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script: ScriptArtifactProcessor.java ScriptImplementation.java

Author: antelder
Date: Fri May  4 05:24:32 2007
New Revision: 535202

URL: http://svn.apache.org/viewvc?view=rev&rev=535202
Log:
Get properties going again with scipt components

Modified:
    incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptArtifactProcessor.java
    incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java

Modified: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptArtifactProcessor.java?view=diff&rev=535202&r1=535201&r2=535202
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptArtifactProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptArtifactProcessor.java Fri May  4 05:24:32 2007
@@ -40,9 +40,6 @@
 import org.apache.tuscany.implementation.spi.PropertyValueObjectFactory;
 import org.apache.tuscany.implementation.spi.ResourceHelper;
 
-// TODO: I hate the way this has to mess about with the .componentType side file, 
-//       the runtime should do that for me
-
 public class ScriptArtifactProcessor implements StAXArtifactProcessor<ScriptImplementation> {
 
     private static final QName IMPLEMENTATION_SCRIPT_QNAME = new QName(Constants.SCA10_NS, "implementation.script");
@@ -55,17 +52,25 @@
         this.propertyFactory = propertyFactory;
     }
 
+    public QName getArtifactType() {
+        return IMPLEMENTATION_SCRIPT_QNAME;
+    }
+
+    public Class<ScriptImplementation> getModelType() {
+        return ScriptImplementation.class;
+    }
+
     public ScriptImplementation read(XMLStreamReader reader) throws ContributionReadException {
 
         try {
 
             String scriptName = reader.getAttributeValue(null, "script");
+
             String scriptLanguage = reader.getAttributeValue(null, "language");
             if (scriptLanguage == null || scriptLanguage.length() < 1) {
                 int i = scriptName.lastIndexOf('.');
                 scriptLanguage = scriptName.substring(i+1);
             }
-            ScriptImplementation scriptImplementation = new ScriptImplementation(scriptName, scriptLanguage);
 
             while (reader.hasNext()) {
                 if (reader.next() == END_ELEMENT && IMPLEMENTATION_SCRIPT_QNAME.equals(reader.getName())) {
@@ -73,34 +78,15 @@
                 }
             }
 
-            String scriptSrc = ResourceHelper.readResource(scriptImplementation.getScriptName());
-            scriptImplementation.setScriptSrc(scriptSrc);
-
-            processComponentType(scriptImplementation);
+            String scriptSrc = ResourceHelper.readResource(scriptName);
 
-            return scriptImplementation;
+            return new ScriptImplementation(scriptName, scriptLanguage, scriptSrc, propertyFactory);
 
         } catch (XMLStreamException e) {
             throw new ContributionReadException(e);
         }
     }
 
-    private void processComponentType(ScriptImplementation scriptImplementation) {
-        // Form the URI of the expected .componentType file;
-
-        String ctName = scriptImplementation.getScriptName();
-        int lastDot = ctName.lastIndexOf('.');
-        ctName = ctName.substring(0, lastDot) + ".componentType";
-        
-        String uri = ctName;
-
-        // Create a ComponentType and mark it unresolved
-        ComponentType componentType = assemblyFactory.createComponentType();
-        componentType.setURI(uri);
-        componentType.setUnresolved(true);
-        scriptImplementation.setComponentType(componentType);
-    }
-
     public void write(ScriptImplementation scriptImplementation, XMLStreamWriter writer) throws ContributionWriteException {
         try {
 
@@ -121,13 +107,18 @@
         }
     }
 
+//  TODO: I hate all the following, why has this to mess about with the .componentType side file, 
+//  the runtime should do that for me
+
     public void resolve(ScriptImplementation scriptImplementation, ArtifactResolver resolver) throws ContributionResolveException {
 
+        processComponentType(scriptImplementation);
+
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         String scriptURI = cl.getResource(scriptImplementation.getScriptName()).toString();
         int lastDot = scriptURI.lastIndexOf('.');
         String ctURI = scriptURI.substring(0, lastDot) + ".componentType";
-        ComponentType ct = scriptImplementation.getComponentType();
+        ComponentType ct = processComponentType(scriptImplementation);
         ct.setURI(ctURI);
         ComponentType componentType = resolver.resolve(ComponentType.class, ct);
         if (componentType.isUnresolved()) {
@@ -142,17 +133,27 @@
         for (Property property : componentType.getProperties()) {
             scriptImplementation.getProperties().add(property);
         }
-        scriptImplementation.setComponentType(componentType);
+//        scriptImplementation.setComponentType(componentType);
         
         scriptImplementation.setUnresolved(false);
     }
 
-    public QName getArtifactType() {
-        return IMPLEMENTATION_SCRIPT_QNAME;
-    }
+    private ComponentType processComponentType(ScriptImplementation scriptImplementation) {
 
-    public Class<ScriptImplementation> getModelType() {
-        return ScriptImplementation.class;
+        // Form the URI of the expected .componentType file;
+
+        String ctName = scriptImplementation.getScriptName();
+        int lastDot = ctName.lastIndexOf('.');
+        ctName = ctName.substring(0, lastDot) + ".componentType";
+        
+        String uri = ctName;
+
+        // Create a ComponentType and mark it unresolved
+        ComponentType componentType = assemblyFactory.createComponentType();
+        componentType.setURI(uri);
+        componentType.setUnresolved(true);
+
+        return componentType;
     }
 
 }

Modified: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java?view=diff&rev=535202&r1=535201&r2=535202
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java Fri May  4 05:24:32 2007
@@ -21,17 +21,20 @@
 import java.io.StringReader;
 
 import javax.script.Invocable;
+import javax.script.ScriptContext;
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
 
 import org.apache.tuscany.assembly.ComponentService;
-import org.apache.tuscany.assembly.ComponentType;
+import org.apache.tuscany.assembly.Property;
 import org.apache.tuscany.core.RuntimeComponent;
 import org.apache.tuscany.implementation.spi.AbstractImplementation;
+import org.apache.tuscany.implementation.spi.PropertyValueObjectFactory;
 import org.apache.tuscany.interfacedef.Operation;
 import org.apache.tuscany.sca.implementation.script.engines.TuscanyJRubyScriptEngine;
 import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
 import org.apache.tuscany.spi.wire.Interceptor;
 
 /**
@@ -39,16 +42,20 @@
  */
 public class ScriptImplementation extends AbstractImplementation {
 
-    private String scriptName;
-    private String scriptSrc;
-    private String scriptLanguage;
-    private ComponentType componentType;
-    
+    protected String scriptName;
+    protected String scriptSrc;
+    protected String scriptLanguage;
+
+    protected PropertyValueObjectFactory propertyFactory;
+
     protected ScriptEngine scriptEngine;
 
-    protected ScriptImplementation(String scriptName, String scriptLanguage) {
+    public ScriptImplementation(String scriptName, String scriptLanguage, String scriptSrc, PropertyValueObjectFactory propertyFactory) {
         this.scriptName = scriptName;
         this.scriptLanguage = scriptLanguage;
+        this.scriptSrc = scriptSrc;
+        this.propertyFactory = propertyFactory;
+        
         setURI(scriptName);
         setUnresolved(true);
     }
@@ -69,14 +76,6 @@
         this.scriptSrc = scriptSrc;
     }
 
-    public ComponentType getComponentType() {
-        return componentType;
-    }
-
-    public void setComponentType(ComponentType componentType) {
-        this.componentType = componentType;
-    }
-
     public Interceptor createInterceptor(RuntimeComponent component, ComponentService service, Operation operation, boolean isCallback) {
         return new ScriptInvoker(this, operation.getName());
     }
@@ -91,7 +90,6 @@
                 throw new ObjectCreationException("script engine does not support Invocable: " + scriptEngine);
             }
             
-//            ObjectFactory<?> propertyValueFactory = null;
 //            for (Reference reference : getReferences()) {
 //                engine.getContext().setAttribute(reference.getName(), 
 //                                                 reference., 
@@ -106,15 +104,15 @@
 //                                                 ScriptContext.ENGINE_SCOPE);
 //            }
 //            
-//            for (String propertyName : propertyValueFactories.keySet()) {
-//                propertyValueFactory = propertyValueFactories.get(propertyName);
-//                if ( propertyValueFactory != null) {
-//                    //manager.put(propertyName, propertyValueFactory.getInstance());
-//                    engine.getContext().setAttribute(propertyName, 
-//                                                     propertyValueFactory.getInstance(), 
-//                                                     ScriptContext.ENGINE_SCOPE);
-//                }
-//            }
+
+            for (Property property : getProperties()) {
+                ObjectFactory<?> propertyValueFactory = propertyFactory.createValueFactory(property);
+                if ( propertyValueFactory != null) {
+                    scriptEngine.getContext().setAttribute(property.getName(), 
+                                                     propertyValueFactory.getInstance(), 
+                                                     ScriptContext.ENGINE_SCOPE);
+                }
+            }
             
             scriptEngine.eval(new StringReader(getScriptSrc()));
 



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