From ad3556602a27b731bfeaebe306e5c0c3e15222ae Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 22 Sep 2008 05:44:18 +0000 Subject: Another fix for TUSCANY-2396. Split implementation-script into two modules, model and runtime. Got the script implementations that use componentTypes working. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@697664 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca-equinox/distribution/features/all/pom.xml | 2 + .../all/src/main/components/src-modules.xml | 2 + .../distribution/features/repository/pom.xml | 2 + .../repository/src/main/components/src-modules.xml | 2 + .../distribution/features/web20/pom.xml | 7 + .../web20/src/main/components/src-modules.xml | 2 + .../modules/implementation-script-runtime/pom.xml | 21 +- .../script/ScriptImplementation.java | 99 --- .../script/ScriptImplementationActivator.java | 49 -- .../sca/implementation/script/ScriptInvoker.java | 84 --- .../script/ScriptInvokerFactory.java | 173 ----- .../provider/ScriptImplementationProvider.java | 176 ++++++ .../ScriptImplementationProviderFactory.java | 55 ++ .../script/provider/ScriptInvoker.java | 84 +++ .../script/provider/ScriptPropertyFactory.java | 225 +++++++ ...ny.sca.extension.helper.ImplementationActivator | 18 - ...cany.sca.provider.ImplementationProviderFactory | 19 + .../itests/dynamic/AbstractHelloWorldTestCase.java | 38 -- .../script/itests/dynamic/HelloWorld.java | 31 - .../dynamic/JavaScriptDynamicRefTestCase.java | 29 - .../dynamic/JavaScriptHelloWorldTestCase.java | 34 - .../JavaScripInlineHelloWorldTestCase.java | 29 - .../itests/dynamic/JavaScriptDynamicRef.composite | 35 -- .../itests/dynamic/JavaScriptHelloWorld.composite | 30 - .../script/itests/dynamic/helloworld.js | 26 - .../script/itests/dynamic/helloworldProxy.js | 22 - .../helloworld/JavaScripInlineHelloWorld.composite | 34 - .../modules/implementation-script/pom.xml | 130 +--- .../script/ScriptImplementation.java | 120 ++-- .../script/ScriptImplementationActivator.java | 49 -- .../script/ScriptImplementationProcessor.java | 166 +++++ .../sca/implementation/script/ScriptInvoker.java | 84 --- .../script/ScriptInvokerFactory.java | 173 ----- .../script/engines/TuscanyJRubyScriptEngine.java | 697 --------------------- ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...ny.sca.extension.helper.ImplementationActivator | 18 - .../script/itests/AbstractSCATestCase.java | 54 -- .../itests/dynamic/AbstractHelloWorldTestCase.java | 38 -- .../script/itests/dynamic/HelloWorld.java | 31 - .../dynamic/JavaScriptDynamicRefTestCase.java | 29 - .../dynamic/JavaScriptHelloWorldTestCase.java | 34 - .../helloworld/AbstractHelloWorldTestCase.java | 38 -- .../helloworld/GroovyHelloWorldTestCase.java | 29 - .../script/itests/helloworld/HelloWorld.java | 30 - .../script/itests/helloworld/HelloWorldProxy.java | 37 -- .../itests/helloworld/JRubyHelloWorldTestCase.java | 29 - .../JavaScripInlineHelloWorldTestCase.java | 29 - .../helloworld/JavaScriptHelloWorldTestCase.java | 29 - .../helloworld/JythonHelloWorldTestCase.java | 29 - .../properties/AbstractHelloWorldTestCase.java | 38 -- .../properties/GroovyHelloWorldTestCase.java | 29 - .../script/itests/properties/HelloWorld.java | 30 - .../script/itests/properties/HelloWorldProxy.java | 37 -- .../itests/properties/JRubyHelloWorldTestCase.java | 28 - .../properties/JavaScriptHelloWorldTestCase.java | 29 - .../properties/JythonHelloWorldTestCase.java | 29 - .../itests/references/GroovyReferenceTestCase.java | 29 - .../script/itests/references/HelloWorldTarget.java | 34 - .../itests/references/JRubyReferenceTestCase.java | 29 - .../references/JavaScriptReferenceTestCase.java | 29 - .../itests/references/JythonReferenceTestCase.java | 29 - .../itests/dynamic/JavaScriptDynamicRef.composite | 35 -- .../itests/dynamic/JavaScriptHelloWorld.composite | 30 - .../script/itests/dynamic/helloworld.js | 26 - .../script/itests/dynamic/helloworldProxy.js | 22 - .../itests/helloworld/GroovyHelloWorld.composite | 33 - .../itests/helloworld/JRubyHelloWorld.composite | 33 - .../helloworld/JavaScripInlineHelloWorld.composite | 34 - .../helloworld/JavaScriptHelloWorld.composite | 33 - .../itests/helloworld/JythonHelloWorld.composite | 33 - .../itests/helloworld/helloworld.componentType | 30 - .../script/itests/helloworld/helloworld.groovy | 22 - .../script/itests/helloworld/helloworld.js | 23 - .../script/itests/helloworld/helloworld.py | 20 - .../script/itests/helloworld/helloworld.rb | 21 - .../itests/properties/GroovyHelloWorld.composite | 33 - .../itests/properties/JRubyHelloWorld.composite | 33 - .../properties/JavaScriptHelloWorld.composite | 33 - .../itests/properties/JythonHelloWorld.composite | 33 - .../itests/properties/helloworld.componentType | 32 - .../script/itests/properties/helloworld.groovy | 22 - .../script/itests/properties/helloworld.js | 23 - .../script/itests/properties/helloworld.py | 20 - .../script/itests/properties/helloworld.rb | 21 - .../itests/references/GroovyReference.composite | 38 -- .../itests/references/JRubyReference.composite | 38 -- .../references/JavaScriptReference.composite | 38 -- .../itests/references/JythonReference.composite | 38 -- .../itests/references/reference.componentType | 31 - .../script/itests/references/reference.groovy | 22 - .../script/itests/references/reference.js | 22 - .../script/itests/references/reference.py | 20 - .../script/itests/references/reference.rb | 21 - branches/sca-equinox/modules/pom.xml | 2 - .../sca-equinox/samples/calculator-script/pom.xml | 2 +- 95 files changed, 852 insertions(+), 3655 deletions(-) delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationActivator.java delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java create mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProvider.java create mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProviderFactory.java create mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptInvoker.java create mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptPropertyFactory.java delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.ImplementationActivator create mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/AbstractHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/HelloWorld.java delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRefTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRef.composite delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworld.js delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworldProxy.js delete mode 100644 branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationActivator.java create mode 100644 branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationProcessor.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/engines/TuscanyJRubyScriptEngine.java create mode 100644 branches/sca-equinox/modules/implementation-script/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor delete mode 100644 branches/sca-equinox/modules/implementation-script/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.ImplementationActivator delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/AbstractSCATestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/AbstractHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/HelloWorld.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRefTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/AbstractHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/GroovyHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/HelloWorld.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/HelloWorldProxy.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JRubyHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScriptHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JythonHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/AbstractHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/GroovyHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/HelloWorld.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/HelloWorldProxy.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JRubyHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JavaScriptHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JythonHelloWorldTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/GroovyReferenceTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/HelloWorldTarget.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JRubyReferenceTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JavaScriptReferenceTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JythonReferenceTestCase.java delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRef.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworld.js delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworldProxy.js delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/GroovyHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JRubyHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScriptHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JythonHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.componentType delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.groovy delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.js delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.py delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.rb delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/GroovyHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JRubyHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JavaScriptHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JythonHelloWorld.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.componentType delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.groovy delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.js delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.py delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.rb delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/GroovyReference.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JRubyReference.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JavaScriptReference.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JythonReference.composite delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.componentType delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.groovy delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.js delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.py delete mode 100644 branches/sca-equinox/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.rb (limited to 'branches/sca-equinox') diff --git a/branches/sca-equinox/distribution/features/all/pom.xml b/branches/sca-equinox/distribution/features/all/pom.xml index f8fbd62e79..f70bb16bf0 100644 --- a/branches/sca-equinox/distribution/features/all/pom.xml +++ b/branches/sca-equinox/distribution/features/all/pom.xml @@ -228,6 +228,8 @@ ../../../modules/implementation-node-runtime ../../../modules/implementation-resource ../../../modules/implementation-resource-runtime + ../../../modules/implementation-script + ../../../modules/implementation-script-runtime ../../../modules/implementation-spring ../../../modules/implementation-widget ../../../modules/implementation-widget-runtime diff --git a/branches/sca-equinox/distribution/features/all/src/main/components/src-modules.xml b/branches/sca-equinox/distribution/features/all/src/main/components/src-modules.xml index 18ec984770..67dd932704 100644 --- a/branches/sca-equinox/distribution/features/all/src/main/components/src-modules.xml +++ b/branches/sca-equinox/distribution/features/all/src/main/components/src-modules.xml @@ -107,6 +107,8 @@ implementation-node-runtime/**/* implementation-resource/**/* implementation-resource-runtime/**/* + implementation-script/**/* + implementation-script-runtime/**/* implementation-spring/**/* implementation-widget/**/* implementation-widget-runtime/**/* diff --git a/branches/sca-equinox/distribution/features/repository/pom.xml b/branches/sca-equinox/distribution/features/repository/pom.xml index c8450af762..2505276816 100644 --- a/branches/sca-equinox/distribution/features/repository/pom.xml +++ b/branches/sca-equinox/distribution/features/repository/pom.xml @@ -155,6 +155,8 @@ ../../../modules/implementation-node-runtime ../../../modules/implementation-resource ../../../modules/implementation-resource-runtime + ../../../modules/implementation-script + ../../../modules/implementation-script-runtime ../../../modules/implementation-spring ../../../modules/implementation-widget ../../../modules/implementation-widget-runtime diff --git a/branches/sca-equinox/distribution/features/repository/src/main/components/src-modules.xml b/branches/sca-equinox/distribution/features/repository/src/main/components/src-modules.xml index acee92e060..1754539cd0 100644 --- a/branches/sca-equinox/distribution/features/repository/src/main/components/src-modules.xml +++ b/branches/sca-equinox/distribution/features/repository/src/main/components/src-modules.xml @@ -108,6 +108,8 @@ implementation-node-runtime/**/* implementation-resource/**/* implementation-resource-runtime/**/* + implementation-script/**/* + implementation-script-runtime/**/* implementation-spring/**/* implementation-widget/**/* implementation-widget-runtime/**/* diff --git a/branches/sca-equinox/distribution/features/web20/pom.xml b/branches/sca-equinox/distribution/features/web20/pom.xml index ea87daa207..3db6afbd9c 100644 --- a/branches/sca-equinox/distribution/features/web20/pom.xml +++ b/branches/sca-equinox/distribution/features/web20/pom.xml @@ -89,6 +89,11 @@ tuscany-implementation-resource-runtime 1.4-SNAPSHOT + + org.apache.tuscany.sca + tuscany-implementation-script-runtime + 1.4-SNAPSHOT + org.apache.tuscany.sca tuscany-implementation-widget-runtime @@ -179,6 +184,8 @@ ../../../modules/implementation-node-runtime ../../../modules/implementation-resource ../../../modules/implementation-resource-runtime + ../../../modules/implementation-script + ../../../modules/implementation-script-runtime ../../../modules/implementation-widget ../../../modules/implementation-widget-runtime ../../../modules/interface diff --git a/branches/sca-equinox/distribution/features/web20/src/main/components/src-modules.xml b/branches/sca-equinox/distribution/features/web20/src/main/components/src-modules.xml index 7c5f00ed36..df51f57953 100644 --- a/branches/sca-equinox/distribution/features/web20/src/main/components/src-modules.xml +++ b/branches/sca-equinox/distribution/features/web20/src/main/components/src-modules.xml @@ -69,6 +69,8 @@ implementation-node-runtime/**/* implementation-resource/**/* implementation-resource-runtime/**/* + implementation-script/**/* + implementation-script-runtime/**/* implementation-widget/**/* implementation-widget-runtime/**/* interface/**/* diff --git a/branches/sca-equinox/modules/implementation-script-runtime/pom.xml b/branches/sca-equinox/modules/implementation-script-runtime/pom.xml index 06a4313d6d..354a01d4bf 100644 --- a/branches/sca-equinox/modules/implementation-script-runtime/pom.xml +++ b/branches/sca-equinox/modules/implementation-script-runtime/pom.xml @@ -43,6 +43,18 @@ 1.4-SNAPSHOT + + org.apache.tuscany.sca + tuscany-core + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding + 1.4-SNAPSHOT + + org.apache.bsf bsf-all @@ -107,6 +119,13 @@ test + + org.apache.tuscany.sca + tuscany-host-embedded + 1.4-SNAPSHOT + test + + org.apache.tuscany.sca tuscany-implementation-java-runtime @@ -186,7 +205,7 @@ ${tuscany.version} org.apache.tuscany.sca.implementation.script.runtime ${pom.name} - org.apache.tuscany.sca.implementation.script.provider* + org.apache.tuscany.sca.implementation.script.provider 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 { - - // TODO: seems wrong to need PropertyValueObjectFactory, could it be on Property somehow? - protected PropertyValueObjectFactory propertyFactory; - - public ScriptImplementationActivator(PropertyValueObjectFactory propertyFactory) { - this.propertyFactory = propertyFactory; - } - - public Class 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/ScriptInvoker.java b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java deleted file mode 100644 index 2ccb414be8..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java +++ /dev/null @@ -1,84 +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 javax.script.Invocable; -import javax.script.ScriptEngine; -import javax.script.ScriptException; - -import org.apache.axiom.om.OMElement; -import org.apache.bsf.xml.XMLHelper; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; - -/** - * Perform the actual script invocation - * - * @version $Rev$ $Date$ - */ -public class ScriptInvoker implements Invoker { - - protected ScriptEngine scriptEngine; - protected XMLHelper xmlHelper; - protected Operation operation; - - public ScriptInvoker(ScriptEngine scriptEngine, XMLHelper xmlHelper, Operation operation) { - this.scriptEngine = scriptEngine; - this.xmlHelper = xmlHelper; - this.operation = operation; - } - - protected Object doInvoke(Object[] objects, Operation op) throws ScriptException { - if (xmlHelper != null) { - objects[0] = xmlHelper.toScriptXML((OMElement)objects[0]); - } - - Operation oper = operation; // static setting - if (oper.getName() == null) { // if no static setting - oper = op; // use dynamic setting - } - Object response; - try { - response = ((Invocable)scriptEngine).invokeFunction(oper.getName(), objects); - } catch (ScriptException e) { - throw e; - } catch (Exception e) { - throw new ScriptException(e); - } - - if (xmlHelper != null) { - response = xmlHelper.toOMElement(response); - } - - return response; - } - - public Message invoke(Message msg) { - try { - Object resp = doInvoke((Object[])msg.getBody(), msg.getOperation()); - msg.setBody(resp); - } catch (ScriptException e) { - msg.setFaultBody(e.getCause()); - } - return msg; - } - -} 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/ScriptInvokerFactory.java deleted file mode 100644 index 9359590424..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java +++ /dev/null @@ -1,173 +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.io.StringReader; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import javax.script.Invocable; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -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.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.runtime.RuntimeComponent; - -/** - * - * @version $Rev$ $Date$ - */ -public class ScriptInvokerFactory implements InvokerFactory { - - protected ScriptEngine scriptEngine; - protected XMLHelper xmlHelper; - - protected RuntimeComponent rc; - protected ComponentType ct; - protected ScriptImplementation implementation; - protected PropertyValueObjectFactory propertyFactory; - - - /** - * @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; - 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; - } - try { - scriptEngine = getScriptEngineByExtension(implementation.getScriptLanguage()); - if (scriptEngine == null) { - throw new ObjectCreationException("no script engine found for language: " + implementation.getScriptLanguage()); - } - 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 (Property property : ct.getProperties()) { - ObjectFactory propertyValueFactory = propertyFactory.createValueFactory(property); - if ( propertyValueFactory != null) { - scriptEngine.put(property.getName(), propertyValueFactory.getInstance()); - } - } - - scriptEngine.eval(new StringReader(implementation.getScriptSrc())); - - } catch (ScriptException e) { - throw new ObjectCreationException(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); - } - } - } - - /** - * TODO: RuntimeComponent should provide a method like this - */ - @SuppressWarnings("unchecked") - protected Object createReferenceProxy(String name, RuntimeComponent component) { - for (ComponentReference reference : component.getReferences()) { - if (reference.getName().equals(name)) { - Class iface = ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass(); - return component.getComponentContext().getService(iface, name); - } - } - throw new IllegalArgumentException("reference " + name + " not found on component: " + component); - } - - /** - * Hack for now to work around a problem with the JRuby script engine - */ - protected ScriptEngine getScriptEngineByExtension(String scriptExtn) { - if ("rb".equals(scriptExtn)) { - return new TuscanyJRubyScriptEngine(); - } else { - if ("py".equals(scriptExtn)) { - pythonCachedir(); - } - // Allow privileged access to run access classes. Requires RuntimePermission - // for accessClassInPackage.sun.misc. - ScriptEngineManager scriptEngineManager = - AccessController.doPrivileged(new PrivilegedAction() { - public ScriptEngineManager run() { - return new ScriptEngineManager(); - } - }); - return scriptEngineManager.getEngineByExtension(scriptExtn); - } - } - - /** - * 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"); - } - } -} diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProvider.java b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProvider.java new file mode 100644 index 0000000000..473b990a79 --- /dev/null +++ b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptImplementationProvider.java @@ -0,0 +1,176 @@ +/* + * 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.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import javax.script.Invocable; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +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.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.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: $ + */ +public class ScriptImplementationProvider implements ImplementationProvider { + + private RuntimeComponent component; + private ScriptImplementation implementation; + private ScriptPropertyFactory propertyFactory; + private ScriptEngine scriptEngine; + private XMLHelper xmlHelper; + + public ScriptImplementationProvider(RuntimeComponent component, ScriptImplementation implementation, ScriptPropertyFactory propertyFactory) { + this.component = component; + this.implementation = implementation; + this.propertyFactory = propertyFactory; + + // 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 { + 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.getLanguage()); + } + if (!(scriptEngine instanceof Invocable)) { + throw new ObjectCreationException("script engine does not support Invocable: " + scriptEngine); + } + + for (Reference reference : implementation.getReferences()) { + scriptEngine.put(reference.getName(), getProxy(reference.getName())); + } + + for (Property property : implementation.getProperties()) { + ObjectFactory valueFactory = propertyFactory.createValueFactory(property); + if (valueFactory != null) { + scriptEngine.put(property.getName(), valueFactory.getInstance()); + } + } + + 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 IllegalArgumentException(e); + } + } + + public void stop() { + } + + 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(); + return component.getComponentContext().getService(iface, name); + } + } + throw new IllegalArgumentException("reference " + name + " not found on component: " + component); + } + + /** + * Returns the script engine for the given language. + * + * @param language + * @return + */ + 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(language)) { + pythonCachedir(); + } + + // Allow privileged access to run access classes. Requires RuntimePermission + // for accessClassInPackage.sun.misc. + ScriptEngineManager scriptEngineManager = + AccessController.doPrivileged(new PrivilegedAction() { + public ScriptEngineManager run() { + return new ScriptEngineManager(); + } + }); + return scriptEngineManager.getEngineByExtension(language); + } + } + + /** + * If the Python home isn't set then let Tuscany suppress messages other than errors + * See TUSCANY-1950 + */ + 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 { + + 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 getModelType() { + return ScriptImplementation.class; + } + +} diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptInvoker.java b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptInvoker.java new file mode 100644 index 0000000000..976eb2c0dd --- /dev/null +++ b/branches/sca-equinox/modules/implementation-script-runtime/src/main/java/org/apache/tuscany/sca/implementation/script/provider/ScriptInvoker.java @@ -0,0 +1,84 @@ +/* + * 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 javax.script.Invocable; +import javax.script.ScriptEngine; +import javax.script.ScriptException; + +import org.apache.axiom.om.OMElement; +import org.apache.bsf.xml.XMLHelper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Perform the actual script invocation + * + * @version $Rev$ $Date$ + */ +public class ScriptInvoker implements Invoker { + + private ScriptEngine scriptEngine; + private XMLHelper xmlHelper; + private Operation operation; + + public ScriptInvoker(ScriptEngine scriptEngine, XMLHelper xmlHelper, Operation operation) { + this.scriptEngine = scriptEngine; + this.xmlHelper = xmlHelper; + this.operation = operation; + } + + private Object doInvoke(Object[] objects, Operation op) throws ScriptException { + if (xmlHelper != null) { + objects[0] = xmlHelper.toScriptXML((OMElement)objects[0]); + } + + Operation oper = operation; // static setting + if (oper.getName() == null) { // if no static setting + oper = op; // use dynamic setting + } + Object response; + try { + response = ((Invocable)scriptEngine).invokeFunction(oper.getName(), objects); + } catch (ScriptException e) { + throw e; + } catch (Exception e) { + throw new ScriptException(e); + } + + if (xmlHelper != null) { + response = xmlHelper.toOMElement(response); + } + + return response; + } + + public Message invoke(Message msg) { + try { + Object resp = doInvoke((Object[])msg.getBody(), msg.getOperation()); + msg.setBody(resp); + } catch (ScriptException e) { + msg.setFaultBody(e.getCause()); + } + return msg; + } + +} 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 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 getSimplePropertyValues(String concatenatedValue, Class javaType) { + List propValues = new ArrayList(); + 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 getComplexPropertyValues(Document document) { + Element rootElement = document.getDocumentElement(); + List propValues = new ArrayList(); + 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 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(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(dataBinding, javaType, xmlType); + } else { + targetDataType = new DataTypeImpl(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, ListpropertyValues, boolean isSimpleType, Class javaType) { + super(property, propertyValues, isSimpleType, javaType); + } + + public List getInstance() throws ObjectCreationException { + if (isSimpleType) { + List values = new ArrayList(); + for (String aValue : (List)propertyValue) { + values.add(simpleTypeMapper.toJavaObject(property.getXSDType(), aValue, null)); + } + return values; + } else { + List instances = new ArrayList(); + for (Node aValue : (List)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.extension.helper.ImplementationActivator deleted file mode 100644 index c8152b606f..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.ImplementationActivator +++ /dev/null @@ -1,18 +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. -# Implementation class for the ExtensionActivator -org.apache.tuscany.sca.implementation.script.ScriptImplementationActivator diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory new file mode 100644 index 0000000000..941cfd7fd5 --- /dev/null +++ b/branches/sca-equinox/modules/implementation-script-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for the implementation extension +org.apache.tuscany.sca.implementation.script.provider.ScriptImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.script.ScriptImplementation diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/AbstractHelloWorldTestCase.java b/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/AbstractHelloWorldTestCase.java deleted file mode 100644 index 09239cd38f..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/AbstractHelloWorldTestCase.java +++ /dev/null @@ -1,38 +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.itests.dynamic; - -import org.apache.tuscany.sca.implementation.script.itests.AbstractSCATestCase; - -/** - * - * @version $Rev$ $Date$ - */ -public abstract class AbstractHelloWorldTestCase extends AbstractSCATestCase { - - public void testHello() throws Exception { - assertEquals("Hello petra", service.sayHello("petra")); - } - - @Override - protected Class getServiceClass() { - return HelloWorld.class; - } -} diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/HelloWorld.java b/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/HelloWorld.java deleted file mode 100644 index 5781f4f2c9..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/HelloWorld.java +++ /dev/null @@ -1,31 +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.itests.dynamic; - -/** - * - * @version $Rev$ $Date$ - */ -public interface HelloWorld { - - String sayHello(String s); - String sayHelloFrom(String s); - -} diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRefTestCase.java b/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRefTestCase.java deleted file mode 100644 index e88e44c7c0..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRefTestCase.java +++ /dev/null @@ -1,29 +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.itests.dynamic; - - -/** - * - * @version $Rev$ $Date$ - */ -public class JavaScriptDynamicRefTestCase extends AbstractHelloWorldTestCase { - // super class does it all getting composite based on this class name -} diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorldTestCase.java b/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorldTestCase.java deleted file mode 100644 index 331d5bcfd4..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorldTestCase.java +++ /dev/null @@ -1,34 +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.itests.dynamic; - - -/** - * - * @version $Rev$ $Date$ - */ -public class JavaScriptHelloWorldTestCase extends AbstractHelloWorldTestCase { - // super class does it all getting composite based on this class name - - public void testHelloFrom() throws Exception { - System.out.println(service.sayHelloFrom("Venkat")); - assertEquals("Hello petra from Tuscany", service.sayHelloFrom("petra")); - } -} diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorldTestCase.java b/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorldTestCase.java deleted file mode 100644 index 93d1949c50..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorldTestCase.java +++ /dev/null @@ -1,29 +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.itests.helloworld; - - -/** - * - * @version $Rev$ $Date$ - */ -public class JavaScripInlineHelloWorldTestCase extends AbstractHelloWorldTestCase { - // super class does it all getting composite based on this class name -} diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRef.composite b/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRef.composite deleted file mode 100644 index 77ba095988..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRef.composite +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorld.composite b/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorld.composite deleted file mode 100644 index 4e71a4a3e6..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorld.composite +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - Tuscany - - - diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworld.js b/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworld.js deleted file mode 100644 index beee72314d..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworld.js +++ /dev/null @@ -1,26 +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. - */ - -function sayHello(s) { - return "Hello " + s; -} - -function sayHelloFrom(s) { - return "Hello " + s + " from " + greeter; -} \ No newline at end of file diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworldProxy.js b/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworldProxy.js deleted file mode 100644 index 69a2f2e639..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworldProxy.js +++ /dev/null @@ -1,22 +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. - */ - -function sayHello(s) { - return delegate.sayHello(s); -} \ No newline at end of file diff --git a/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorld.composite b/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorld.composite deleted file mode 100644 index 7ddf517b96..0000000000 --- a/branches/sca-equinox/modules/implementation-script-runtime/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorld.composite +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - function sayHello(s) { - return "Hello " + s; - } - - - - - diff --git a/branches/sca-equinox/modules/implementation-script/pom.xml b/branches/sca-equinox/modules/implementation-script/pom.xml index 8651295898..61658f9eb9 100644 --- a/branches/sca-equinox/modules/implementation-script/pom.xml +++ b/branches/sca-equinox/modules/implementation-script/pom.xml @@ -31,142 +31,18 @@ Apache Tuscany SCA Script Implementation Model - org.apache.tuscany.sca - tuscany-sca-api + tuscany-assembly-xml 1.4-SNAPSHOT - compile - org.apache.bsf - bsf-all - 3.0-beta2 - - - - org.apache.tuscany.sca - tuscany-interface-wsdl - 1.4-SNAPSHOT - - - - org.apache.ws.commons.axiom - axiom-api - - - xerces - xercesImpl - - - javax.mail - mail - - - commons-logging - commons-logging - - - xml-apis - xml-apis - - - 1.2.5 - - - - org.apache.ws.commons.axiom - axiom-impl - 1.2.5 - runtime - - - - junit + junit junit 4.2 test - - - org.easymock - easymock - 2.2 - test - - - - org.easymock - easymockclassextension - 2.2 - test - - - - org.apache.tuscany.sca - tuscany-implementation-java-runtime - 1.4-SNAPSHOT - test - - - - commons-logging - commons-logging - 1.1 - - - commons-logging - commons-logging - - - javax.servlet - servlet-api - - - - - - - - rhino - js - 1.6R7 - compile - - - org.jruby - jruby-complete - 1.1.3 - compile - - - asm - asm - - - asm - asm-commons - - - jline - jline - - - - - org.python - jython - 2.2 - compile - - - org.codehaus.groovy - groovy-all-minimal - 1.5.4 - compile - - @@ -181,7 +57,7 @@ ${tuscany.version} org.apache.tuscany.sca.implementation.script ${pom.name} - org.apache.tuscany.sca.implementation.script* + org.apache.tuscany.sca.implementation.script diff --git a/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java b/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java index 87820c18ed..9dc8f2aeca 100644 --- a/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java +++ b/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java @@ -18,82 +18,96 @@ */ package org.apache.tuscany.sca.implementation.script; -import java.net.MalformedURLException; -import java.net.URL; +import java.util.ArrayList; +import java.util.List; -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; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; /** * Represents a Script implementation. * * @version $Rev$ $Date$ */ -public class ScriptImplementation { +public class ScriptImplementation implements Implementation { - protected String scriptName; - protected URL scriptURL; - protected String scriptSrc; - protected String scriptLanguage; + private String uri; + private String language; + private List properties = new ArrayList(); + private List references = new ArrayList(); + private List services = new ArrayList(); + private String location; + private boolean unresolved; + + public ScriptImplementation() { + } public String getScript() { - return scriptName; + return uri; } - public void setScript(String scriptName) { - this.scriptName = scriptName; + public void setScript(String uri) { + this.uri = uri; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; } public void setLanguage(String language) { - this.scriptLanguage = language; + this.language = language; } - public void setElementText(String elementText) { - scriptSrc = elementText; + public String getLanguage() { + return language; } - public String getScriptLanguage() { - if (scriptLanguage == null || scriptLanguage.length() < 1) { - int i = scriptName.lastIndexOf('.'); - if (i > 0) { - scriptLanguage = scriptName.substring(i + 1); - } - } - return scriptLanguage; + public ConstrainingType getConstrainingType() { + // The script implementation does not support constrainingTypes + return null; } - 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); - } + public List getProperties() { + return properties; + } - scriptSrc = ResourceHelper.readResource(scriptURL); - } - return scriptSrc; + public List getServices() { + return services; } - 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); - } - } - } + public List getReferences() { + return references; + } + + public String getURI() { + return uri; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + // The script implementation does not support constrainingTypes + } + + public void setURI(String uri) { + this.uri = uri; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + @Override + public String toString() { + return "Script : " + getURI(); } } diff --git a/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationActivator.java b/branches/sca-equinox/modules/implementation-script/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/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 { - - // TODO: seems wrong to need PropertyValueObjectFactory, could it be on Property somehow? - protected PropertyValueObjectFactory propertyFactory; - - public ScriptImplementationActivator(PropertyValueObjectFactory propertyFactory) { - this.propertyFactory = propertyFactory; - } - - public Class 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/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationProcessor.java b/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationProcessor.java new file mode 100644 index 0000000000..38ce384fe2 --- /dev/null +++ b/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationProcessor.java @@ -0,0 +1,166 @@ +/* + * 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 static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import java.io.IOException; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + +/** + * ScriptImplementationProcessor + * + * @version $Rev: $ $Date: $ + */ +public class ScriptImplementationProcessor implements StAXArtifactProcessor { + private static final QName IMPLEMENTATION_SCRIPT = new QName(Constants.SCA10_TUSCANY_NS, "implementation.script"); + + private AssemblyFactory assemblyFactory; + private ContributionFactory contributionFactory; + private Monitor monitor; + + public ScriptImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + contributionFactory = modelFactories.getFactory(ContributionFactory.class); + this.monitor = monitor; + } + + public QName getArtifactType() { + return IMPLEMENTATION_SCRIPT; + } + + public Class getModelType() { + return ScriptImplementation.class; + } + + public ScriptImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + + // Read an element + + // Create and initialize the script implementation model + ScriptImplementation implementation = new ScriptImplementation(); + implementation.setUnresolved(true); + + // Read the script attribute + String script = reader.getAttributeValue(null, "script"); + if (script != null) { + implementation.setScript(script); + } + + // Read the language attribute + String language = reader.getAttributeValue(null, "language"); + if (language != null) { + implementation.setLanguage(language); + } + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && IMPLEMENTATION_SCRIPT.equals(reader.getName())) { + break; + } + } + + return implementation; + } + + public void resolve(ScriptImplementation implementation, ModelResolver resolver) throws ContributionResolveException { + + // Resolve the script location + if (implementation.getScript() != null) { + Artifact artifact = contributionFactory.createArtifact(); + artifact.setURI(implementation.getScript()); + Artifact resolved = resolver.resolveModel(Artifact.class, artifact); + if (resolved.getLocation() != null) { + implementation.setLocation(resolved.getLocation()); + } else { + error("CouldNotResolveScript", resolver, implementation.getScript()); + } + + // Resolve the componentType and add the declared properties, references + // and services to the implementation + String componentTypeURI = implementation.getScript(); + componentTypeURI = componentTypeURI.substring(0, componentTypeURI.lastIndexOf('.')); + componentTypeURI += ".componentType"; + ComponentType componentType = assemblyFactory.createComponentType(); + componentType.setUnresolved(true); + componentType.setURI(componentTypeURI); + componentType = resolver.resolveModel(ComponentType.class, componentType); + if (!componentType.isUnresolved()) { + implementation.getProperties().addAll(componentType.getProperties()); + implementation.getReferences().addAll(componentType.getReferences()); + implementation.getServices().addAll(componentType.getServices()); + } + } + + implementation.setUnresolved(false); + } + + public void write(ScriptImplementation implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write + writer.setPrefix("script", IMPLEMENTATION_SCRIPT.getNamespaceURI()); + writer.writeStartElement(IMPLEMENTATION_SCRIPT.getNamespaceURI(), IMPLEMENTATION_SCRIPT.getLocalPart()); + writer.writeNamespace("script", IMPLEMENTATION_SCRIPT.getNamespaceURI()); + + if (implementation.getScript() != null) { + writer.writeAttribute("script", implementation.getScript()); + } + if (implementation.getLanguage() != null) { + writer.writeAttribute("language", implementation.getLanguage()); + } + + writer.writeEndElement(); + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "impl-widget-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + +} diff --git a/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java b/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java deleted file mode 100644 index 2ccb414be8..0000000000 --- a/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java +++ /dev/null @@ -1,84 +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 javax.script.Invocable; -import javax.script.ScriptEngine; -import javax.script.ScriptException; - -import org.apache.axiom.om.OMElement; -import org.apache.bsf.xml.XMLHelper; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; - -/** - * Perform the actual script invocation - * - * @version $Rev$ $Date$ - */ -public class ScriptInvoker implements Invoker { - - protected ScriptEngine scriptEngine; - protected XMLHelper xmlHelper; - protected Operation operation; - - public ScriptInvoker(ScriptEngine scriptEngine, XMLHelper xmlHelper, Operation operation) { - this.scriptEngine = scriptEngine; - this.xmlHelper = xmlHelper; - this.operation = operation; - } - - protected Object doInvoke(Object[] objects, Operation op) throws ScriptException { - if (xmlHelper != null) { - objects[0] = xmlHelper.toScriptXML((OMElement)objects[0]); - } - - Operation oper = operation; // static setting - if (oper.getName() == null) { // if no static setting - oper = op; // use dynamic setting - } - Object response; - try { - response = ((Invocable)scriptEngine).invokeFunction(oper.getName(), objects); - } catch (ScriptException e) { - throw e; - } catch (Exception e) { - throw new ScriptException(e); - } - - if (xmlHelper != null) { - response = xmlHelper.toOMElement(response); - } - - return response; - } - - public Message invoke(Message msg) { - try { - Object resp = doInvoke((Object[])msg.getBody(), msg.getOperation()); - msg.setBody(resp); - } catch (ScriptException e) { - msg.setFaultBody(e.getCause()); - } - return msg; - } - -} diff --git a/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java b/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java deleted file mode 100644 index 9359590424..0000000000 --- a/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java +++ /dev/null @@ -1,173 +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.io.StringReader; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import javax.script.Invocable; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -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.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.runtime.RuntimeComponent; - -/** - * - * @version $Rev$ $Date$ - */ -public class ScriptInvokerFactory implements InvokerFactory { - - protected ScriptEngine scriptEngine; - protected XMLHelper xmlHelper; - - protected RuntimeComponent rc; - protected ComponentType ct; - protected ScriptImplementation implementation; - protected PropertyValueObjectFactory propertyFactory; - - - /** - * @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; - 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; - } - try { - scriptEngine = getScriptEngineByExtension(implementation.getScriptLanguage()); - if (scriptEngine == null) { - throw new ObjectCreationException("no script engine found for language: " + implementation.getScriptLanguage()); - } - 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 (Property property : ct.getProperties()) { - ObjectFactory propertyValueFactory = propertyFactory.createValueFactory(property); - if ( propertyValueFactory != null) { - scriptEngine.put(property.getName(), propertyValueFactory.getInstance()); - } - } - - scriptEngine.eval(new StringReader(implementation.getScriptSrc())); - - } catch (ScriptException e) { - throw new ObjectCreationException(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); - } - } - } - - /** - * TODO: RuntimeComponent should provide a method like this - */ - @SuppressWarnings("unchecked") - protected Object createReferenceProxy(String name, RuntimeComponent component) { - for (ComponentReference reference : component.getReferences()) { - if (reference.getName().equals(name)) { - Class iface = ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass(); - return component.getComponentContext().getService(iface, name); - } - } - throw new IllegalArgumentException("reference " + name + " not found on component: " + component); - } - - /** - * Hack for now to work around a problem with the JRuby script engine - */ - protected ScriptEngine getScriptEngineByExtension(String scriptExtn) { - if ("rb".equals(scriptExtn)) { - return new TuscanyJRubyScriptEngine(); - } else { - if ("py".equals(scriptExtn)) { - pythonCachedir(); - } - // Allow privileged access to run access classes. Requires RuntimePermission - // for accessClassInPackage.sun.misc. - ScriptEngineManager scriptEngineManager = - AccessController.doPrivileged(new PrivilegedAction() { - public ScriptEngineManager run() { - return new ScriptEngineManager(); - } - }); - return scriptEngineManager.getEngineByExtension(scriptExtn); - } - } - - /** - * 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"); - } - } -} diff --git a/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/engines/TuscanyJRubyScriptEngine.java b/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/engines/TuscanyJRubyScriptEngine.java deleted file mode 100644 index 324246c32b..0000000000 --- a/branches/sca-equinox/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/engines/TuscanyJRubyScriptEngine.java +++ /dev/null @@ -1,697 +0,0 @@ -/* -* Copyright (c) 2006, Sun Microsystems, Inc. -* All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* - Redistributions of source code must retain the above copyright notice, this -* list of conditions and the following disclaimer. -* -* - Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* - Neither the name of the Sun Microsystems, Inc. nor the names of -* contributors may be used to endorse or promote products derived from this -* software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY -* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -* DAMAGE. -*/ -package org.apache.tuscany.sca.implementation.script.engines; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.io.Reader; -import java.io.StringWriter; -import java.io.UnsupportedEncodingException; -import java.io.Writer; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CoderResult; -import java.nio.charset.CodingErrorAction; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import javax.script.AbstractScriptEngine; -import javax.script.Bindings; -import javax.script.Compilable; -import javax.script.CompiledScript; -import javax.script.Invocable; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineFactory; -import javax.script.ScriptException; -import javax.script.SimpleBindings; - -import org.jruby.Ruby; -import org.jruby.RubyException; -import org.jruby.RubyIO; -import org.jruby.RubyObject; -import org.jruby.ast.Node; -import org.jruby.exceptions.RaiseException; -import org.jruby.internal.runtime.GlobalVariable; -import org.jruby.internal.runtime.GlobalVariables; -import org.jruby.internal.runtime.ReadonlyAccessor; -import org.jruby.internal.runtime.ValueAccessor; -import org.jruby.javasupport.Java; -import org.jruby.javasupport.JavaEmbedUtils; -import org.jruby.javasupport.JavaObject; -import org.jruby.javasupport.JavaUtil; -import org.jruby.runtime.Block; -import org.jruby.runtime.IAccessor; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.util.KCode; - -import com.sun.script.jruby.JRubyScriptEngineFactory; - -/** - * This class is a copy of the class com.sun.script.ruby.JRubyScriptEngine with some minor modifications - * to work around problems with Tuscany setting SCA properties and references as global variable in JRuby - * Should only need it temporarily till a new BSF release fixes it. - * - * @version $Rev$ $Date$ - */ -@SuppressWarnings("unchecked") -public class TuscanyJRubyScriptEngine extends AbstractScriptEngine - implements Compilable, Invocable { - - // my factory, may be null - private ScriptEngineFactory factory; - private Ruby runtime; - - public TuscanyJRubyScriptEngine() { - // Allow privileged access to ready properties. Requires PropertyPermission in security - // policy. - String rubyPath = AccessController.doPrivileged(new PrivilegedAction() { - public String run() { - return System.getProperty("com.sun.script.jruby.loadpath"); - } - }); - init(rubyPath); - } - - public TuscanyJRubyScriptEngine(String loadPath) { - init(loadPath); - } - - // my implementation for CompiledScript - private class JRubyCompiledScript extends CompiledScript { - // my compiled code - private Node node; - - JRubyCompiledScript (Node node) { - this.node = node; - } - - public ScriptEngine getEngine() { - return TuscanyJRubyScriptEngine.this; - } - - public Object eval(ScriptContext ctx) throws ScriptException { - return evalNode(node, ctx); - } - } - - // Compilable methods - public CompiledScript compile(String script) - throws ScriptException { - Node node = compileScript(script, context); - return new JRubyCompiledScript(node); - } - - public CompiledScript compile (Reader reader) - throws ScriptException { - Node node = compileScript(reader, context); - return new JRubyCompiledScript(node); - } - - // Invocable methods - public Object invokeFunction(String name, Object... args) - throws ScriptException, NoSuchMethodException { - return invokeImpl(null, name, args, Object.class); - } - - public Object invokeMethod(Object obj, String name, Object... args) - throws ScriptException, NoSuchMethodException { - if (obj == null) { - throw new IllegalArgumentException("script object is null"); - } - return invokeImpl(obj, name, args, Object.class); - } - - public Object getInterface(Object obj, Class clazz) { - if (obj == null) { - throw new IllegalArgumentException("script object is null"); - } - return makeInterface(obj, clazz); - } - - public Object getInterface(Class clazz) { - return makeInterface(null, clazz); - } - - private T makeInterface(Object obj, Class clazz) { - if (clazz == null || !clazz.isInterface()) { - throw new IllegalArgumentException("interface Class expected"); - } - final Object thiz = obj; - return (T) Proxy.newProxyInstance( - clazz.getClassLoader(), - new Class[] { clazz }, - new InvocationHandler() { - public Object invoke(Object proxy, Method m, Object[] args) - throws Throwable { - return invokeImpl(thiz, m.getName(), - args, m.getReturnType()); - } - }); - } - - // ScriptEngine methods - public synchronized Object eval(String str, ScriptContext ctx) - throws ScriptException { - Node node = compileScript(str, ctx); - return evalNode(node, ctx); - } - - public synchronized Object eval(Reader reader, ScriptContext ctx) - throws ScriptException { - Node node = compileScript(reader, ctx); - return evalNode(node, ctx); - } - - public ScriptEngineFactory getFactory() { - synchronized (this) { - if (factory == null) { - factory = new JRubyScriptEngineFactory(); - } - } - return factory; - } - - public Bindings createBindings() { - return new SimpleBindings(); - } - - // package-private methods - void setFactory(ScriptEngineFactory factory) { - this.factory = factory; - } - - // internals only below this point - - private Object rubyToJava(IRubyObject value) { - return rubyToJava(value, Object.class); - } - - private Object rubyToJava(IRubyObject value, Class type) { - return JavaUtil.convertArgument( - runtime, - Java.ruby_to_java(value, value, Block.NULL_BLOCK), - type); - } - - private IRubyObject javaToRuby(Object value) { - if (value instanceof IRubyObject) { - return (IRubyObject) value; - } - IRubyObject result = JavaUtil.convertJavaToRuby(runtime, value); - if (result instanceof JavaObject) { - return runtime.getModule("JavaUtilities").callMethod(runtime.getCurrentContext(), "wrap", result); - } - return result; - } - - private synchronized Node compileScript(String script, ScriptContext ctx) - throws ScriptException { - GlobalVariables oldGlobals = runtime.getGlobalVariables(); - try { - setErrorWriter(ctx.getErrorWriter()); - setGlobalVariables(ctx); - String filename = (String) ctx.getAttribute(ScriptEngine.FILENAME); - if (filename == null) { - filename = ""; - } - return runtime.parseEval(script, filename, null, 0); - } catch (RaiseException e) { - RubyException re = e.getException(); - runtime.printError(re); - throw new ScriptException(e); - } catch (Exception e) { - throw new ScriptException(e); - } finally { - if (oldGlobals != null) { - setGlobalVariables(oldGlobals); - } - } - } - - private synchronized Node compileScript(Reader reader, ScriptContext ctx) - throws ScriptException { - GlobalVariables oldGlobals = runtime.getGlobalVariables(); - try { - setErrorWriter(ctx.getErrorWriter()); - setGlobalVariables(ctx); - String filename = (String) ctx.getAttribute(ScriptEngine.FILENAME); - if (filename == null) { - filename = ""; - String script = getRubyScript(reader); - return runtime.parseEval(script, filename, null, 0); - } - InputStream inputStream = getRubyReader(filename); - return runtime.parseFile(inputStream, filename, null); - } catch (RaiseException e) { - RubyException re = e.getException(); - runtime.printError(re); - throw new ScriptException(e); - } catch (Exception exp) { - throw new ScriptException(exp); - } finally { - if (oldGlobals != null) { - setGlobalVariables(oldGlobals); - } - } - } - - private String getRubyScript(Reader reader) throws IOException { - StringBuffer sb = new StringBuffer(); - char[] cbuf; - while (true) { - cbuf = new char[8*1024]; - int chars = reader.read(cbuf, 0, cbuf.length); - if (chars < 0) { - break; - } - sb.append(cbuf, 0, chars); - } - cbuf = null; - return (new String(sb)).trim(); - } - - private InputStream getRubyReader(String filename) throws FileNotFoundException { - File file = new File(filename); - return new FileInputStream(file); - } - - private void setGlobalVariables(final ScriptContext ctx) { - ctx.setAttribute("context", ctx, ScriptContext.ENGINE_SCOPE); - setGlobalVariables(new GlobalVariables(runtime) { - GlobalVariables parent = runtime.getGlobalVariables(); - - @Override - public void define(String name, IAccessor accessor) { - assert name != null; - assert accessor != null; - assert name.startsWith("$"); - synchronized (ctx) { - Bindings engineScope = ctx.getBindings(ScriptContext.ENGINE_SCOPE); - engineScope.put(name, new GlobalVariable(accessor)); - } - } - - @Override - public void defineReadonly(String name, IAccessor accessor) { - assert name != null; - assert accessor != null; - assert name.startsWith("$"); - synchronized (ctx) { - Bindings engineScope = ctx.getBindings(ScriptContext.ENGINE_SCOPE); - engineScope.put(name, new GlobalVariable(new - ReadonlyAccessor(name, accessor))); - } - } - - @Override - public boolean isDefined(String name) { - assert name != null; - assert name.startsWith("$"); - synchronized (ctx) { - String modifiedName = name.substring(1); - boolean defined = ctx.getAttributesScope(modifiedName) != -1; - return defined ? true : parent.isDefined(name); - } - } - - @Override - public void alias(String name, String oldName) { - assert name != null; - assert oldName != null; - assert name.startsWith("$"); - assert oldName.startsWith("$"); - - if (runtime.getSafeLevel() >= 4) { - throw runtime.newSecurityError("Insecure: can't alias global variable"); - } - - synchronized (ctx) { - int scope = ctx.getAttributesScope(name); - if (scope == -1) { - scope = ScriptContext.ENGINE_SCOPE; - } - - IRubyObject value = get(oldName); - ctx.setAttribute(name, rubyToJava(value), scope); - } - } - - @Override - public IRubyObject get(String name) { - assert name != null; - assert name.startsWith("$"); - - synchronized (ctx) { - // skip '$' and try - String modifiedName = name.substring(1); - int scope = ctx.getAttributesScope(modifiedName); - if (scope == -1) { - return parent.get(name); - } - - Object obj = ctx.getAttribute(modifiedName, scope); - if (obj instanceof IAccessor) { - return ((IAccessor)obj).getValue(); - } else { - return javaToRuby(obj); - } - } - } - - @Override - public IRubyObject set(String name, IRubyObject value) { - assert name != null; - assert name.startsWith("$"); - - if (runtime.getSafeLevel() >= 4) { - throw runtime.newSecurityError("Insecure: can't change global variable value"); - } - - synchronized (ctx) { - // skip '$' and try - String modifiedName = name.substring(1); - int scope = ctx.getAttributesScope(modifiedName); - if (scope == -1) { - scope = ScriptContext.ENGINE_SCOPE; - } - IRubyObject oldValue = get(name); - Object obj = ctx.getAttribute(modifiedName, scope); - if (obj instanceof IAccessor) { - ((IAccessor)obj).setValue(value); - } else { - ctx.setAttribute(modifiedName, rubyToJava(value), scope); - if ("KCODE".equals(modifiedName)) { - setKCode((String)rubyToJava(value)); - } else if ("stdout".equals(modifiedName)) { - equalOutputs((RubyObject)value); - } - } - return oldValue; - } - } - - @Override - public Set getNames() { - HashSet set = new HashSet(); - synchronized (ctx) { - for (Object scope : ctx.getScopes()) { - Bindings b = ctx.getBindings((Integer)scope); - if (b != null) { - for (Object key: b.keySet()) { - set.add(key); - } - } - } - } - for (Iterator names = parent.getNames().iterator(); names.hasNext();) { - set.add(names.next()); - } - return Collections.unmodifiableSet(set); - } - - @Override - public IRubyObject getDefaultSeparator() { - return parent.getDefaultSeparator(); - } - }); - } - - private void setGlobalVariables(GlobalVariables globals) { - runtime.setGlobalVariables(globals); - } - - private synchronized Object evalNode(Node node, ScriptContext ctx) - throws ScriptException { - GlobalVariables oldGlobals = runtime.getGlobalVariables(); - try { - setWriterOutputStream(ctx.getWriter()); - setErrorWriter(ctx.getErrorWriter()); - setGlobalVariables(ctx); - return rubyToJava(runtime.runNormally(node, false)); - } catch (Exception exp) { - throw new ScriptException(exp); - } finally { - try { - JavaEmbedUtils.terminate(runtime); - } catch (RaiseException e) { - RubyException re = e.getException(); - runtime.printError(re); - if (!runtime.fastGetClass("SystemExit").isInstance(re)) { - throw new ScriptException(e); - } - } finally { - if (oldGlobals != null) { - setGlobalVariables(oldGlobals); - } - } - } - } - - private void init(final String loadPath) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - runtime = Ruby.newInstance(); - IAccessor d = new ValueAccessor(runtime.newString("