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/05 09:34:27 UTC

svn commit: r535470 - in /incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany: implementation/spi/ sca/implementation/script/

Author: antelder
Date: Sat May  5 00:34:26 2007
New Revision: 535470

URL: http://svn.apache.org/viewvc?view=rev&rev=535470
Log:
Script impl tidy up

Added:
    incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractStAXArtifactProcessor.java   (with props)
Modified:
    incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractImplementation.java
    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/ScriptInvoker.java

Modified: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractImplementation.java?view=diff&rev=535470&r1=535469&r2=535470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractImplementation.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractImplementation.java Sat May  5 00:34:26 2007
@@ -52,10 +52,13 @@
     private List<Property> properties = new ArrayList<Property>();
     private ConstrainingType constrainingType;
     private String uri;
-    private boolean unresolved;
+    private boolean unresolved = true;
     private List<Intent> intents;
     private List<PolicySet> policySets;
-    
+
+    public AbstractImplementation() {
+    }
+
     public List<Property> getProperties() {
         return properties;
     }

Added: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractStAXArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractStAXArtifactProcessor.java?view=auto&rev=535470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractStAXArtifactProcessor.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractStAXArtifactProcessor.java Sat May  5 00:34:26 2007
@@ -0,0 +1,78 @@
+/*
+ * 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.implementation.spi;
+
+import org.apache.tuscany.assembly.AssemblyFactory;
+import org.apache.tuscany.assembly.ComponentType;
+import org.apache.tuscany.assembly.Implementation;
+import org.apache.tuscany.assembly.Property;
+import org.apache.tuscany.assembly.Reference;
+import org.apache.tuscany.assembly.Service;
+import org.apache.tuscany.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.contribution.resolver.ArtifactResolver;
+import org.apache.tuscany.contribution.service.ContributionResolveException;
+
+/**
+ * TODO: couldn't something like this class be provided by the runtime?
+ * Each impl shouldn't have to have their own .componentType merging code
+ */
+public abstract class AbstractStAXArtifactProcessor<I extends Implementation> implements StAXArtifactProcessor<I> {
+
+    private AssemblyFactory assemblyFactory;
+
+    public AbstractStAXArtifactProcessor(AssemblyFactory assemblyFactory) {
+        this.assemblyFactory = assemblyFactory;
+    }
+
+    public void resolve(I model, ArtifactResolver resolver) throws ContributionResolveException {
+      addSideFileComponentType(model.getURI(), model, resolver);
+      model.setUnresolved(false);
+    }
+
+    protected void addSideFileComponentType(String name, Implementation impl, ArtifactResolver resolver) {
+        int lastDot = name.lastIndexOf('.');
+        if (lastDot < 0) {
+            return;
+        }
+        String sideFileName = name.substring(0, lastDot) + ".componentType";
+
+        ComponentType componentType = assemblyFactory.createComponentType();
+        componentType.setURI(sideFileName);
+        componentType.setUnresolved(true);
+
+        componentType = resolver.resolve(ComponentType.class, componentType);
+
+        if (!componentType.isUnresolved()) {
+            for (Reference reference : componentType.getReferences()) {
+                impl.getReferences().add(reference);
+            }
+            for (Service service : componentType.getServices()) {
+                impl.getServices().add(service);
+            }
+            for (Property property : componentType.getProperties()) {
+                impl.getProperties().add(property);
+            }
+            if (componentType.getConstrainingType() != null) {
+                impl.setConstrainingType(componentType.getConstrainingType());
+            }
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractStAXArtifactProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/spi/AbstractStAXArtifactProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

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=535470&r1=535469&r2=535470
==============================================================================
--- 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 Sat May  5 00:34:26 2007
@@ -27,27 +27,26 @@
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.tuscany.assembly.AssemblyFactory;
-import org.apache.tuscany.assembly.ComponentType;
-import org.apache.tuscany.assembly.Property;
-import org.apache.tuscany.assembly.Reference;
-import org.apache.tuscany.assembly.Service;
 import org.apache.tuscany.assembly.xml.Constants;
-import org.apache.tuscany.contribution.processor.StAXArtifactProcessor;
-import org.apache.tuscany.contribution.resolver.ArtifactResolver;
 import org.apache.tuscany.contribution.service.ContributionReadException;
-import org.apache.tuscany.contribution.service.ContributionResolveException;
+import org.apache.tuscany.implementation.spi.AbstractStAXArtifactProcessor;
 import org.apache.tuscany.implementation.spi.PropertyValueObjectFactory;
 import org.apache.tuscany.implementation.spi.ResourceHelper;
 
-public class ScriptArtifactProcessor implements StAXArtifactProcessor<ScriptImplementation> {
+/**
+ * ArtifactProcessor to read the SCDL XML for script implementations
+ * 
+ * <code><implementation.script script="pathToScriptFile" [language="scriptLanguage"] /></code>
+ */
+public class ScriptArtifactProcessor extends AbstractStAXArtifactProcessor<ScriptImplementation> {
 
     private static final QName IMPLEMENTATION_SCRIPT_QNAME = new QName(Constants.SCA10_NS, "implementation.script");
-    
-    private AssemblyFactory assemblyFactory;
+
+    // TODO: runtime needs to provide a better way to get the PropertyValueObjectFactory
     private PropertyValueObjectFactory propertyFactory;
 
     public ScriptArtifactProcessor(AssemblyFactory assemblyFactory, PropertyValueObjectFactory propertyFactory) {
-        this.assemblyFactory = assemblyFactory;
+        super(assemblyFactory);
         this.propertyFactory = propertyFactory;
     }
 
@@ -75,8 +74,13 @@
         }
 
         String scriptSrc = ResourceHelper.readResource(scriptName);
+        ScriptImplementation scriptImpl = new ScriptImplementation(scriptName, scriptLanguage, scriptSrc, propertyFactory);
+
+        // TODO: How to get the script URI? Should use the contrabution service
+        //   the uri is used in the resolve method (perhaps incorrectly?) to get the .componentType sidefile
+        scriptImpl.setURI(Thread.currentThread().getContextClassLoader().getResource(scriptName).toString());
 
-        return new ScriptImplementation(scriptName, scriptLanguage, scriptSrc, propertyFactory);
+        return scriptImpl;
     }
 
     public void write(ScriptImplementation scriptImplementation, XMLStreamWriter writer) throws XMLStreamException {
@@ -93,54 +97,4 @@
 
         writer.writeEndElement();
     }
-
-//  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 = processComponentType(scriptImplementation);
-        ct.setURI(ctURI);
-        ComponentType componentType = resolver.resolve(ComponentType.class, ct);
-        if (componentType.isUnresolved()) {
-            throw new ContributionResolveException("missing .componentType side file");
-        }
-        for (Reference reference : componentType.getReferences()) {
-            scriptImplementation.getReferences().add(reference);
-        }
-        for (Service service : componentType.getServices()) {
-            scriptImplementation.getServices().add(service);
-        }
-        for (Property property : componentType.getProperties()) {
-            scriptImplementation.getProperties().add(property);
-        }
-//        scriptImplementation.setComponentType(componentType);
-        
-        scriptImplementation.setUnresolved(false);
-    }
-
-    private ComponentType 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);
-
-        return componentType;
-    }
-
 }

Modified: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java?view=diff&rev=535470&r1=535469&r2=535470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java Sat May  5 00:34:26 2007
@@ -35,7 +35,7 @@
     protected String operationName;
 
     /**
-     * TODO: pasing in the impl is a hack to get at scriptEngine as thats all this uses
+     * TODO: pasing in the impl is a bit of a hack to get at scriptEngine as thats all this uses
      * but its not created till the start method which is called after the invokers are created 
      */
     public ScriptInvoker(ScriptImplementation impl, String operationName) {



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