tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r532715 - in /incubator/tuscany/sandbox/SPI: implementation-crud/src/main/java/crud/ implementation-script/ implementation-script/src/main/java/org/apache/tuscany/implementation/script/ implementation-script/src/main/resources/META-INF/serv...
Date Thu, 26 Apr 2007 11:48:04 GMT
Author: antelder
Date: Thu Apr 26 04:48:02 2007
New Revision: 532715

URL: http://svn.apache.org/viewvc?view=rev&rev=532715
Log:
Implementation SPI strawman updates, update spi for properties and references, add an implementation-script using SPI, and get working for varrious scritp languages with helloworld, properties and references

Added:
    incubator/tuscany/sandbox/SPI/implementation-script/
      - copied from r531931, incubator/tuscany/java/sca/modules/implementation-script/
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationActivator.java   (with props)
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvokerFactory.java   (with props)
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptXMLSCDLProcessor.java   (with props)
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/resources/META-INF/services/org.apache.tuscany.spi.implementation.ImplementationActivator
    incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/PropertyValueObjectFactory.java   (with props)
Removed:
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/InstanceWrapperBase.java
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptArtifactProcessor.java
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptComponent.java
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptComponentBuilder.java
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptModuleActivator.java
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptPropertyValueObjectFactory.java
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/resources/META-INF/services/org.apache.tuscany.core.ModuleActivator
    incubator/tuscany/sandbox/SPI/implementation-script/src/test/java/org/apache/tuscany/implementation/script/ScriptImplementationLoaderTestCase.java
    incubator/tuscany/sandbox/SPI/implementation-script/src/test/java/org/apache/tuscany/implementation/script/ScriptInvokerTestCase.java
Modified:
    incubator/tuscany/sandbox/SPI/implementation-crud/src/main/java/crud/CRUDInvoker.java
    incubator/tuscany/sandbox/SPI/implementation-crud/src/main/java/crud/CRUDInvokerFactory.java
    incubator/tuscany/sandbox/SPI/implementation-script/pom.xml
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java
    incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvoker.java
    incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplAtomicComponent.java
    incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplTargetInvoker.java
    incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationArtifactProcessor.java
    incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationBuilder.java
    incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationSPIModuleActivator.java
    incubator/tuscany/sandbox/SPI/implementation-spi/src/main/java/org/apache/tuscany/spi/implementation/Invoker.java
    incubator/tuscany/sandbox/SPI/implementation-spi/src/main/java/org/apache/tuscany/spi/implementation/InvokerFactory.java

Modified: incubator/tuscany/sandbox/SPI/implementation-crud/src/main/java/crud/CRUDInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-crud/src/main/java/crud/CRUDInvoker.java?view=diff&rev=532715&r1=532714&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-crud/src/main/java/crud/CRUDInvoker.java (original)
+++ incubator/tuscany/sandbox/SPI/implementation-crud/src/main/java/crud/CRUDInvoker.java Thu Apr 26 04:48:02 2007
@@ -32,7 +32,7 @@
         this.operation = operation;
     }
 
