You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2007/03/16 21:12:05 UTC
svn commit: r519121 - in
/incubator/tuscany/java/sca/extensions/script/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/extension/ src/mai...
Author: antelder
Date: Fri Mar 16 13:12:01 2007
New Revision: 519121
URL: http://svn.apache.org/viewvc?view=rev&rev=519121
Log:
Copy script container from brn, start getting working on trunk code, and upgrade to use BSF JSR-223 impl
Added:
incubator/tuscany/java/sca/extensions/script/container.jsr223/ (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/LICENSE.txt
- copied unchanged from r519117, incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/LICENSE.txt
incubator/tuscany/java/sca/extensions/script/container.jsr223/NOTICE.txt
- copied unchanged from r519117, incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/NOTICE.txt
incubator/tuscany/java/sca/extensions/script/container.jsr223/pom.xml
- copied, changed from r519117, incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/pom.xml
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/InstanceWrapperBase.java (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponent.java (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentBuilder.java (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentType.java (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentTypeLoader.java (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementation.java (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementationLoader.java (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptInvoker.java (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/resources/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/resources/META-INF/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/resources/META-INF/sca/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptImplementationLoaderTestCase.java (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptInvokerTestCase.java (with props)
incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/resources/
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Mar 16 13:12:01 2007
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+
Copied: incubator/tuscany/java/sca/extensions/script/container.jsr223/pom.xml (from r519117, incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/pom.xml)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/pom.xml?view=diff&rev=519121&p1=incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/pom.xml&r1=519117&p2=incubator/tuscany/java/sca/extensions/script/container.jsr223/pom.xml&r2=519121
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/pom.xml (original)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/pom.xml Fri Mar 16 13:12:01 2007
@@ -20,75 +20,65 @@
<project>
<parent>
- <groupId>org.apache.tuscany.sca.extensions</groupId>
+ <groupId>org.apache.tuscany.sca.script</groupId>
<artifactId>parent</artifactId>
- <version>0.1-integration-incubating-SNAPSHOT</version>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>tuscany-bsf</artifactId>
- <name>Apache Tuscany Script Container</name>
- <description>Apache Tuscany Script Container using BSF</description>
+ <artifactId>container-jsr223</artifactId>
+ <name>Apache Tuscany Script Container using JSR-223</name>
+ <description>Apache Tuscany Script Container using JSR-223</description>
<dependencies>
<dependency>
<groupId>org.apache.tuscany.sca.kernel</groupId>
<artifactId>tuscany-spi</artifactId>
- <version>0.1-integration-incubating-SNAPSHOT</version>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.apache.tuscany.sca.kernel</groupId>
- <artifactId>tuscany-api</artifactId>
- <version>0.1-integration-incubating-SNAPSHOT</version>
+ <groupId>org.apache.bsf</groupId>
+ <artifactId>bsf-all</artifactId>
+ <version>3.0-beta1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.apache.tuscany.sca.kernel</groupId>
- <artifactId>tuscany-core</artifactId>
- <version>0.1-integration-incubating-SNAPSHOT</version>
- <scope>runtime</scope>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ <version>2.2</version>
+ <scope>compile</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
+ <groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.2</version>
+ <version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>bsf</groupId>
- <artifactId>bsf</artifactId>
- <version>2.4.0</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1</version>
- <scope>runtime</scope>
- </dependency>
-
- <dependency>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
<version>2.2</version>
- <scope>compile</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymockclassextension</artifactId>
+ <groupId>rhino</groupId>
+ <artifactId>js</artifactId>
+ <version>1.6R5</version>
+ <scope>compile</scope> <!-- TODO: hack till extension dependencies fixed -->
</dependency>
</dependencies>
Added: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/InstanceWrapperBase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/InstanceWrapperBase.java?view=auto&rev=519121
==============================================================================
--- incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/InstanceWrapperBase.java (added)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/InstanceWrapperBase.java Fri Mar 16 13:12:01 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.extension.script;
+
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetInitializationException;
+
+/**
+ * TODO: this should be in the SPI
+ */
+public class InstanceWrapperBase<T> implements InstanceWrapper<T> {
+ protected final T instance;
+ private boolean started;
+
+ public InstanceWrapperBase(T instance) {
+ assert instance != null;
+ this.instance = instance;
+ }
+
+ public T getInstance() {
+ assert started;
+ return instance;
+ }
+
+ public boolean isStarted() {
+ return started;
+ }
+
+ public void start() throws TargetInitializationException {
+ started = true;
+ }
+
+ public void stop() throws TargetDestructionException {
+ started = false;
+ }
+}
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/InstanceWrapperBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/InstanceWrapperBase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponent.java?view=auto&rev=519121
==============================================================================
--- incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponent.java (added)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponent.java Fri Mar 16 13:12:01 2007
@@ -0,0 +1,134 @@
+/*
+ * 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.extension.script;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.AtomicComponentExtension;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.ProxyService;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+public class ScriptComponent extends AtomicComponentExtension {
+
+ private ScriptImplementation impl;
+
+ protected ScriptComponent(URI name,
+ ScriptImplementation implementation,
+ ProxyService proxyService,
+ WorkContext workContext,
+ int initLevel) {
+ super(name, proxyService, workContext, initLevel);
+ impl = implementation;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation) {
+ return new ScriptInvoker(operation.getName(), this, scopeContainer, workContext);
+ }
+
+ @SuppressWarnings("unchecked")
+ public InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException {
+ try {
+
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); // TODO: classloader?
+
+ ScriptEngineManager manager = new ScriptEngineManager();
+ ScriptEngine engine = manager.getEngineByExtension(impl.getScriptLanguage());
+ if (engine == null) {
+ throw new ObjectCreationException("no script engine found for language: " + impl.getScriptLanguage());
+ }
+
+ Reader reader;
+ if (impl.getInlineSrc() == null) {
+ URL url = impl.getClassLoader().getResource(impl.getScriptName());
+ reader = new InputStreamReader(url.openStream());
+ } else {
+ reader = new StringReader(impl.getInlineSrc());
+ }
+
+ engine.eval(reader);
+
+ return new InstanceWrapperBase(engine);
+
+ } catch (ScriptException e) {
+ throw new ObjectCreationException(e);
+ } catch (IOException e) {
+ throw new ObjectCreationException(e);
+ }
+ }
+
+ // TODO: move all the rest to SPI extension
+
+ @Deprecated
+ public Object createInstance() throws ObjectCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object getAssociatedTargetInstance() throws TargetResolutionException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getTargetInstance() throws TargetResolutionException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void attachCallbackWire(Wire wire) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void attachWire(Wire wire) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void attachWires(List<Wire> wires) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public List<Wire> getWires(String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation) {
+ throw new UnsupportedOperationException();
+ }
+
+}
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponent.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentBuilder.java?view=auto&rev=519121
==============================================================================
--- incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentBuilder.java (added)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentBuilder.java Fri Mar 16 13:12:01 2007
@@ -0,0 +1,48 @@
+/*
+ * 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.extension.script;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+
+public class ScriptComponentBuilder extends ComponentBuilderExtension<ScriptImplementation> {
+
+ public ScriptComponentBuilder() {
+ }
+
+ @Override
+ protected Class<ScriptImplementation> getImplementationType() {
+ return ScriptImplementation.class;
+ }
+
+ public Component build(ComponentDefinition componentDefinition, DeploymentContext context) throws BuilderException {
+ URI name = componentDefinition.getUri();
+ Component scriptComponent =
+ new ScriptComponent(name, (ScriptImplementation)componentDefinition.getImplementation(), proxyService,
+ workContext, 0);
+ return scriptComponent;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentBuilder.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentType.java?view=auto&rev=519121
==============================================================================
--- incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentType.java (added)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentType.java Fri Mar 16 13:12:01 2007
@@ -0,0 +1,37 @@
+/*
+ * 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.extension.script;
+
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * A componentType for script components
+ * TODO: need lifecycle methods init/destroy
+ */
+public class ScriptComponentType extends ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> {
+
+ public ScriptComponentType() {
+ this.implementationScope = Scope.COMPOSITE;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentTypeLoader.java?view=auto&rev=519121
==============================================================================
--- incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentTypeLoader.java (added)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentTypeLoader.java Fri Mar 16 13:12:01 2007
@@ -0,0 +1,68 @@
+/*
+ * 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.extension.script;
+
+import java.net.URL;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ComponentType;
+
+/**
+ * ComponentType loader for script components
+ */
+public class ScriptComponentTypeLoader extends ComponentTypeLoaderExtension<ScriptImplementation> {
+
+ public ScriptComponentTypeLoader() {
+ }
+
+ @Override
+ protected Class<ScriptImplementation> getImplementationClass() {
+ return ScriptImplementation.class;
+ }
+
+ public void load(ScriptImplementation implementation, DeploymentContext deploymentContext) throws LoaderException {
+
+ String sideFile = getSideFileName(implementation.getScriptName());
+ URL resource = implementation.getClassLoader().getResource(sideFile);
+
+ ScriptComponentType componentType;
+ if (resource == null) {
+ // TODO: or else implement introspection
+ throw new LoaderException("ComponentType side file not found", sideFile);
+ } else {
+ componentType =
+ (ScriptComponentType)loaderRegistry.load(new ScriptComponentType(),
+ resource,
+ ComponentType.class,
+ deploymentContext);
+ }
+ implementation.setComponentType(componentType);
+ }
+
+ protected String getSideFileName(String resourceName) {
+ int lastDot = resourceName.lastIndexOf('.');
+ if (lastDot != -1) {
+ resourceName = resourceName.substring(0, lastDot);
+ }
+ return resourceName + ".componentType";
+ }
+
+}
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentTypeLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptComponentTypeLoader.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementation.java?view=auto&rev=519121
==============================================================================
--- incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementation.java (added)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementation.java Fri Mar 16 13:12:01 2007
@@ -0,0 +1,62 @@
+/*
+ * 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.extension.script;
+
+import org.apache.tuscany.spi.model.Implementation;
+
+/**
+ * Model object for a script implementation.
+ */
+public class ScriptImplementation extends Implementation<ScriptComponentType> {
+
+ private String scriptName;
+ private String inlineSrc;
+ private String scriptLanguage;
+ private String scriptClassName;
+ private ClassLoader classLoader;
+
+ public ScriptImplementation(String scriptName, String inlineSrc, String scriptLanguage, String scriptClassName, ClassLoader classLoader) {
+ this.scriptName = scriptName;
+ this.inlineSrc = inlineSrc;
+ this.scriptLanguage = scriptLanguage;
+ this.scriptClassName = scriptClassName;
+ this.classLoader = classLoader;
+ }
+
+ public String getScriptClassName() {
+ return scriptClassName;
+ }
+
+ public String getScriptName() {
+ return scriptName;
+ }
+
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public String getScriptLanguage() {
+ return scriptLanguage;
+ }
+
+ public String getInlineSrc() {
+ return inlineSrc;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementation.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementationLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementationLoader.java?view=auto&rev=519121
==============================================================================
--- incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementationLoader.java (added)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementationLoader.java Fri Mar 16 13:12:01 2007
@@ -0,0 +1,97 @@
+/*
+ * 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.extension.script;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+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.apache.tuscany.spi.model.ModelObject;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * Loader for handling implementation.script elements. <p/>
+ * <code><implementation.script script="path/foo.py" [language="lang" class="myclass"]></code>
+ */
+public class ScriptImplementationLoader extends LoaderExtension<ScriptImplementation> {
+
+ private static final QName IMPLEMENTATION_SCRIPT = new QName(SCA_NS, "implementation.script");
+
+ @Constructor( {"registry"})
+ public ScriptImplementationLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return IMPLEMENTATION_SCRIPT;
+ }
+
+ public ScriptImplementation load(ModelObject mo, XMLStreamReader reader, DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException {
+
+ String scriptName = reader.getAttributeValue(null, "script");
+ if (scriptName != null && scriptName.length() < 1) {
+ scriptName = null;
+ }
+
+ String scriptLanguage = reader.getAttributeValue(null, "language");
+ if (scriptLanguage == null || scriptLanguage.length() < 1) {
+ int i = scriptName.lastIndexOf('.');
+ if (i > 0) {
+ scriptLanguage = scriptName.substring(i + 1);
+ }
+ }
+ if (scriptLanguage == null || scriptLanguage.length() < 1) {
+ throw new LoaderException("unable to determine script language");
+ }
+
+ String scriptClassName = reader.getAttributeValue(null, "class");
+
+ String scriptSrc = null;
+// String scriptSrc = reader.getElementText();
+// if (scriptSrc != null && scriptSrc.length() < 1) {
+// scriptSrc = null;
+// }
+ if (scriptName == null && scriptSrc == null) {
+ throw new MissingResourceException("no 'script' attribute or inline script source");
+ }
+ if (scriptName != null && scriptSrc != null) {
+ throw new MissingResourceException("cannot use both 'script' attribute and inline script");
+ }
+
+ LoaderUtil.skipToEndElement(reader);
+
+ ClassLoader cl = deploymentContext.getClassLoader();
+
+ ScriptImplementation impl = new ScriptImplementation(scriptName, scriptSrc, scriptLanguage, scriptClassName, cl);
+
+ registry.loadComponentType(impl, deploymentContext);
+
+ return impl;
+ }
+}
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementationLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptImplementationLoader.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptInvoker.java?view=auto&rev=519121
==============================================================================
--- incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptInvoker.java (added)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptInvoker.java Fri Mar 16 13:12:01 2007
@@ -0,0 +1,137 @@
+/*
+ * 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.extension.script;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.script.Invocable;
+import javax.script.ScriptException;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.InvalidConversationSequenceException;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.TargetInvokerExtension;
+import org.apache.tuscany.spi.model.Scope;
+
+/**
+ * Perform the actual script invocation
+ * TODO: move vertually all of this to SPI TargetInvokerExtension
+ */
+@SuppressWarnings("deprecation")
+public class ScriptInvoker extends TargetInvokerExtension {
+
+ protected Object clazz;
+ protected String operationName;
+
+ private final AtomicComponent component;
+ private final ScopeContainer<?, ?> scopeContainer;
+ protected InstanceWrapper<?> target;
+ protected boolean stateless;
+
+ public ScriptInvoker(String operationName,
+ AtomicComponent component,
+ ScopeContainer scopeContainer,
+ WorkContext workContext) {
+ super(workContext);
+ this.component = component;
+ this.scopeContainer = scopeContainer;
+ stateless = Scope.STATELESS == scopeContainer.getScope();
+
+ this.operationName = operationName;
+ // TODO: support script classes
+ }
+
+ public Object invokeTarget(Object instance, Object args) throws InvocationTargetException {
+ try {
+
+ Invocable scriptEngine = (Invocable)instance;
+
+ if (clazz == null) {
+ return scriptEngine.invokeFunction(operationName, (Object[])args);
+ } else {
+ return scriptEngine.invokeMethod(clazz, operationName, (Object[])args);
+ }
+
+ } catch (ScriptException e) {
+ throw new InvocationTargetException(e.getCause() != null ? e.getCause() : e);
+ } catch (Exception e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException {
+ try {
+ InstanceWrapper<?> wrapper = getInstance(sequence);
+ Object instance = wrapper.getInstance();
+
+ Object ret = invokeTarget(instance, payload);
+
+ scopeContainer.returnWrapper(component, wrapper);
+ if (sequence == END) {
+ // if end conversation, remove resource
+ scopeContainer.remove(component);
+ }
+ return ret;
+ } catch (ComponentException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ @Override
+ public ScriptInvoker clone() throws CloneNotSupportedException {
+ try {
+ ScriptInvoker invoker = (ScriptInvoker)super.clone();
+ invoker.target = null;
+ return invoker;
+ } catch (CloneNotSupportedException e) {
+ return null; // will not happen
+ }
+ }
+
+ /**
+ * Resolves the target service instance or returns a cached one
+ */
+ protected InstanceWrapper<?> getInstance(short sequence) throws TargetException {
+ switch (sequence) {
+ case NONE:
+ if (cacheable) {
+ if (target == null) {
+ target = scopeContainer.getWrapper(component);
+ }
+ return target;
+ } else {
+ return scopeContainer.getWrapper(component);
+ }
+ case START:
+ assert !cacheable;
+ return scopeContainer.getWrapper(component);
+ case CONTINUE:
+ case END:
+ assert !cacheable;
+ return scopeContainer.getAssociatedWrapper(component);
+ default:
+ throw new InvalidConversationSequenceException("Unknown sequence type", String.valueOf(sequence));
+ }
+ }
+}
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptInvoker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/java/org/apache/tuscany/extension/script/ScriptInvoker.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl?view=auto&rev=519121
==============================================================================
--- incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl (added)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl Fri Mar 16 13:12:01 2007
@@ -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/sca/system/2.0-alpha"
+ name="org.apache.tuscany.extension.script.jsr223"
+ autowire="true">
+
+ <component name="script.implementationLoader">
+ <system:implementation.system class="org.apache.tuscany.extension.script.ScriptImplementationLoader"/>
+ </component>
+
+ <component name="script.componentTypeLoader">
+ <system:implementation.system class="org.apache.tuscany.extension.script.ScriptComponentTypeLoader"/>
+ </component>
+
+ <component name="script.componentBuilder">
+ <system:implementation.system class="org.apache.tuscany.extension.script.ScriptComponentBuilder"/>
+ </component>
+
+</composite>
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/main/resources/META-INF/sca/script.system.scdl
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptImplementationLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptImplementationLoaderTestCase.java?view=auto&rev=519121
==============================================================================
--- incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptImplementationLoaderTestCase.java (added)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptImplementationLoaderTestCase.java Fri Mar 16 13:12:01 2007
@@ -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.extension.script;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.easymock.EasyMock;
+
+public class ScriptImplementationLoaderTestCase extends TestCase {
+
+ private String XML_START =
+ "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/2.0-alpha\">";
+ private String XML_END = "</composite>";
+
+ public void testLoadNamedScript() throws XMLStreamException, LoaderException {
+
+ String xml =
+ XML_START + "<implementation.script script=\"path/foo.py\" language=\"myLang\" class=\"myClass\" />"
+ + XML_END;
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(xml));
+ reader.next();
+ reader.next();
+
+ LoaderRegistry reg = EasyMock.createNiceMock(LoaderRegistry.class);
+ ScriptImplementationLoader loader = new ScriptImplementationLoader(reg);
+ DeploymentContext deploymentContext = EasyMock.createNiceMock(DeploymentContext.class);
+ ScriptImplementation impl = loader.load(null, reader, deploymentContext);
+
+ assertEquals("path/foo.py", impl.getScriptName());
+ assertEquals("myLang", impl.getScriptLanguage());
+ assertEquals("myClass", impl.getScriptClassName());
+ assertNull(impl.getInlineSrc());
+ }
+
+// public void testLoadInlineScript() throws XMLStreamException, LoaderException {
+//
+// String xml =
+// XML_START + "<implementation.script language=\"myLang\" class=\"myClass\">"
+// + "myScriptSrc"
+// + "</implementation.script>"
+// + XML_END;
+// XMLInputFactory factory = XMLInputFactory.newInstance();
+// XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(xml));
+// reader.next();
+// reader.next();
+//
+// LoaderRegistry reg = EasyMock.createNiceMock(LoaderRegistry.class);
+// ScriptImplementationLoader loader = new ScriptImplementationLoader(reg);
+// DeploymentContext deploymentContext = EasyMock.createNiceMock(DeploymentContext.class);
+// ScriptImplementation impl = loader.load(null, reader, deploymentContext);
+//
+// assertNull(impl.getScriptName());
+// assertEquals("myScriptSrc", impl.getInlineSrc());
+// assertEquals("myLang", impl.getScriptLanguage());
+// assertEquals("myClass", impl.getScriptClassName());
+// }
+}
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptImplementationLoaderTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptImplementationLoaderTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptInvokerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptInvokerTestCase.java?view=auto&rev=519121
==============================================================================
--- incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptInvokerTestCase.java (added)
+++ incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptInvokerTestCase.java Fri Mar 16 13:12:01 2007
@@ -0,0 +1,51 @@
+/*
+ * 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.extension.script;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.easymock.EasyMock;
+
+public class ScriptInvokerTestCase extends TestCase {
+
+ private ScriptEngine engine;
+ private ScopeContainer mockScopeContainer;
+
+ public void testInvokeTarget() throws ScriptException, InvocationTargetException {
+ engine.eval("function foo(s) {return 'hi ' + s; }");
+ ScriptInvoker invoker = new ScriptInvoker("foo", null, mockScopeContainer, null);
+ assertEquals("hi petra", invoker.invokeTarget(engine, new Object[] {"petra"}));
+ }
+
+ @Override
+ public void setUp() {
+ ScriptEngineManager manager = new ScriptEngineManager();
+ engine = manager.getEngineByExtension("js");
+ mockScopeContainer = EasyMock.createNiceMock(ScopeContainer.class);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptInvokerTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/extensions/script/container.jsr223/src/test/java/org/apache/tuscany/extension/script/ScriptInvokerTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org