Author: antelder
Date: Mon Sep 11 05:35:56 2006
New Revision: 442197

URL: http://svn.apache.org/viewvc?view=rev&rev=442197
Log:
Script container using BSF to try out the easy container extension

Added:
    incubator/tuscany/sandbox/ant/container.script/
    incubator/tuscany/sandbox/ant/container.script/NOTICE.txt   (with props)
    incubator/tuscany/sandbox/ant/container.script/pom.xml   (with props)
    incubator/tuscany/sandbox/ant/container.script/src/
    incubator/tuscany/sandbox/ant/container.script/src/main/
    incubator/tuscany/sandbox/ant/container.script/src/main/java/
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/
    incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/
    
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/
    
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/
    
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/
    
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
   (with props)
    
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java
   (with props)
    
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java
   (with props)
    incubator/tuscany/sandbox/ant/container.script/src/main/resources/
    incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/
    
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/
    
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/default.scdl
   (with props)
    
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/script.system.scdl
   (with props)
    incubator/tuscany/sandbox/ant/container.script/src/test/
    incubator/tuscany/sandbox/ant/container.script/src/test/java/
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/
    incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/
    
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/
    
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/
    
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/
    
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java
   (with props)
    
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java
   (with props)
    
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java
   (with props)
    
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/mock/
    
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java
   (with props)
    incubator/tuscany/sandbox/ant/container.script/src/test/resources/
    incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/
    
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/
    
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/
    
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/
    
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/
    
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.componentType
    
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.mock

Added: incubator/tuscany/sandbox/ant/container.script/NOTICE.txt
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/NOTICE.txt?view=auto&rev=442197
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/NOTICE.txt (added)
+++ incubator/tuscany/sandbox/ant/container.script/NOTICE.txt Mon Sep 11 
05:35:56 2006
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the 
ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+

Propchange: incubator/tuscany/sandbox/ant/container.script/NOTICE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/tuscany/sandbox/ant/container.script/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/pom.xml?view=auto&rev=442197
==============================================================================
--- incubator/tuscany/sandbox/ant/container.script/pom.xml (added)
+++ incubator/tuscany/sandbox/ant/container.script/pom.xml Mon Sep 11 05:35:56 
2006
@@ -0,0 +1,85 @@
+<?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.containers</groupId>
+        <artifactId>containers</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>tuscany-script</artifactId>
+    <name>Apache Tuscany Script Container</name>
+    <description>Apache Tuscany Script Container using BSF</description>
+
+    <repositories>
+       <repository>
+          <id>ant</id>
+          <url>http://people.apache.org/~antelder/maven2</url>
+          <snapshots>
+             <enabled>true</enabled>
+          </snapshots>
+       </repository>
+    </repositories>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.tuscany.containers</groupId>
+            <artifactId>easy-container</artifactId>
+            <version>${sca.version}</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>bsf</groupId>
+            <artifactId>bsf</artifactId>
+            <version>SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <version>1.1</version>
+            <scope>runtime</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany</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>
+
+    </dependencies>
+
+</project>

Propchange: incubator/tuscany/sandbox/ant/container.script/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/ant/container.script/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java?view=auto&rev=442197
==============================================================================
--- 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
 (added)
+++ 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
 Mon Sep 11 05:35:56 2006