-    public Object invoke(Object[] args) {
+    public Object invoke(Object arg0, Object[] args) {
         if (operation.getName().equals("create")) {
             return resourceManager.createResource(args[0]);
             

Modified: incubator/tuscany/sandbox/SPI/implementation-crud/src/main/java/crud/CRUDInvokerFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-crud/src/main/java/crud/CRUDInvokerFactory.java?view=diff&rev=532715&r1=532714&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-crud/src/main/java/crud/CRUDInvokerFactory.java (original)
+++ incubator/tuscany/sandbox/SPI/implementation-crud/src/main/java/crud/CRUDInvokerFactory.java Thu Apr 26 04:48:02 2007
@@ -19,6 +19,8 @@
 
 package crud;
 
+import java.util.Map;
+
 import org.apache.tuscany.interfacedef.Operation;
 import org.apache.tuscany.spi.implementation.InvokerFactory;
 
@@ -34,7 +36,7 @@
         return new CRUDInvoker(resourceManager, operation);
     }
 
-    public Object getInstance() {
+    public Object getInstance(Map<String, Object> arg0, Map<String, Object> arg1) {
         return resourceManager;
     }
 

Modified: incubator/tuscany/sandbox/SPI/implementation-script/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-script/pom.xml?view=diff&rev=532715&r1=531931&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-script/pom.xml (original)
+++ incubator/tuscany/sandbox/SPI/implementation-script/pom.xml Thu Apr 26 04:48:02 2007
@@ -27,43 +27,14 @@
         <relativePath>../pom.xml</relativePath>
     </parent>
 
-    <artifactId>tuscany-implementation-script</artifactId>
+    <artifactId>tuscany-implementation-script2</artifactId>
     <name>Apache Tuscany Implementation Script</name>
 
     <dependencies>
+
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-assembly</artifactId>
-            <version>1.0-incubating-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-core</artifactId>
-            <version>1.0-incubating-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-interface</artifactId>
-            <version>1.0-incubating-SNAPSHOT</version>
-        </dependency>        
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-assembly-xml</artifactId>
-            <version>1.0-incubating-SNAPSHOT</version>
-        </dependency>        
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-contribution-impl</artifactId>
-            <version>1.0-incubating-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.osoa</groupId>
-            <artifactId>sca-api</artifactId>
-            <version>1.0-incubating-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-assembly-xml</artifactId>
+            <artifactId>tuscany-implementation-spi</artifactId>
             <version>1.0-incubating-SNAPSHOT</version>
         </dependency>
 

Modified: incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java?view=diff&rev=532715&r1=531931&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java (original)
+++ incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java Thu Apr 26 04:48:02 2007
@@ -18,12 +18,7 @@
  */
 package org.apache.tuscany.implementation.script;
 
-import java.util.List;
-
-import org.apache.tuscany.assembly.ComponentType;
 import org.apache.tuscany.assembly.Implementation;
-import org.apache.tuscany.assembly.Reference;
-import org.apache.tuscany.assembly.Service;
 import org.apache.tuscany.assembly.impl.ComponentTypeImpl;
 
 /**
@@ -34,11 +29,8 @@
     private String scriptName;
     private String scriptSrc;
     private String scriptLanguage;
-    private ComponentType componentType;
 
-    public ScriptImplementation(String scriptName, String scriptLanguage) {
-        this.scriptName = scriptName;
-        this.scriptLanguage = scriptLanguage;
+    public ScriptImplementation() {
         setUnresolved(true);
     }
 
@@ -58,19 +50,12 @@
         this.scriptSrc = scriptSrc;
     }
 
-    public ComponentType getComponentType() {
-        return componentType;
-    }
-
-    public void setComponentType(ComponentType componentType) {
-        this.componentType = componentType;
-    }
-
-    public List<Service> getServices() {
-        return componentType.getServices();
+    public void setScriptLanguage(String scriptLanguage) {
+        this.scriptLanguage = scriptLanguage;
     }
 
-    public List<Reference> getReferences() {
-        return componentType.getReferences();
+    public void setScriptName(String scriptName) {
+        this.scriptName = scriptName;
+        setURI(scriptName); // TODO: hack to enable getting componentType name
     }
 }

Added: incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationActivator.java?view=auto&rev=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationActivator.java (added)
+++ incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationActivator.java Thu Apr 26 04:48:02 2007
@@ -0,0 +1,49 @@
+/*
+ * 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.script;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.assembly.xml.Constants;
+import org.apache.tuscany.spi.implementation.ImplementationActivator;
+import org.apache.tuscany.spi.implementation.InvokerFactory;
+import org.apache.tuscany.spi.implementation.XMLSCDLProcessor;
+
+public class ScriptImplementationActivator implements ImplementationActivator<ScriptImplementation>{
+
+    private static final QName IMPLEMENTATION_SCRIPT_QNAME = new QName(Constants.SCA10_NS, "implementation.script");
+
+    public Class getImplementationClass() {
+        return ScriptImplementation.class;
+    }
+
+    public InvokerFactory getInvokerFactory(ScriptImplementation impl) {
+        return new ScriptInvokerFactory(impl);
+    }
+
+    public QName getModelQName() {
+        return IMPLEMENTATION_SCRIPT_QNAME;
+    }
+
+    public XMLSCDLProcessor getSCDLProcessor() {
+        return new ScriptXMLSCDLProcessor();
+    }
+
+}

Propchange: incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationActivator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvoker.java?view=diff&rev=532715&r1=531931&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvoker.java (original)
+++ incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvoker.java Thu Apr 26 04:48:02 2007
@@ -19,114 +19,30 @@
 
 package org.apache.tuscany.implementation.script;
 
-import java.lang.reflect.InvocationTargetException;
-
 import javax.script.Invocable;
 import javax.script.ScriptException;
 
-import org.apache.tuscany.spi.Scope;
-import org.apache.tuscany.spi.component.ComponentException;
-import org.apache.tuscany.spi.component.InstanceWrapper;
-import org.apache.tuscany.spi.component.InvalidConversationSequenceException;
-import org.apache.tuscany.spi.component.ScopeContainer;
-import org.apache.tuscany.spi.component.TargetException;
-import org.apache.tuscany.spi.component.WorkContext;
-import org.apache.tuscany.spi.extension.TargetInvokerExtension;
-
-/**
- * Perform the actual script invocation
- * TODO: move vertually all of this to SPI TargetInvokerExtension
- */
-@SuppressWarnings("deprecation")
-public class ScriptInvoker<T> extends TargetInvokerExtension {
-
-    protected Object clazz;
-    protected String operationName;
-
-    private final ScriptComponent component;
-    private final ScopeContainer scopeContainer;
-    protected InstanceWrapper<T> target;
-    protected boolean stateless;
-
-    public ScriptInvoker(String operationName,
-                         ScriptComponent component,
-                         ScopeContainer scopeContainer,
-                         WorkContext workContext) {
-
-        this.operationName = operationName;
-        this.component = component;
-        this.scopeContainer = scopeContainer;
-        stateless = Scope.STATELESS == scopeContainer.getScope();
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.spi.implementation.Invoker;
+
+public class ScriptInvoker implements Invoker {
+
+    private String operationName;
 
-        // TODO: support script classes
+    public ScriptInvoker(ScriptImplementation impl, Operation operation) {
+        this.operationName = operation.getName();
     }
 
-    @SuppressWarnings("unchecked")
-    public Object invokeTarget(Object payload, short sequence, WorkContext workContext) throws InvocationTargetException {
-        Object contextId = workContext.getIdentifier(scopeContainer.getScope());
+    public Object invoke(Object instance, Object[] args) {
         try {
 
-            InstanceWrapper<T> wrapper = getInstance(sequence, contextId);
-            Invocable scriptEngine = (Invocable)wrapper.getInstance();
+            Invocable scriptEngine = (Invocable)instance;
 
-            Object ret;
-            if (clazz == null) {
-                ret = scriptEngine.invokeFunction(operationName, (Object[])payload);
-            } else {
-                ret =  scriptEngine.invokeMethod(clazz, operationName, (Object[])payload);
-            }
-
-            scopeContainer.returnWrapper(component, wrapper, contextId);
-            if (sequence == END) {
-                // if end conversation, remove resource
-                scopeContainer.remove(component);
-            }
-
-            return ret;
+            return scriptEngine.invokeFunction(operationName, args);
 
         } catch (ScriptException e) {
-            throw new InvocationTargetException(e);
-        } catch (ComponentException e) {
-            throw new InvocationTargetException(e);
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public ScriptInvoker clone() throws CloneNotSupportedException {
-        try {
-            ScriptInvoker invoker = (ScriptInvoker)super.clone();
-            invoker.target = null;
-            return invoker;
-        } catch (CloneNotSupportedException e) {
-            return null; // will not happen
+            throw new RuntimeException(e);
         }
     }
 
-    /**
-     * Resolves the target service instance or returns a cached one
-     */
-    @SuppressWarnings("unchecked")
-    protected InstanceWrapper<T> getInstance(short sequence, Object contextId) throws TargetException {
-        switch (sequence) {
-        case NONE:
-            if (cacheable) {
-                if (target == null) {
-                    target = scopeContainer.getWrapper(component, contextId);
-                }
-                return target;
-            } else {
-                return scopeContainer.getWrapper(component, contextId);
-            }
-        case START:
-            assert !cacheable;
-            return scopeContainer.getWrapper(component, contextId);
-        case CONTINUE:
-        case END:
-            assert !cacheable;
-            return scopeContainer.getAssociatedWrapper(component, contextId);
-        default:
-            throw new InvalidConversationSequenceException("Unknown sequence type", String.valueOf(sequence));
-        }
-    }
 }

Added: incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvokerFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvokerFactory.java?view=auto&rev=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvokerFactory.java (added)
+++ incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvokerFactory.java Thu Apr 26 04:48:02 2007
@@ -0,0 +1,74 @@
+/*
+ * 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.script;
+
+import java.io.StringReader;
+import java.util.Map;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.implementation.Invoker;
+import org.apache.tuscany.spi.implementation.InvokerFactory;
+
+public class ScriptInvokerFactory implements InvokerFactory {
+    
+    private ScriptImplementation impl;
+
+    public ScriptInvokerFactory(ScriptImplementation impl) {
+        this.impl = impl;
+    }
+
+    public Invoker createInvoker(Operation operation) {
+        return new ScriptInvoker(impl, operation);
+    }
+
+    public Object getInstance(Map<String, Object> references, Map<String, Object> properties) {
+        try {
+            ScriptEngineManager manager = new ScriptEngineManager();
+            
+            for (String referenceName : references.keySet()) {
+                Object reference = references.get(referenceName);
+                manager.put(referenceName, reference);
+            }
+            
+            for (String propertyName : properties.keySet()) {
+                Object propertyValue = properties.get(propertyName);
+                manager.put(propertyName, propertyValue);
+            }
+            
+            ScriptEngine engine = manager.getEngineByExtension(impl.getScriptLanguage());
+            if (engine == null) {
+                throw new ObjectCreationException("no script engine found for language: " + impl.getScriptLanguage());
+            }
+           
+            engine.eval(new StringReader(impl.getScriptSrc()));
+           
+            return engine;
+           
+        } catch (ScriptException e) {
+            throw new ObjectCreationException(e);
+        }
+    }
+
+}

Propchange: incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvokerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptInvokerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptXMLSCDLProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptXMLSCDLProcessor.java?view=auto&rev=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptXMLSCDLProcessor.java (added)
+++ incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptXMLSCDLProcessor.java Thu Apr 26 04:48:02 2007
@@ -0,0 +1,94 @@
+/*
+ * 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.script;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.assembly.Implementation;
+import org.apache.tuscany.spi.implementation.XMLSCDLProcessor;
+
+public class ScriptXMLSCDLProcessor implements XMLSCDLProcessor {
+
+    private static final String SCRIPT = "script";
+    private static final String LANGUAGE = "language";
+
+    public void read(Implementation impl, XMLStreamReader reader) {
+        ScriptImplementation scriptImplementation = (ScriptImplementation)impl;
+
+        String scriptName = reader.getAttributeValue(null, SCRIPT);
+        scriptImplementation.setScriptName(scriptName);
+
+        String scriptLanguage = reader.getAttributeValue(null, LANGUAGE);
+        if (scriptLanguage == null || scriptLanguage.length() < 1) {
+            int i = scriptName.lastIndexOf('.');
+            scriptLanguage = scriptName.substring(i+1);
+        }
+        scriptImplementation.setScriptLanguage(scriptLanguage);
+
+        scriptImplementation.setScriptSrc(readScript(scriptImplementation.getScriptName()));
+    }
+
+    public void write(Implementation impl, XMLStreamWriter writer) {
+    }
+
+    protected String readScript(String scriptName) {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        URL scriptSrcUrl = cl.getResource(scriptName);
+        if (scriptSrcUrl == null) {
+            throw new RuntimeException("No script: " + scriptName);
+        }
+
+        InputStream is;
+        try {
+            is = scriptSrcUrl.openStream();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+        try {
+
+            Reader reader = new InputStreamReader(is, "UTF-8");
+            char[] buffer = new char[1024];
+            StringBuilder source = new StringBuilder();
+            int count;
+            while ((count = reader.read(buffer)) > 0) {
+                source.append(buffer, 0, count);
+            }
+
+            return source.toString();
+
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } finally {
+            try {
+                is.close();
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+    }
+}

Propchange: incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptXMLSCDLProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/SPI/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptXMLSCDLProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/sandbox/SPI/implementation-script/src/main/resources/META-INF/services/org.apache.tuscany.spi.implementation.ImplementationActivator
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-script/src/main/resources/META-INF/services/org.apache.tuscany.spi.implementation.ImplementationActivator?view=auto&rev=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-script/src/main/resources/META-INF/services/org.apache.tuscany.spi.implementation.ImplementationActivator (added)
+++ incubator/tuscany/sandbox/SPI/implementation-script/src/main/resources/META-INF/services/org.apache.tuscany.spi.implementation.ImplementationActivator Thu Apr 26 04:48:02 2007
@@ -0,0 +1,3 @@
+# Implementation class for the Script ImplementationActivator
+org.apache.tuscany.implementation.script.ScriptImplementationActivator
+

Modified: incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplAtomicComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplAtomicComponent.java?view=diff&rev=532715&r1=532714&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplAtomicComponent.java (original)
+++ incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplAtomicComponent.java Thu Apr 26 04:48:02 2007
@@ -20,18 +20,24 @@
 package org.apache.tuscany.spi.implementation.impl;
 
 import java.net.URI;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.tuscany.assembly.ComponentProperty;
 import org.apache.tuscany.assembly.Implementation;
 import org.apache.tuscany.core.component.ComponentContextImpl;
 import org.apache.tuscany.core.component.ComponentContextProvider;
 import org.apache.tuscany.core.component.ServiceReferenceImpl;
 import org.apache.tuscany.core.component.scope.InstanceWrapperBase;
+import org.apache.tuscany.databinding.DataBindingExtensionPoint;
 import org.apache.tuscany.interfacedef.Operation;
 import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
 import org.apache.tuscany.spi.SingletonObjectFactory;
 import org.apache.tuscany.spi.component.InstanceWrapper;
 import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
 import org.apache.tuscany.spi.extension.AtomicComponentExtension;
 import org.apache.tuscany.spi.implementation.ImplementationActivator;
 import org.apache.tuscany.spi.implementation.Invoker;
@@ -47,15 +53,30 @@
     private ImplementationActivator ia;
     private Implementation impl;
 
+    private Map<String, Object> references;
+    private Map<String, ObjectFactory<?>> propertyValueFactories;
+    
+    private PropertyValueObjectFactory propertyValueObjectFactory = null;
+    private DataBindingExtensionPoint dataBindingRegistry;
+
     public ImplAtomicComponent(URI uri, URI groupId, ImplementationActivator ia, Implementation impl) {
         super(uri, null, null, groupId, 50);
         this.ia = ia;
         this.componentContext = new ComponentContextImpl(this);
         this.impl = impl;
+        references = new HashMap<String, Object>();
+        propertyValueFactories = new HashMap<String, ObjectFactory<?>>();
     }
 
     public Object createInstance() throws ObjectCreationException {
-        return ia.getInvokerFactory(impl).getInstance();
+        Map<String, Object> properties = new HashMap<String, Object>();
+        for (String propertyName : propertyValueFactories.keySet()) {
+            ObjectFactory<?> propertyValueFactory = propertyValueFactories.get(propertyName);
+            if ( propertyValueFactory != null) {
+                properties.put(propertyName, propertyValueFactory.getInstance());
+            }
+        }
+        return ia.getInvokerFactory(impl).getInstance(references, properties);
     }
 
     public InstanceWrapper createInstanceWrapper() throws ObjectCreationException {
@@ -65,7 +86,19 @@
     public void attachCallbackWire(Wire arg0) {
     }
 
-    public void attachWire(Wire arg0) {
+    public void attachWire(Wire wire) {
+        references.put(wire.getSourceUri().getFragment(), createWireProxy(wire));
+    }
+
+    protected Object createWireProxy(Wire wire) {
+        // TODO: this is completly wrong :) Need to create a proxy wraping the wire
+        Object ref;
+        try {
+            ref = wire.getTargetInstance();
+        } catch (TargetResolutionException e) {
+            throw new RuntimeException(e);
+        }
+        return ref;
     }
 
     public void attachWires(List<Wire> arg0) {
@@ -78,7 +111,7 @@
     public TargetInvoker createTargetInvoker(String targetName, final Operation operation, boolean callback)
         throws TargetInvokerCreationException {
         Invoker invoker = ia.getInvokerFactory(impl).createInvoker(operation);
-        return new ImplTargetInvoker(invoker);
+        return new ImplTargetInvoker(invoker, this, scopeContainer, workContext);
     }
 
     @Override
@@ -100,5 +133,23 @@
 
     public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
         return new ServiceReferenceImpl<B>(businessInterface, new SingletonObjectFactory<B>((B)createInstance()));
+    }
+    public void setDataBindingRegistry(DataBindingExtensionPoint dataBindingRegistry) {
+        this.dataBindingRegistry = dataBindingRegistry;
+    }
+
+    public void setPropertyValueObjectFactory(PropertyValueObjectFactory propertyValueObjectFactory) {
+        this.propertyValueObjectFactory = propertyValueObjectFactory;
+    }
+    
+    public void initializePropertyValueFactories(List<ComponentProperty> properties) {
+        ObjectFactory<?> propertyObjectFactory = null;
+        
+        for (ComponentProperty aProperty : properties) {
+            if (aProperty.getValue() != null) {
+                propertyObjectFactory = propertyValueObjectFactory.createValueFactory(aProperty);
+                propertyValueFactories.put(aProperty.getName(), propertyObjectFactory);
+            }
+        }
     }
 }

Modified: incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplTargetInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplTargetInvoker.java?view=diff&rev=532715&r1=532714&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplTargetInvoker.java (original)
+++ incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplTargetInvoker.java Thu Apr 26 04:48:02 2007
@@ -21,19 +21,103 @@
 
 import java.lang.reflect.InvocationTargetException;
 
+import org.apache.tuscany.spi.Scope;
+import org.apache.tuscany.spi.component.ComponentException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.InvalidConversationSequenceException;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
 import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.extension.TargetInvokerExtension;
 import org.apache.tuscany.spi.implementation.Invoker;
 
-public class ImplTargetInvoker extends TargetInvokerExtension {
+/**
+ * Perform the actual script invocation
+ * TODO: move vertually all of this to SPI TargetInvokerExtension
+ */
+@SuppressWarnings("deprecation")
+public class ImplTargetInvoker<T> extends TargetInvokerExtension {
+
+    protected Object clazz;
+    protected Invoker invoker;
+
+    private final ImplAtomicComponent component;
+    private final ScopeContainer scopeContainer;
+    protected InstanceWrapper<T> target;
+    protected boolean stateless;
+
+    public ImplTargetInvoker(Invoker invoker,
+                         ImplAtomicComponent component,
+                         ScopeContainer scopeContainer,
+                         WorkContext workContext) {
 
-    private Invoker invoker;
-    public ImplTargetInvoker(Invoker invoker) {
         this.invoker = invoker;
+        this.component = component;
+        this.scopeContainer = scopeContainer;
+        stateless = Scope.STATELESS == scopeContainer.getScope();
+
+        // TODO: support script classes
     }
 
+    @SuppressWarnings("unchecked")
     public Object invokeTarget(Object payload, short sequence, WorkContext workContext) throws InvocationTargetException {
-        return invoker.invoke((Object[])payload);
+        Object contextId = workContext.getIdentifier(scopeContainer.getScope());
+        try {
+
+            InstanceWrapper<T> wrapper = getInstance(sequence, contextId);
+            Object instance = wrapper.getInstance();
+
+            Object ret = invoker.invoke(instance, (Object[])payload);
+
+            scopeContainer.returnWrapper(component, wrapper, contextId);
+            if (sequence == END) {
+                // if end conversation, remove resource
+                scopeContainer.remove(component);
+            }
+
+            return ret;
+
+        } catch (ComponentException e) {
+            throw new InvocationTargetException(e);
+        }
     }
 
+    @SuppressWarnings("unchecked")
+    @Override
+    public ImplTargetInvoker clone() throws CloneNotSupportedException {
+        try {
+            ImplTargetInvoker invoker = (ImplTargetInvoker)super.clone();
+            invoker.target = null;
+            return invoker;
+        } catch (CloneNotSupportedException e) {
+            return null; // will not happen
+        }
+    }
+
+    /**
+     * Resolves the target service instance or returns a cached one
+     */
+    @SuppressWarnings("unchecked")
+    protected InstanceWrapper<T> getInstance(short sequence, Object contextId) throws TargetException {
+        switch (sequence) {
+        case NONE:
+            if (cacheable) {
+                if (target == null) {
+                    target = scopeContainer.getWrapper(component, contextId);
+                }
+                return target;
+            } else {
+                return scopeContainer.getWrapper(component, contextId);
+            }
+        case START:
+            assert !cacheable;
+            return scopeContainer.getWrapper(component, contextId);
+        case CONTINUE:
+        case END:
+            assert !cacheable;
+            return scopeContainer.getAssociatedWrapper(component, contextId);
+        default:
+            throw new InvalidConversationSequenceException("Unknown sequence type", String.valueOf(sequence));
+        }
+    }
 }

Modified: incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationArtifactProcessor.java?view=diff&rev=532715&r1=532714&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationArtifactProcessor.java (original)
+++ incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationArtifactProcessor.java Thu Apr 26 04:48:02 2007
@@ -26,7 +26,12 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+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.assembly.impl.DefaultAssemblyFactory;
 import org.apache.tuscany.contribution.processor.StAXArtifactProcessorExtension;
 import org.apache.tuscany.contribution.resolver.ArtifactResolver;
 import org.apache.tuscany.contribution.service.ContributionReadException;
@@ -79,7 +84,28 @@
         return ia.getImplementationClass();
     }
 
-    public void resolve(Object arg0, ArtifactResolver arg1) throws ContributionResolveException {
+    public void resolve(Object arg0, ArtifactResolver resolver) throws ContributionResolveException {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        Implementation impl = (Implementation)arg0;
+        String scriptURI = cl.getResource(((Implementation)arg0).getURI()).toString();
+        int lastDot = scriptURI.lastIndexOf('.');
+        String ctURI = scriptURI.substring(0, lastDot) + ".componentType";
+        ComponentType componentType = new DefaultAssemblyFactory().createComponentType();
+        componentType.setUnresolved(true);
+        componentType.setURI(ctURI);
+        componentType = resolver.resolve(ComponentType.class, componentType);
+        if (componentType.isUnresolved()) {
+            throw new ContributionResolveException("missing .componentType side file");
+        }
+        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);
+        }
     }
 
     public void wire(Object arg0) throws ContributionWireException {

Modified: incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationBuilder.java?view=diff&rev=532715&r1=532714&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationBuilder.java (original)
+++ incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationBuilder.java Thu Apr 26 04:48:02 2007
@@ -25,6 +25,7 @@
 import org.apache.tuscany.spi.component.AtomicComponent;
 import org.apache.tuscany.assembly.Component;
 import org.apache.tuscany.assembly.Implementation;
+import org.apache.tuscany.databinding.DataBindingExtensionPoint;
 import org.apache.tuscany.spi.deployer.DeploymentContext;
 import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
 import org.apache.tuscany.spi.implementation.ImplementationActivator;
@@ -32,6 +33,8 @@
 public class ImplementationBuilder extends ComponentBuilderExtension {
 
     private ImplementationActivator ia;
+    private PropertyValueObjectFactory propertyValueObjectFactory;
+    private DataBindingExtensionPoint dataBindingRegistry;
 
     public ImplementationBuilder(ImplementationActivator ia) {
         this.ia = ia;
@@ -46,8 +49,17 @@
         URI uri = URI.create(context.getComponentId() + definition.getName());
         Implementation impl = definition.getImplementation();
         ImplAtomicComponent component = new ImplAtomicComponent(uri, context.getGroupId(), ia, impl);
+        component.setPropertyValueObjectFactory(propertyValueObjectFactory);
+        component.setDataBindingRegistry(dataBindingRegistry);
+        component.initializePropertyValueFactories(definition.getProperties());
         return component;
     }
 
+    public void setPropertyValueObjectFactory(PropertyValueObjectFactory propertyValueObjectFactory) {
+        this.propertyValueObjectFactory = propertyValueObjectFactory;
+    }
 
+    public void setDataBindingRegistry(DataBindingExtensionPoint dataBindingRegistry) {
+        this.dataBindingRegistry = dataBindingRegistry;
+    }
 }

Modified: incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationSPIModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationSPIModuleActivator.java?view=diff&rev=532715&r1=532714&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationSPIModuleActivator.java (original)
+++ incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplementationSPIModuleActivator.java Thu Apr 26 04:48:02 2007
@@ -26,6 +26,8 @@
 import org.apache.tuscany.contribution.processor.StAXArtifactProcessorExtensionPoint;
 import org.apache.tuscany.core.ExtensionPointRegistry;
 import org.apache.tuscany.core.ModuleActivator;
+import org.apache.tuscany.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.databinding.Mediator;
 import org.apache.tuscany.spi.builder.BuilderRegistry;
 import org.apache.tuscany.spi.implementation.ImplementationActivator;
 
@@ -50,8 +52,17 @@
             as.add(implementationArtifactProcessor);
 
             ImplementationBuilder builder = new ImplementationBuilder(ia);
+            builder.setBuilderRegistry(builderRegistry);
             builderRegistry.register(ia.getImplementationClass(), builder);
 
+            Mediator mediator = epRegistry.getExtensionPoint(Mediator.class);
+            PropertyValueObjectFactory factory = new PropertyValueObjectFactory(mediator);
+            builder.setPropertyValueObjectFactory(factory);
+
+            DataBindingExtensionPoint dataBindingRegistry = epRegistry.getExtensionPoint(DataBindingExtensionPoint.class);
+            builder.setDataBindingRegistry(dataBindingRegistry);
+
+            builder.init();
         }
     }
 

Added: incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/PropertyValueObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/PropertyValueObjectFactory.java?view=auto&rev=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/PropertyValueObjectFactory.java (added)
+++ incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/PropertyValueObjectFactory.java Thu Apr 26 04:48:02 2007
@@ -0,0 +1,224 @@
+/*
+ * 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.spi.implementation.impl;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.tuscany.assembly.Property;
+import org.apache.tuscany.databinding.Mediator;
+import org.apache.tuscany.databinding.SimpleTypeMapper;
+import org.apache.tuscany.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.interfacedef.DataType;
+import org.apache.tuscany.interfacedef.util.XMLType;
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class PropertyValueObjectFactory {
+    // protected DataBindingRegistry dbRegistry = new DataBindingRegistryImpl();
+    protected Mediator mediator = null;
+    protected SimpleTypeMapper simpleTypeMapper = new SimpleTypeMapperExtension();
+    boolean isSimpleType;
+    
+    public PropertyValueObjectFactory(Mediator mediator) {
+        this.mediator = mediator;
+    }
+    
+    public ObjectFactory createValueFactory(Property property) {
+        isSimpleType = isSimpleType(property);
+        Document doc = (Document)property.getValue();
+        Element rootElement = doc.getDocumentElement();
+        
+        //FIXME : since scripts use dynamic types we need to generate a dynamic java type using the 
+        //xml structure of the property value.  Should this be done in the JavaBeansDataBinding... 
+        Class javaType = null;
+        
+        if (property.isMany()) {
+            if (isSimpleType) {
+                String value = "";
+                if (rootElement.getChildNodes().getLength() > 0) {
+                    value = rootElement.getChildNodes().item(0).getTextContent();
+                }
+                List<String> values = 
+                    getSimplePropertyValues(value, javaType);
+                return new ListObjectFactoryImpl(property, 
+                                                 values,
+                                                 isSimpleType,
+                                                 javaType);
+            } else {
+                return new ListObjectFactoryImpl(property,
+                                                 getComplexPropertyValues(doc),
+                                                 isSimpleType,
+                                                 javaType);
+            }
+        } else {
+            if (isSimpleType) {
+                String value = "";
+                if (rootElement.getChildNodes().getLength() > 0) {
+                    value = rootElement.getChildNodes().item(0).getTextContent();
+                }
+                return new ObjectFactoryImpl(property,
+                                             value,
+                                             isSimpleType,
+                                             javaType);
+            } else {
+                Object value = getComplexPropertyValues(doc).get(0);
+                return new ObjectFactoryImpl(property,
+                                             value,
+                                             isSimpleType,
+                                             javaType);
+            }
+            
+        }
+    }
+    
+    private boolean isSimpleType(Property property) {
+        if (property.getXSDType() != null) {
+            return SimpleTypeMapperExtension.isSimpleXSDType(property.getXSDType());
+        } else {
+            if (property instanceof Document) {
+                Document doc = (Document)property;
+                Element element = doc.getDocumentElement(); 
+                if (element.getChildNodes().getLength() == 1 && 
+                    element.getChildNodes().item(0).getNodeType() == Element.TEXT_NODE) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+    
+    private List<String> getSimplePropertyValues(String concatenatedValue, Class javaType) {
+        List<String> propValues = new ArrayList<String>();
+        StringTokenizer st = null;
+        if ( javaType.getName().equals("java.lang.String")) {
+            st = new StringTokenizer(concatenatedValue, "\"");
+        } else {
+            st = new StringTokenizer(concatenatedValue);
+        }
+        String aToken = null;
+        while (st.hasMoreTokens()) {
+            aToken = st.nextToken();
+            if (aToken.trim().length() > 0) {
+                propValues.add(aToken);
+            }
+        }
+        return propValues;
+    }
+    
+    private List<Node> getComplexPropertyValues(Document document) {
+        Element rootElement = document.getDocumentElement();
+        List<Node> propValues = new ArrayList<Node>();
+        for (int count = 0 ; count < rootElement.getChildNodes().getLength() ; ++count) {
+            if (rootElement.getChildNodes().item(count).getNodeType() == Document.ELEMENT_NODE) {
+                propValues.add(rootElement.getChildNodes().item(count));
+            }
+        }
+        return propValues;
+    }
+    
+    public abstract class ObjectFactoryImplBase  implements ObjectFactory {
+        protected SimpleTypeMapper simpleTypeMapper = new SimpleTypeMapperExtension();
+        protected Property property;
+        protected Object propertyValue;
+        protected Class javaType;
+        protected DataType<XMLType> sourceDataType;
+        protected DataType<?> targetDataType;
+        boolean isSimpleType;
+
+        public ObjectFactoryImplBase(Property property, Object propertyValue, boolean isSimpleType, Class javaType)  {
+            
+            this.isSimpleType = isSimpleType;
+            this.property = property;
+            this.propertyValue = propertyValue;
+            this.javaType = javaType;
+            //FIXME : fix this when we have managed to generate dynamic java types
+            /*sourceDataType =
+                new DataTypeImpl<XMLType>(DOMDataBinding.NAME, Node.class, 
+                    new XMLType(null, this.property.getXSDType()));
+            TypeInfo typeInfo = null;
+            if (this.property.getXSDType() != null) {
+                if (SimpleTypeMapperExtension.isSimpleXSDType(this.property.getXSDType())) {
+                    typeInfo = new TypeInfo(property.getXSDType(), true, null);
+                } else {
+                    typeInfo = new TypeInfo(property.getXSDType(), false, null);
+                }
+            } else {
+                typeInfo = new TypeInfo(property.getXSDType(), false, null);
+            }
+
+            XMLType xmlType = new XMLType(typeInfo);
+            String dataBinding = null; //(String)property.getExtensions().get(DataBinding.class.getName());
+            if (dataBinding != null) {
+                targetDataType = new DataTypeImpl<XMLType>(dataBinding, javaType, xmlType);
+            } else {
+                targetDataType = new DataTypeImpl<XMLType>(dataBinding, javaType, xmlType);
+                mediator.getDataBindingRegistry().introspectType(targetDataType, null);  
+            }*/
+        }
+    }
+    
+    public class ObjectFactoryImpl extends ObjectFactoryImplBase {
+        public ObjectFactoryImpl(Property property, Object propertyValue, boolean isSimpleType, Class javaType) {
+            super(property, propertyValue, isSimpleType, javaType);
+        }
+
+        @SuppressWarnings("unchecked")
+        public Object getInstance() throws ObjectCreationException {
+            if (isSimpleType) {
+                return simpleTypeMapper.toJavaObject(property.getXSDType(), (String)propertyValue, null);
+            } else {
+                return mediator.mediate(propertyValue, sourceDataType, targetDataType, null);
+                //return null;
+            }
+        }
+    }
+
+    public class ListObjectFactoryImpl extends ObjectFactoryImplBase  {
+        public ListObjectFactoryImpl(Property property, List<?>propertyValues, boolean isSimpleType, Class javaType) {
+            super(property, propertyValues, isSimpleType, javaType);
+        }
+
+        @SuppressWarnings("unchecked")
+        public List<?> getInstance() throws ObjectCreationException {
+            if (isSimpleType) {
+                List<Object> values = new ArrayList<Object>();
+                for (String aValue : (List<String>)propertyValue) {
+                    values.add(simpleTypeMapper.toJavaObject(property.getXSDType(), aValue, null));
+                }
+                return values;
+            } else {
+                List instances = new ArrayList();
+                for (Node aValue : (List<Node>)propertyValue) {
+                    instances.add(mediator.mediate(aValue,
+                                                      sourceDataType,
+                                                      targetDataType,
+                                                      null));
+                }
+                return instances;
+            }
+        }
+    }
+}
+      
\ No newline at end of file

Propchange: incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/PropertyValueObjectFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/PropertyValueObjectFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/sandbox/SPI/implementation-spi/src/main/java/org/apache/tuscany/spi/implementation/Invoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-spi/src/main/java/org/apache/tuscany/spi/implementation/Invoker.java?view=diff&rev=532715&r1=532714&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-spi/src/main/java/org/apache/tuscany/spi/implementation/Invoker.java (original)
+++ incubator/tuscany/sandbox/SPI/implementation-spi/src/main/java/org/apache/tuscany/spi/implementation/Invoker.java Thu Apr 26 04:48:02 2007
@@ -21,6 +21,6 @@
 
 public interface Invoker {
     
-    Object invoke(Object[] args);
+    Object invoke(Object instance, Object[] args);
 
 }

Modified: incubator/tuscany/sandbox/SPI/implementation-spi/src/main/java/org/apache/tuscany/spi/implementation/InvokerFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/SPI/implementation-spi/src/main/java/org/apache/tuscany/spi/implementation/InvokerFactory.java?view=diff&rev=532715&r1=532714&r2=532715
==============================================================================
--- incubator/tuscany/sandbox/SPI/implementation-spi/src/main/java/org/apache/tuscany/spi/implementation/InvokerFactory.java (original)
+++ incubator/tuscany/sandbox/SPI/implementation-spi/src/main/java/org/apache/tuscany/spi/implementation/InvokerFactory.java Thu Apr 26 04:48:02 2007
@@ -19,11 +19,13 @@
 
 package org.apache.tuscany.spi.implementation;
 
+import java.util.Map;
+
 import org.apache.tuscany.interfacedef.Operation;
 
 public interface InvokerFactory {
     
    Invoker createInvoker(Operation operation);
 
-   Object getInstance();
+   Object getInstance(Map<String, Object> references, Map<String, Object> properties);
 }



---------------------------------------------------------------------
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