summaryrefslogtreecommitdiffstats
path: root/branches/sca-equinox/modules/implementation-script-runtime/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'branches/sca-equinox/modules/implementation-script-runtime/src/main')
-rw-r--r--branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java99
-rw-r--r--branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationActivator.java49
-rw-r--r--branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProvider.java (renamed from branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java)147
-rw-r--r--branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProviderFactory.java55
-rw-r--r--branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptInvoker.java (renamed from branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java)10
-rw-r--r--branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptPropertyFactory.java225
-rw-r--r--branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory (renamed from branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.ImplementationActivator)7
7 files changed, 364 insertions, 228 deletions
diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java
deleted file mode 100644
index 87820c18ed..0000000000
--- a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.sca.implementation.script;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import org.apache.tuscany.sca.contribution.Artifact;
-import org.apache.tuscany.sca.contribution.ContributionFactory;
-import org.apache.tuscany.sca.contribution.DefaultContributionFactory;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.extension.helper.utils.ResourceHelper;
-
-/**
- * Represents a Script implementation.
- *
- * @version $Rev$ $Date$
- */
-public class ScriptImplementation {
-
- protected String scriptName;
- protected URL scriptURL;
- protected String scriptSrc;
- protected String scriptLanguage;
-
- public String getScript() {
- return scriptName;
- }
-
- public void setScript(String scriptName) {
- this.scriptName = scriptName;
- }
-
- public void setLanguage(String language) {
- this.scriptLanguage = language;
- }
-
- public void setElementText(String elementText) {
- scriptSrc = elementText;
- }
-
- public String getScriptLanguage() {
- if (scriptLanguage == null || scriptLanguage.length() < 1) {
- int i = scriptName.lastIndexOf('.');
- if (i > 0) {
- scriptLanguage = scriptName.substring(i + 1);
- }
- }
- return scriptLanguage;
- }
-
- public String getScriptSrc() {
- if (scriptSrc == null) {
- if (scriptName == null) {
- throw new IllegalArgumentException("script name is null and no inline source used");
- }
- if (scriptURL == null) {
- throw new RuntimeException("No script: " + scriptName);
- }
-
- scriptSrc = ResourceHelper.readResource(scriptURL);
- }
- return scriptSrc;
- }
-
- public void resolve(ModelResolver resolver) {
-
- if (scriptName != null) {
- //FIXME The contribution factory should be injected
- ContributionFactory contributionFactory = new DefaultContributionFactory();
- Artifact artifact = contributionFactory.createArtifact();
- artifact.setURI(scriptName);
- artifact = resolver.resolveModel(Artifact.class, artifact);
- if (artifact.getLocation() != null) {
- try {
- scriptURL = new URL(artifact.getLocation());
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-}
diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationActivator.java b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationActivator.java
deleted file mode 100644
index a7c4b9074f..0000000000
--- a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationActivator.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.sca.implementation.script;
-
-import org.apache.tuscany.sca.assembly.ComponentType;
-import org.apache.tuscany.sca.extension.helper.ImplementationActivator;
-import org.apache.tuscany.sca.extension.helper.InvokerFactory;
-import org.apache.tuscany.sca.extension.helper.utils.PropertyValueObjectFactory;
-import org.apache.tuscany.sca.runtime.RuntimeComponent;
-
-/**
- *
- * @version $Rev$ $Date$
- */
-public class ScriptImplementationActivator implements ImplementationActivator<ScriptImplementation> {
-
- // TODO: seems wrong to need PropertyValueObjectFactory, could it be on Property somehow?
- protected PropertyValueObjectFactory propertyFactory;
-
- public ScriptImplementationActivator(PropertyValueObjectFactory propertyFactory) {
- this.propertyFactory = propertyFactory;
- }
-
- public Class<ScriptImplementation> getImplementationClass() {
- return ScriptImplementation.class;
- }
-
- public InvokerFactory createInvokerFactory(RuntimeComponent rc, ComponentType ct, ScriptImplementation implementation) {
- return new ScriptInvokerFactory(rc, ct, implementation, propertyFactory);
- }
-
-}
diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProvider.java
index 9359590424..473b990a79 100644
--- a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java
+++ b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProvider.java
@@ -17,9 +17,11 @@
* under the License.
*/
-package org.apache.tuscany.sca.implementation.script;
+package org.apache.tuscany.sca.implementation.script.provider;
-import java.io.StringReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -31,108 +33,103 @@ import javax.script.ScriptException;
import org.apache.axiom.om.OMElement;
import org.apache.bsf.xml.XMLHelper;
import org.apache.tuscany.sca.assembly.ComponentReference;
-import org.apache.tuscany.sca.assembly.ComponentType;
import org.apache.tuscany.sca.assembly.Property;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.core.factory.ObjectCreationException;
import org.apache.tuscany.sca.core.factory.ObjectFactory;
-import org.apache.tuscany.sca.extension.helper.InvokerFactory;
-import org.apache.tuscany.sca.extension.helper.utils.PropertyValueObjectFactory;
+import org.apache.tuscany.sca.implementation.script.ScriptImplementation;
import org.apache.tuscany.sca.implementation.script.engines.TuscanyJRubyScriptEngine;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
/**
+ * An ImplementationProvider for Script implementations.
*
- * @version $Rev$ $Date$
+ * @version $Rev: $ $Date: $
*/
-public class ScriptInvokerFactory implements InvokerFactory {
-
- protected ScriptEngine scriptEngine;
- protected XMLHelper xmlHelper;
+public class ScriptImplementationProvider implements ImplementationProvider {
- protected RuntimeComponent rc;
- protected ComponentType ct;
- protected ScriptImplementation implementation;
- protected PropertyValueObjectFactory propertyFactory;
-
+ private RuntimeComponent component;
+ private ScriptImplementation implementation;
+ private ScriptPropertyFactory propertyFactory;
+ private ScriptEngine scriptEngine;
+ private XMLHelper xmlHelper;
- /**
- * @param rc
- * @param ct
- * @param implementation
- * @param propertyFactory
- */
- public ScriptInvokerFactory(RuntimeComponent rc,
- ComponentType ct,
- ScriptImplementation implementation,
- PropertyValueObjectFactory propertyFactory) {
- super();
- this.rc = rc;
- this.ct = ct;
+ public ScriptImplementationProvider(RuntimeComponent component, ScriptImplementation implementation, ScriptPropertyFactory propertyFactory) {
+ this.component = component;
this.implementation = implementation;
this.propertyFactory = propertyFactory;
- }
- public Invoker createInvoker(Operation operation) {
- init(rc, ct, implementation, propertyFactory);
- return new ScriptInvoker(scriptEngine, xmlHelper, operation);
- }
-
- protected synchronized void init(RuntimeComponent rc, ComponentType ct, ScriptImplementation implementation, PropertyValueObjectFactory propertyFactory) {
- if(scriptEngine!=null) {
- return;
+ // Set the databinding and XMLHelper for WSDL interfaces
+ for (Service service : component.getServices()) {
+ InterfaceContract ic = service.getInterfaceContract();
+ if (ic instanceof WSDLInterfaceContract) {
+ ic.getInterface().resetDataBinding(OMElement.class.getName());
+ xmlHelper = XMLHelper.getArgHelper(scriptEngine);
+ }
}
+ }
+
+ public void start() {
try {
- scriptEngine = getScriptEngineByExtension(implementation.getScriptLanguage());
+ String language = implementation.getLanguage();
+ if (language == null) {
+ language = implementation.getScript();
+ language = language.substring(language.lastIndexOf('.') +1);
+ }
+ scriptEngine = scriptEngine(language);
if (scriptEngine == null) {
- throw new ObjectCreationException("no script engine found for language: " + implementation.getScriptLanguage());
+ throw new ObjectCreationException("no script engine found for language: " + implementation.getLanguage());
}
if (!(scriptEngine instanceof Invocable)) {
throw new ObjectCreationException("script engine does not support Invocable: " + scriptEngine);
}
- for (Reference reference : ct.getReferences()) {
- scriptEngine.put(reference.getName(), createReferenceProxy(reference.getName(), rc));
+ for (Reference reference : implementation.getReferences()) {
+ scriptEngine.put(reference.getName(), getProxy(reference.getName()));
}
- for (Property property : ct.getProperties()) {
- ObjectFactory<?> propertyValueFactory = propertyFactory.createValueFactory(property);
- if ( propertyValueFactory != null) {
- scriptEngine.put(property.getName(), propertyValueFactory.getInstance());
+ for (Property property : implementation.getProperties()) {
+ ObjectFactory<?> valueFactory = propertyFactory.createValueFactory(property);
+ if (valueFactory != null) {
+ scriptEngine.put(property.getName(), valueFactory.getInstance());
}
}
-
- scriptEngine.eval(new StringReader(implementation.getScriptSrc()));
+ URL url = new URL(implementation.getLocation());
+ InputStreamReader reader = new InputStreamReader(url.openStream());
+ scriptEngine.eval(reader);
+ reader.close();
+
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
} catch (ScriptException e) {
- throw new ObjectCreationException(e);
+ throw new IllegalArgumentException(e);
}
+ }
- // set the databinding and XMLHelper for WSDL interfaces
- for (Service service : rc.getServices()) {
- InterfaceContract ic = service.getInterfaceContract();
- if (ic instanceof WSDLInterfaceContract) {
- // Set to use the Axiom data binding
- ic.getInterface().resetDataBinding(OMElement.class.getName());
- xmlHelper = XMLHelper.getArgHelper(scriptEngine);
- }
- }
+ public void stop() {
}
- /**
- * TODO: RuntimeComponent should provide a method like this
- */
- @SuppressWarnings("unchecked")
- protected Object createReferenceProxy(String name, RuntimeComponent component) {
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
+
+ public Invoker createInvoker(RuntimeComponentService service, Operation operation) {
+ return new ScriptInvoker(scriptEngine, xmlHelper, operation);
+ }
+
+ private Object getProxy(String name) {
for (ComponentReference reference : component.getReferences()) {
if (reference.getName().equals(name)) {
- Class iface = ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass();
+ Class<?> iface = ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass();
return component.getComponentContext().getService(iface, name);
}
}
@@ -140,15 +137,21 @@ public class ScriptInvokerFactory implements InvokerFactory {
}
/**
- * Hack for now to work around a problem with the JRuby script engine
+ * Returns the script engine for the given language.
+ *
+ * @param language
+ * @return
*/
- protected ScriptEngine getScriptEngineByExtension(String scriptExtn) {
- if ("rb".equals(scriptExtn)) {
+ private ScriptEngine scriptEngine(String language) {
+ if ("rb".equals(language)) {
+
+ // Hack for now to work around a problem with the JRuby script engine
return new TuscanyJRubyScriptEngine();
} else {
- if ("py".equals(scriptExtn)) {
+ if ("py".equals(language)) {
pythonCachedir();
}
+
// Allow privileged access to run access classes. Requires RuntimePermission
// for accessClassInPackage.sun.misc.
ScriptEngineManager scriptEngineManager =
@@ -157,7 +160,7 @@ public class ScriptInvokerFactory implements InvokerFactory {
return new ScriptEngineManager();
}
});
- return scriptEngineManager.getEngineByExtension(scriptExtn);
+ return scriptEngineManager.getEngineByExtension(language);
}
}
@@ -165,9 +168,9 @@ public class ScriptInvokerFactory implements InvokerFactory {
* If the Python home isn't set then let Tuscany suppress messages other than errors
* See TUSCANY-1950
*/
- protected void pythonCachedir() {
- if (System.getProperty("python.home") == null) {
- System.setProperty("python.verbose", "error");
- }
+ private static void pythonCachedir() {
+ if (System.getProperty("python.home") == null) {
+ System.setProperty("python.verbose", "error");
+ }
}
}
diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProviderFactory.java b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProviderFactory.java
new file mode 100644
index 0000000000..f65403c9ed
--- /dev/null
+++ b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProviderFactory.java
@@ -0,0 +1,55 @@
+/*
+ * 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.sca.implementation.script.provider;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.TransformerExtensionPoint;
+import org.apache.tuscany.sca.databinding.impl.MediatorImpl;
+import org.apache.tuscany.sca.implementation.script.ScriptImplementation;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * An ImplementationProviderFactory for Script implementations.
+ *
+ * @version $Rev: $ $Date: $
+ */
+public class ScriptImplementationProviderFactory implements ImplementationProviderFactory<ScriptImplementation> {
+
+ private ScriptPropertyFactory propertyFactory;
+
+ public ScriptImplementationProviderFactory(ExtensionPointRegistry extensionPoints) {
+ Mediator mediator = new MediatorImpl(extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class),
+ extensionPoints.getExtensionPoint(TransformerExtensionPoint.class));
+ propertyFactory = new ScriptPropertyFactory(mediator);
+ }
+
+ public ImplementationProvider createImplementationProvider(RuntimeComponent component, ScriptImplementation Implementation) {
+ return new ScriptImplementationProvider(component, Implementation, propertyFactory);
+ }
+
+ public Class<ScriptImplementation> getModelType() {
+ return ScriptImplementation.class;
+ }
+
+}
diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptInvoker.java
index 2ccb414be8..976eb2c0dd 100644
--- a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java
+++ b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptInvoker.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.implementation.script;
+package org.apache.tuscany.sca.implementation.script.provider;
import javax.script.Invocable;
import javax.script.ScriptEngine;
@@ -36,9 +36,9 @@ import org.apache.tuscany.sca.invocation.Message;
*/
public class ScriptInvoker implements Invoker {
- protected ScriptEngine scriptEngine;
- protected XMLHelper xmlHelper;
- protected Operation operation;
+ private ScriptEngine scriptEngine;
+ private XMLHelper xmlHelper;
+ private Operation operation;
public ScriptInvoker(ScriptEngine scriptEngine, XMLHelper xmlHelper, Operation operation) {
this.scriptEngine = scriptEngine;
@@ -46,7 +46,7 @@ public class ScriptInvoker implements Invoker {
this.operation = operation;
}
- protected Object doInvoke(Object[] objects, Operation op) throws ScriptException {
+ private Object doInvoke(Object[] objects, Operation op) throws ScriptException {
if (xmlHelper != null) {
objects[0] = xmlHelper.toScriptXML((OMElement)objects[0]);
}
diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptPropertyFactory.java b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptPropertyFactory.java
new file mode 100644
index 0000000000..5833c9f4d5
--- /dev/null
+++ b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptPropertyFactory.java
@@ -0,0 +1,225 @@
+/*
+ * 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.sca.implementation.script.provider;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.SimpleTypeMapper;
+import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * A property factory for script properties.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScriptPropertyFactory {
+ private Mediator mediator = null;
+ boolean isSimpleType;
+
+ public ScriptPropertyFactory(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 SimpleTypeMapperImpl.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() == Node.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() == Node.ELEMENT_NODE) {
+ propValues.add(rootElement.getChildNodes().item(count));
+ }
+ }
+ return propValues;
+ }
+
+ public abstract class ObjectFactoryImplBase implements ObjectFactory {
+ protected SimpleTypeMapper simpleTypeMapper = new SimpleTypeMapperImpl();
+ 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);
+ }
+
+ public Object getInstance() throws ObjectCreationException {
+ if (isSimpleType) {
+ return simpleTypeMapper.toJavaObject(property.getXSDType(), (String)propertyValue, null);
+ } else {
+ return mediator.mediate(propertyValue, sourceDataType, targetDataType, null);
+ }
+ }
+ }
+
+ public class ListObjectFactoryImpl extends ObjectFactoryImplBase {
+ public ListObjectFactoryImpl(Property property, List<?>propertyValues, boolean isSimpleType, Class<?> javaType) {
+ super(property, propertyValues, isSimpleType, javaType);
+ }
+
+ 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<Object> instances = new ArrayList<Object>();
+ for (Node aValue : (List<Node>)propertyValue) {
+ instances.add(mediator.mediate(aValue,
+ sourceDataType,
+ targetDataType,
+ null));
+ }
+ return instances;
+ }
+ }
+ }
+}
diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.ImplementationActivator b/branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
index c8152b606f..941cfd7fd5 100644
--- a/branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.ImplementationActivator
+++ b/branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
@@ -13,6 +13,7 @@
# "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.
-# Implementation class for the ExtensionActivator
-org.apache.tuscany.sca.implementation.script.ScriptImplementationActivator
+# under the License.
+
+# Implementation class for the implementation extension
+org.apache.tuscany.sca.implementation.script.provider.ScriptImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.script.ScriptImplementation