@@ -0,0 +1,80 @@
+/*
+ * 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.script;
+
+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.setScriptInstanceFactory(instanceFactory);
+        
+        registry.loadComponentType(parent, implementation, deploymentContext);
+
+        return implementation;
+    }
+}

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptImplementationLoader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java?view=auto&rev=442197
==============================================================================
--- 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java
 (added)
+++ 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java
 Mon Sep 11 05:35:56 2006
@@ -0,0 +1,52 @@
+/*
+ * 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.script;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.bsf.BSFEngine;
+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 BSFEngine bsfEngine;
+
+    protected Object clazz;
+
+    public ScriptInstance(BSFEngine bsfEngine, Object clazz) {
+        this.bsfEngine = bsfEngine;
+        this.clazz = clazz;
+    }
+
+    public Object invokeTarget(String operationName, Object[] args) throws 
InvocationTargetException {
+        try {
+
+            return bsfEngine.call(clazz, operationName, args);
+
+        } catch (Exception e) {
+            throw new InvocationTargetException(e);
+        }
+    }
+
+}

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstance.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java?view=auto&rev=442197
==============================================================================
--- 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java
 (added)
+++ 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java
 Mon Sep 11 05:35:56 2006
@@ -0,0 +1,80 @@
+/*
+ * 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.script;
+
+import java.util.Map;
+
+import org.apache.bsf.BSFEngine;
+import org.apache.bsf.BSFException;
+import org.apache.bsf.BSFManager;
+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>{
+
+    public ScriptInstanceFactory(String arg0, String arg1, String arg2, 
ClassLoader arg3) {
+        super(arg0, arg1, arg2, arg3);
+    }
+
+    /**
+     * 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(Map<String, Object> context) {
+        try {
+
+            //TODO: this uses a new manager and recompiles the scrip each 
time, may be able to optimize
+            
+            BSFManager bsfManager = new BSFManager();
+            bsfManager.setClassLoader(getClass().getClassLoader());
+
+            // register any context objects (SCA properties and references)
+            for (String beanName : context.keySet()) {
+                bsfManager.registerBean(beanName, context.get(beanName));
+            }
+
+            String scriptLanguage = BSFManager.getLangFromFilename(scriptName);
+            BSFEngine bsfEngine = 
bsfManager.loadScriptingEngine(scriptLanguage);
+            bsfEngine.exec(scriptName, 0, 0, scriptSource);
+
+            // if there's a className then get the class object
+            Object clazz = null;
+            if (className != null) {
+                // special case for Ruby which requires a .new call
+                if ("ruby".equals(scriptLanguage)) {
+                    clazz = bsfEngine.eval(null, 1, 1, className + ".new");
+                } else {
+                    clazz = bsfEngine.call(null, className, null);
+                }
+            }
+
+            return new ScriptInstance(bsfEngine, clazz);
+
+        } catch (BSFException e) {
+            throw new ObjectCreationException();
+        }
+    }
+
+}

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/default.scdl
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/default.scdl?view=auto&rev=442197
==============================================================================
--- 
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/default.scdl
 (added)
+++ 
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/default.scdl
 Mon Sep 11 05:35:56 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.script.ScriptImplementation">
+
+    <component name="script.implementationLoader">
+        <system:implementation.system 
class="org.apache.tuscany.container.script.ScriptImplementationLoader"/>
+    </component>
+
+    <component name="script.componentTypeLoader">
+        <system:implementation.system 
class="org.apache.tuscany.container.easy.EasyComponentTypeLoader"/>
+    </component>
+
+    <component name="script.componentBuilder">
+        <system:implementation.system 
class="org.apache.tuscany.container.easy.EasyComponentBuilder"/>
+    </component>
+    
+</composite>

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/default.scdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/default.scdl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/script.system.scdl
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/script.system.scdl?view=auto&rev=442197
==============================================================================
--- 
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/script.system.scdl
 (added)
+++ 
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/script.system.scdl
 Mon Sep 11 05:35:56 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.script.ScriptImplementation">
+
+    <component name="script.implementationLoader">
+        <system:implementation.system 
class="org.apache.tuscany.container.script.ScriptImplementationLoader"/>
+    </component>
+
+    <component name="script.componentTypeLoader">
+        <system:implementation.system 
class="org.apache.tuscany.container.easy.EasyComponentTypeLoader"/>
+    </component>
+
+    <component name="script.componentBuilder">
+        <system:implementation.system 
class="org.apache.tuscany.container.easy.EasyComponentBuilder"/>
+    </component>
+    
+</composite>

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/script.system.scdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/main/resources/META-INF/sca/script.system.scdl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java?view=auto&rev=442197
==============================================================================
--- 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java
 (added)
+++ 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java
 Mon Sep 11 05:35:56 2006
@@ -0,0 +1,132 @@
+/*
+ * 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.script;
+
+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.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);
+    }
+}

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java?view=auto&rev=442197
==============================================================================
--- 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java
 (added)
+++ 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java
 Mon Sep 11 05:35:56 2006
@@ -0,0 +1,69 @@
+package org.apache.tuscany.container.script;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.bsf.BSFManager;
+import org.apache.tuscany.container.script.mock.MockBSFEngine;
+import org.apache.tuscany.spi.ObjectCreationException;
+
+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(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(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(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(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());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+}

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java?view=auto&rev=442197
==============================================================================
--- 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java
 (added)
+++ 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java
 Mon Sep 11 05:35:56 2006
@@ -0,0 +1,30 @@
+package org.apache.tuscany.container.script;
+
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.mock.MockBSFEngine;
+
+public class ScriptInstanceTestCase extends TestCase {
+
+    private ScriptInstance instance;
+
+    public void testInvokeTarget() throws InvocationTargetException {
+        assertEquals("hello:", instance.invokeTarget("hello", null));
+    }
+
+    public void testInvokeTargetException() throws InvocationTargetException {
+        try {
+            instance.invokeTarget("bang", null);
+            fail();
+        } catch (InvocationTargetException e) {
+            // expected
+        }
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        this.instance = new ScriptInstance(new MockBSFEngine(), null);
+    }
+}

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java?view=auto&rev=442197
==============================================================================
--- 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java
 (added)
+++ 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java
 Mon Sep 11 05:35:56 2006
@@ -0,0 +1,27 @@
+package org.apache.tuscany.container.script.mock;
+
+import org.apache.bsf.BSFException;
+import org.apache.bsf.util.BSFEngineImpl;
+
+public class MockBSFEngine extends BSFEngineImpl {
+
+    public Object call(Object object, String name, Object[] args) throws 
BSFException {
+        if ("bang".equals(name)) {
+            throw new RuntimeException(name);
+        }
+        
+        String resp = name + ":";
+        if (args != null) {
+            for (Object o : args) {
+                resp += " " + String.valueOf(o);
+            }
+        }
+        return resp;
+    }
+
+    public Object eval(String source, int lineNo, int columnNo, Object expr) 
throws BSFException {
+        // not used for the mock tests
+        return null;
+    }
+
+}

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.componentType
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.componentType?view=auto&rev=442197
==============================================================================
--- 
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.componentType
 (added)
+++ 
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.componentType
 Mon Sep 11 05:35:56 2006
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="ASCII"?>
+
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
+
+    <service name="HelloWorldService">
+        <interface.java interface="not.used"/>
+    </service>
+
+</componentType>

Added: 
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.mock
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.mock?view=auto&rev=442197
==============================================================================
--- 
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.mock
 (added)
+++ 
incubator/tuscany/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.mock
 Mon Sep 11 05:35:56 2006
@@ -0,0 +1 @@
+hello
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to