tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r454317 - in /incubator/tuscany/sandbox/ant/container.jsr223: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/container/ src/main/java/org/apac...
Date Mon, 09 Oct 2006 09:28:20 GMT
Author: antelder
Date: Mon Oct  9 02:28:18 2006
New Revision: 454317

URL: http://svn.apache.org/viewvc?view=rev&rev=454317
Log:
Playing about with JSR-223

Added:
    incubator/tuscany/sandbox/ant/container.jsr223/pom.xml
    incubator/tuscany/sandbox/ant/container.jsr223/src/   (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/   (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/   (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/   (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/   (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/   (with
props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/
  (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/
  (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptImplementationLoader.java
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptInstance.java
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptInstanceFactory.java
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/   (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/   (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/   (with
props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/default.scdl
    incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/   (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/   (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/   (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/   (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/   (with
props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/
  (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/
  (with props)
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/FunctionTestCase.java
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptImplementationLoaderTestCase.java
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptInstanceFactoryTestCase.java
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptInstanceTestCase.java
    incubator/tuscany/sandbox/ant/container.jsr223/src/test/resources/   (with props)
Modified:
    incubator/tuscany/sandbox/ant/container.jsr223/   (props changed)

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Added: incubator/tuscany/sandbox/ant/container.jsr223/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.jsr223/pom.xml?view=auto&rev=454317
==============================================================================
--- incubator/tuscany/sandbox/ant/container.jsr223/pom.xml (added)
+++ incubator/tuscany/sandbox/ant/container.jsr223/pom.xml Mon Oct  9 02:28:18 2006
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<project>
+
+    <parent>
+        <groupId>org.apache.tuscany.sca.services.containers</groupId>
+        <artifactId>parent</artifactId>
+        <version>1.0-incubator-M2-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>container-jsr223</artifactId>
+    <name>Apache Tuscany Script Container using JSR-223</name>
+    <description>Apache Tuscany Script Container using JSR-223</description>
+
+    <repositories>
+       <repository>
+          <!-- Hmm, there must be a better way to get this -->
+          <id>jsr223</id>
+          <url>http://dist.codehaus.org/mule/dependencies/maven2</url>
+       </repository>
+    </repositories>
+
+      <dependencies>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca.services.containers</groupId>
+            <artifactId>easy-container</artifactId>
+            <version>${sca.version}</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+           <groupId>script</groupId>
+           <artifactId>jsr223</artifactId>
+           <version>1.0</version>
+           <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>test</artifactId>
+            <version>${sca.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymockclassextension</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>rhino</groupId>
+            <artifactId>js</artifactId>
+            <version>1.6R2</version>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+</project>

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/main/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Added: incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptImplementationLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptImplementationLoader.java?view=auto&rev=454317
==============================================================================
--- incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptImplementationLoader.java
(added)
+++ incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptImplementationLoader.java
Mon Oct  9 02:28:18 2006
@@ -0,0 +1,81 @@
+/*
+ * 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.container.jsr223;
+
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.container.easy.EasyImplementation;
+import org.apache.tuscany.container.easy.EasyImplementationLoader;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.osoa.sca.annotations.Constructor;
+
+/**
+ * Loader for handling implementation.script elements.
+ * 
+ * <implementation.script script="path/foo.py" class="myclass">
+ *  
+ */
+public class ScriptImplementationLoader extends EasyImplementationLoader {
+
+    private static final QName IMPLEMENTATION_SCRIPT = new QName(XML_NAMESPACE_1_0, "implementation.script");
+
+    @Constructor( { "registry" })
+    public ScriptImplementationLoader(@Autowire LoaderRegistry registry) {
+        super(registry);
+    }
+
+    public QName getXMLType() {
+        return IMPLEMENTATION_SCRIPT;
+    }
+
+    @Override
+    public EasyImplementation load(CompositeComponent parent, XMLStreamReader reader, DeploymentContext
deploymentContext) throws XMLStreamException, LoaderException {
+        String scriptName = reader.getAttributeValue(null, "script");
+        if (scriptName == null) {
+            throw new MissingResourceException("implementation element has no 'script' attribute");
+        }
+
+        String className = reader.getAttributeValue(null, "class");
+
+        LoaderUtil.skipToEndElement(reader);
+
+        ClassLoader cl = deploymentContext.getClassLoader();
+        String scriptSource = loadSource(cl, scriptName);
+
+        ScriptInstanceFactory instanceFactory = new ScriptInstanceFactory(scriptName, className,
scriptSource, cl);
+
+        EasyImplementation implementation = new EasyImplementation();
+        implementation.setResourceName(scriptName);
+        implementation.setScriptInstanceFactory(instanceFactory);
+        
+        registry.loadComponentType(parent, implementation, deploymentContext);
+
+        return implementation;
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptInstance.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptInstance.java?view=auto&rev=454317
==============================================================================
--- incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptInstance.java
(added)
+++ incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptInstance.java
Mon Oct  9 02:28:18 2006
@@ -0,0 +1,50 @@
+/*
+ * 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.container.jsr223;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.script.Invocable;
+
+import org.apache.tuscany.container.easy.EasyInstance;
+
+/**
+ * An invokable instance of a script
+ * 
+ * Basically just a wrapper around a BSF engine with an optional script class object.
+ */
+public class ScriptInstance implements EasyInstance {
+
+    protected Invocable invocableEngine;
+
+    public ScriptInstance(Invocable invocableEngine) {
+        this.invocableEngine = invocableEngine;
+    }
+
+    public Object invokeTarget(String operationName, Object[] args) throws InvocationTargetException
{
+        try {
+
+            return invocableEngine.call(operationName, args);
+
+        } catch (Exception e) {
+            throw new InvocationTargetException(e);
+        }
+    }
+
+}

Added: incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptInstanceFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptInstanceFactory.java?view=auto&rev=454317
==============================================================================
--- incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptInstanceFactory.java
(added)
+++ incubator/tuscany/sandbox/ant/container.jsr223/src/main/java/org/apache/tuscany/container/jsr223/ScriptInstanceFactory.java
Mon Oct  9 02:28:18 2006
@@ -0,0 +1,75 @@
+/*
+ * 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.container.jsr223;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.script.Invocable;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
+import org.apache.tuscany.container.easy.EasyInstanceFactory;
+import org.apache.tuscany.spi.ObjectCreationException;
+
+/**
+ * ScriptInstanceFactory creates ScriptInstances for a script
+ */
+public class ScriptInstanceFactory extends EasyInstanceFactory<ScriptInstance>{
+
+    private String className;
+
+    private String scriptSource;
+
+    public ScriptInstanceFactory(String resourceName, String className, String scriptSource,
ClassLoader classLoader) {
+        super(resourceName, classLoader);
+        this.className = className;
+        this.scriptSource = scriptSource;
+    }
+
+    /**
+     * Create a new invokeable instance of the script
+     * 
+     * @param context
+     *            objects to add to scope of the script instance
+     * @return a RhinoScriptInstance
+     */
+    public ScriptInstance createInstance(List<Class> services, Map<String, Object>
context) {
+        try {
+
+            ScriptEngineManager engineMgr = new ScriptEngineManager();
+            ScriptEngine engine = engineMgr.getEngineByExtension(getScriptExtension());
+            engine.eval(scriptSource);
+            return new ScriptInstance((Invocable) engine);
+            
+        } catch (ScriptException e) {
+            throw new ObjectCreationException(e);
+        }
+    }
+
+    protected String getScriptExtension() {
+        int lastDot = resourceName.lastIndexOf('.');
+        if (lastDot == -1) {
+            return null;
+        }
+        return resourceName.substring(lastDot+1);
+    }
+
+}

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Added: incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/default.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/default.scdl?view=auto&rev=454317
==============================================================================
--- incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/default.scdl
(added)
+++ incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/default.scdl
Mon Oct  9 02:28:18 2006
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<!--
+    JavaScript configuration for the launcher environment.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+           xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+
+           name="org.apache.tuscany.container.jsr223.ScriptImplementation">
+
+    <component name="jsr223.implementationLoader">
+        <system:implementation.system class="org.apache.tuscany.container.jsr223.ScriptImplementationLoader"/>
+    </component>
+
+    <component name="jsr223.componentTypeLoader">
+        <system:implementation.system class="org.apache.tuscany.container.easy.EasyComponentTypeLoader"/>
+    </component>
+
+    <component name="jsr223.componentBuilder">
+        <system:implementation.system class="org.apache.tuscany.container.easy.EasyComponentBuilder"/>
+    </component>
+    
+</composite>

Added: incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl?view=auto&rev=454317
==============================================================================
--- incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl
(added)
+++ incubator/tuscany/sandbox/ant/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl
Mon Oct  9 02:28:18 2006
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<!--
+    JavaScript configuration for the launcher environment.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+           xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+
+           name="org.apache.tuscany.container.jsr223.ScriptImplementation">
+
+    <component name="jsr223.implementationLoader">
+        <system:implementation.system class="org.apache.tuscany.container.jsr223.ScriptImplementationLoader"/>
+    </component>
+
+    <component name="jsr223.componentTypeLoader">
+        <system:implementation.system class="org.apache.tuscany.container.easy.EasyComponentTypeLoader"/>
+    </component>
+
+    <component name="jsr223.componentBuilder">
+        <system:implementation.system class="org.apache.tuscany.container.easy.EasyComponentBuilder"/>
+    </component>
+    
+</composite>

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Added: incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/FunctionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/FunctionTestCase.java?view=auto&rev=454317
==============================================================================
--- incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/FunctionTestCase.java
(added)
+++ incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/FunctionTestCase.java
Mon Oct  9 02:28:18 2006
@@ -0,0 +1,39 @@
+/*
+ * 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.container.jsr223;
+
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.TestCase;
+
+public class FunctionTestCase extends TestCase {
+
+    public void testBasicInvoke() {
+        String src = "function foo(s) { return 'foo ' + s; }";
+        ScriptInstanceFactory factory = new ScriptInstanceFactory("test.js", null, src, null);
+        ScriptInstance inst = factory.createInstance(null, null);
+        Object o;
+        try {
+            o = inst.invokeTarget("foo", new Object[] { "petra" });
+        } catch (InvocationTargetException e) {
+            throw new RuntimeException(e);
+        }
+        assertEquals("foo petra", o);
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptImplementationLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptImplementationLoaderTestCase.java?view=auto&rev=454317
==============================================================================
--- incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptImplementationLoaderTestCase.java
(added)
+++ incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptImplementationLoaderTestCase.java
Mon Oct  9 02:28:18 2006
@@ -0,0 +1,133 @@
+/*
+ * 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.container.jsr223;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.classextension.EasyMock.createMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.jsr223.ScriptImplementationLoader;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+
+/**
+ * 
+ */
+public class ScriptImplementationLoaderTestCase extends TestCase {
+    private CompositeComponent parent;
+
+    private XMLStreamReader reader;
+
+    private DeploymentContext deploymentContext;
+
+    private ClassLoader classLoader;
+
+    private LoaderRegistry registry;
+
+    private ScriptImplementationLoader loader;
+
+    public void testLoadNoScriptAttribute() throws LoaderException, XMLStreamException {
+        expect(reader.getAttributeValue(null, "script")).andReturn(null);
+        replay(reader);
+        replay(deploymentContext);
+
+        try {
+            loader.load(parent, reader, deploymentContext);
+            fail();
+        } catch (MissingResourceException e) {
+            // ok
+        }
+        verify(reader);
+        verify(deploymentContext);
+    }
+
+    public void testLoad() throws LoaderException, XMLStreamException {
+        expect(reader.getAttributeValue(null, "script")).andReturn("foo.mock");
+        expect(reader.getAttributeValue(null, "class")).andReturn(null);
+        expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+        expect(deploymentContext.getClassLoader()).andReturn(classLoader);
+
+        replay(reader);
+        replay(deploymentContext);
+
+        ScriptImplementationLoader mockLoader = new ScriptImplementationLoader(registry)
{
+            protected String loadSource(ClassLoader cl, String resource) throws LoaderException
{
+                assertSame(classLoader, cl);
+                assertEquals("foo.mock", resource);
+                return "bar";
+            }
+        };
+        mockLoader.load(parent, reader, deploymentContext);
+        verify(reader);
+        verify(deploymentContext);
+    }
+
+    public void testLoadNoScriptPresent() throws LoaderException, XMLStreamException {
+        expect(reader.getAttributeValue(null, "script")).andReturn("foo.py");
+        expect(reader.getAttributeValue(null, "class")).andReturn(null);
+        expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+        expect(deploymentContext.getClassLoader()).andReturn(classLoader);
+
+        replay(reader);
+        replay(deploymentContext);
+
+        ScriptImplementationLoader mockLoader = new ScriptImplementationLoader(registry)
{
+            protected String loadSource(ClassLoader cl, String resource) throws LoaderException
{
+                assertSame(classLoader, cl);
+                assertEquals("foo.py", resource);
+                throw new MissingResourceException(resource);
+            }
+        };
+        try {
+            mockLoader.load(parent, reader, deploymentContext);
+            fail();
+        } catch (MissingResourceException e) {
+            assertEquals("foo.py", e.getMessage());
+        }
+        verify(reader);
+        verify(deploymentContext);
+    }
+
+    public void testGetXMLType() throws LoaderException {
+        assertEquals(XML_NAMESPACE_1_0, loader.getXMLType().getNamespaceURI());
+        assertEquals("implementation.script", loader.getXMLType().getLocalPart());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        registry = createMock(LoaderRegistry.class);
+        loader = new ScriptImplementationLoader(registry);
+
+        parent = createMock(CompositeComponent.class);
+        reader = createMock(XMLStreamReader.class);
+        deploymentContext = createMock(DeploymentContext.class);
+        classLoader = createMock(ClassLoader.class);
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptInstanceFactoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptInstanceFactoryTestCase.java?view=auto&rev=454317
==============================================================================
--- incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptInstanceFactoryTestCase.java
(added)
+++ incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptInstanceFactoryTestCase.java
Mon Oct  9 02:28:18 2006
@@ -0,0 +1,91 @@
+/*
+ * 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.container.jsr223;
+
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.TestCase;
+
+public class ScriptInstanceFactoryTestCase extends TestCase {
+
+//    public void testCreateInstance() throws InvocationTargetException {
+//        BSFManager.registerScriptingEngine("mock", MockBSFEngine.class.getName(), new String[]
{"mock"});
+//        ScriptInstanceFactory factory = new ScriptInstanceFactory("foo.mock", "bar", "baz",
getClass().getClassLoader());
+//        Map<String, Object> context = new HashMap<String, Object>();
+//        context.put("foo", "bar");
+//        ScriptInstance instance = factory.createInstance(null, context);
+//        assertNotNull(instance);
+//        assertNotNull(instance.bsfEngine);
+////        assertNotNull(instance.clazz);
+//    }
+//
+//    public void testCreateInstanceNoClass() throws InvocationTargetException {
+//        BSFManager.registerScriptingEngine("mock", MockBSFEngine.class.getName(), new String[]
{"mock"});
+//        ScriptInstanceFactory factory = new ScriptInstanceFactory("foo.mock", null, "baz",
getClass().getClassLoader());
+//        Map<String, Object> context = new HashMap<String, Object>();
+//        context.put("foo", "bar");
+//        ScriptInstance instance = factory.createInstance(null, context);
+//        assertNotNull(instance);
+//        assertNotNull(instance.bsfEngine);
+//    }
+//
+//    public void testCreateInstanceRuby() throws InvocationTargetException {
+//        BSFManager.registerScriptingEngine("ruby", MockBSFEngine.class.getName(), new String[]
{"mock"});
+//        ScriptInstanceFactory factory = new ScriptInstanceFactory("foo.mock", "bar", "baz",
getClass().getClassLoader());
+//        Map<String, Object> context = new HashMap<String, Object>();
+//        context.put("foo", "bar");
+//        ScriptInstance instance = factory.createInstance(null, context);
+//        assertNotNull(instance);
+//        assertNotNull(instance.bsfEngine);
+////        assertNotNull(instance.clazz);
+//    }
+//
+//    public void testBadCreateInstance() throws InvocationTargetException {
+//        ScriptInstanceFactory factory = new ScriptInstanceFactory("foo", "bar", "baz",
getClass().getClassLoader());
+//        Map<String, Object> context = new HashMap<String, Object>();
+//        try {
+//            factory.createInstance(null, context);
+//            fail();
+//        } catch (ObjectCreationException e) {
+//            // expected
+//        }
+//    }
+//
+    public void testGetters() throws InvocationTargetException {
+        ScriptInstanceFactory factory = new ScriptInstanceFactory("foo", "bar", "baz", getClass().getClassLoader());
+//        assertEquals("foo", factory.getScriptName());
+//        assertEquals("bar", factory.getClassName());
+//        assertEquals("baz", factory.getScriptSource());
+        assertEquals(getClass().getClassLoader(), factory.getClassLoader());
+    }
+
+    public void testGetScriptExtension() throws InvocationTargetException {
+        ScriptInstanceFactory factory = new ScriptInstanceFactory("x.js", null, null, null);
+        assertEquals("js", factory.getScriptExtension());
+    }
+
+    public void testNullGetScriptExtension() throws InvocationTargetException {
+        ScriptInstanceFactory factory = new ScriptInstanceFactory("x", null, null, null);
+        assertEquals(null, factory.getScriptExtension());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+}

Added: incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptInstanceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptInstanceTestCase.java?view=auto&rev=454317
==============================================================================
--- incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptInstanceTestCase.java
(added)
+++ incubator/tuscany/sandbox/ant/container.jsr223/src/test/java/org/apache/tuscany/container/jsr223/ScriptInstanceTestCase.java
Mon Oct  9 02:28:18 2006
@@ -0,0 +1,65 @@
+/*
+ * 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.container.jsr223;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.classextension.EasyMock.createMock;
+import static org.easymock.classextension.EasyMock.replay;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.script.Invocable;
+import javax.script.ScriptException;
+
+import junit.framework.TestCase;
+
+import org.easymock.IAnswer;
+
+public class ScriptInstanceTestCase extends TestCase {
+
+    public void testInvokeTarget() throws InvocationTargetException, ScriptException, NoSuchMethodException
{
+        Invocable invocable = createMock(Invocable.class);
+        expect(invocable.call("foo", null)).andReturn("foo petra");
+        replay(invocable);
+        ScriptInstance instance = new ScriptInstance(invocable);
+        assertEquals("foo petra", instance.invokeTarget("foo", null));
+    }
+
+    public void testInvokeTargetException() throws InvocationTargetException, ScriptException,
NoSuchMethodException {
+        Invocable invocable = createMock(Invocable.class);
+        expect(invocable.call("foo", null)).andStubAnswer(new IAnswer<Object>() {
+            public Object answer() throws Throwable {
+                throw new RuntimeException("bang");
+            }
+        });
+        replay(invocable);
+        ScriptInstance instance = new ScriptInstance(invocable);
+        try {
+            instance.invokeTarget("foo", null);
+            fail();
+        } catch (InvocationTargetException e) {
+            assertEquals("bang", e.getCause().getMessage());
+        }
+
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+}

Propchange: incubator/tuscany/sandbox/ant/container.jsr223/src/test/resources/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct  9 02:28:18 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+



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


Mime
View raw message