diff options
Diffstat (limited to 'sca-java-1.x/tags/java-stable-20060304/sca/container.js/src')
55 files changed, 3366 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptAssemblyFactory.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptAssemblyFactory.java new file mode 100644 index 0000000000..0072bcdaa1 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptAssemblyFactory.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly; + +import org.apache.tuscany.model.assembly.AssemblyFactory; + +public interface JavaScriptAssemblyFactory extends AssemblyFactory { + + /** + * Returns a new object of class '<em>JavaScript Implementation</em>'. + */ + JavaScriptImplementation createJavaScriptImplementation(); + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptImplementation.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptImplementation.java new file mode 100644 index 0000000000..6edaf2b60a --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptImplementation.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly; + +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.model.assembly.ComponentImplementation; + +/** + * A representation of a JavaScript component implementation type + * + * @version $Rev$ $Date$ + */ +public interface JavaScriptImplementation extends ComponentImplementation { + + public ResourceLoader getResourceLoader(); + + public String getScriptFile(); + + public void setScriptFile(String fn); +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptAssemblyFactoryImpl.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptAssemblyFactoryImpl.java new file mode 100644 index 0000000000..21930d22ec --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptAssemblyFactoryImpl.java @@ -0,0 +1,33 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.impl; + +import org.apache.tuscany.container.js.assembly.JavaScriptAssemblyFactory; +import org.apache.tuscany.container.js.assembly.JavaScriptImplementation; +import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; + +public class JavaScriptAssemblyFactoryImpl extends AssemblyFactoryImpl implements JavaScriptAssemblyFactory { + + public JavaScriptAssemblyFactoryImpl() { + super(); + } + + public JavaScriptImplementation createJavaScriptImplementation() { + return new JavaScriptImplementationImpl(); + } + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptImplementationImpl.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptImplementationImpl.java new file mode 100644 index 0000000000..c6b58a25c6 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptImplementationImpl.java @@ -0,0 +1,116 @@ +package org.apache.tuscany.container.js.assembly.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.container.js.assembly.JavaScriptImplementation; +import org.apache.tuscany.model.assembly.AssemblyModelContext; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.ModelInitException; +import org.apache.tuscany.model.assembly.impl.ComponentImplementationImpl; + +/** + * Default implementation of a JavScript component implementation type + * + * @version $Rev$ $Date$ + */ +public class JavaScriptImplementationImpl extends ComponentImplementationImpl implements JavaScriptImplementation { + + private ResourceLoader resourceLoader; + + public JavaScriptImplementationImpl() { + super(); + } + + public ResourceLoader getResourceLoader() { + return null; + } + + public void initialize(AssemblyModelContext modelContext) throws ModelInitException { + if (isInitialized()) { + return; + } + this.resourceLoader = modelContext.getApplicationResourceLoader(); + if(resourceLoader == null){ + throw new ModelInitException("No resource loader set on model context"); + } + getScriptFile(); + + // Initialize the component type + ComponentType componentType = getComponentType(); + if (componentType == null) { + try { + componentType = createComponentType(modelContext); + } catch (IOException e) { + throw new ModelInitException("Error retrieving component type file",e); + } + setComponentType(componentType); + } + + super.initialize(modelContext); + + } + + String script; + + public String getScriptFile() { + return script; + } + + public void setScriptFile(String fn) { + script = fn; + } + + private String scriptCode; + + public String getScript() throws ModelInitException { + if (scriptCode != null) { + return scriptCode; + } + try { + URL url = resourceLoader.getResource(getScriptFile()); + if (url == null) { + ModelInitException ce = new ModelInitException("Script not found"); + ce.setIdentifier(getScriptFile()); + throw ce; + } + InputStream inputStream = url.openStream(); + try { + StringBuffer sb = new StringBuffer(); + int n = 0; + while ((n = inputStream.read()) != -1) { + sb.append((char) n); + } + scriptCode = sb.toString(); + return scriptCode; + } finally { + inputStream.close(); + } + } catch (IOException e) { + ModelInitException ce = new ModelInitException("Error reading script file",e); + ce.setIdentifier(getScriptFile()); + throw ce; + } + } + + /** + * Create the component type + * + * @param modelContext + * @param implementationClass + */ + private ComponentType createComponentType(AssemblyModelContext modelContext) throws IOException{ + String prefix = script.substring(0,script.lastIndexOf('.')); + URL componentTypeFile = resourceLoader.getResource(prefix + ".componentType"); + if (componentTypeFile != null) { + return modelContext.getAssemblyLoader().loadComponentType(componentTypeFile.toString()); + } else { + // TODO we could introspect the JavaScript source + return modelContext.getAssemblyFactory().createComponentType(); + } + } + + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/builder/JavaScriptComponentContextBuilder.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/builder/JavaScriptComponentContextBuilder.java new file mode 100644 index 0000000000..37ec68942a --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/builder/JavaScriptComponentContextBuilder.java @@ -0,0 +1,217 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.builder; + +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.container.js.assembly.JavaScriptImplementation; +import org.apache.tuscany.container.js.assembly.impl.JavaScriptImplementationImpl; +import org.apache.tuscany.container.js.config.JavaScriptComponentRuntimeConfiguration; +import org.apache.tuscany.container.js.rhino.RhinoScript; +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder; +import org.apache.tuscany.core.context.AggregateContext; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.invocation.InvocationConfiguration; +import org.apache.tuscany.core.invocation.MethodHashMap; +import org.apache.tuscany.core.invocation.ProxyConfiguration; +import org.apache.tuscany.core.invocation.impl.InvokerInterceptor; +import org.apache.tuscany.core.invocation.spi.ProxyFactory; +import org.apache.tuscany.core.invocation.spi.ProxyFactoryFactory; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.apache.tuscany.model.assembly.AssemblyModelObject; +import org.apache.tuscany.model.assembly.ComponentImplementation; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.ModelInitException; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.assembly.ServiceContract; +import org.apache.tuscany.model.assembly.SimpleComponent; +import org.osoa.sca.annotations.Init; + +/** + * Builds {@link org.apache.tuscany.container.js.config.JavaScriptComponentRuntimeConfiguration}s from a JavaScript + * component type + * + * @version $Rev$ $Date$ + */ +@org.osoa.sca.annotations.Scope("MODULE") +public class JavaScriptComponentContextBuilder implements RuntimeConfigurationBuilder<AggregateContext> { + + private ProxyFactoryFactory factory; + private MessageFactory msgFactory; + private RuntimeConfigurationBuilder referenceBuilder; + private RuntimeContext runtimeContext; + + // ---------------------------------- + // Constructors + // ---------------------------------- + + public JavaScriptComponentContextBuilder() { + } + + // ---------------------------------- + // Methods + // ---------------------------------- + + @Init(eager = true) + public void init() { + runtimeContext.addBuilder(this); + } + + /** + * @param runtimeContext The runtimeContext to set. + */ + @Autowire + public void setRuntimeContext(RuntimeContext runtimeContext) { + this.runtimeContext = runtimeContext; + } + + /** + * Sets the factory used to construct proxies implmementing the business interface required by a reference + */ + @Autowire + public void setProxyFactoryFactory(ProxyFactoryFactory factory) { + this.factory = factory; + } + + /** + * Sets the factory used to construct invocation messages + */ + @Autowire + public void setMessageFactory(MessageFactory msgFactory) { + this.msgFactory = msgFactory; + } + + /** + * Sets a builder responsible for creating source-side and target-side invocation chains for a reference. The + * reference builder may be hierarchical, containing other child reference builders that operate on specific + * metadata used to construct and invocation chain. + * + * @see org.apache.tuscany.core.builder.impl.HierarchicalBuilder + */ + public void setReferenceBuilder(RuntimeConfigurationBuilder builder) { + this.referenceBuilder = builder; + } + + public void build(AssemblyModelObject modelObject, AggregateContext context) throws BuilderException { + if (modelObject instanceof SimpleComponent) { + SimpleComponent component = (SimpleComponent) modelObject; + ComponentImplementation impl = component.getComponentImplementation(); + if (impl instanceof JavaScriptImplementation) { + Scope scope = ((JavaScriptImplementation) impl).getComponentType().getServices().get(0).getServiceContract() + .getScope(); + Map<String, Class> services = new HashMap(); + for (Service service : ((JavaScriptImplementation) impl).getComponentType().getServices()) { + services.put(service.getName(), service.getServiceContract().getInterface()); + } + Map<String, Object> properties = new HashMap(); + // TODO support properties + String script = null; + if (impl instanceof JavaScriptImplementationImpl) { // fixme + try { + script = ((JavaScriptImplementationImpl) impl).getScript(); + } catch (ModelInitException e) { + throw new BuilderConfigException(e); + } + } + + RhinoScript invoker = createRhinoInvoker(component.getName(), script, properties); + JavaScriptComponentRuntimeConfiguration config = new JavaScriptComponentRuntimeConfiguration(component.getName(), + scope, services, properties, invoker); + + // create target-side invocation chains for each service offered by the implementation + for (ConfiguredService configuredService : component.getConfiguredServices()) { + Service service = configuredService.getService(); + ServiceContract contract = service.getServiceContract(); + Map<Method, InvocationConfiguration> iConfigMap = new MethodHashMap(); + ProxyFactory proxyFactory = factory.createProxyFactory(); + for (Method method : contract.getInterface().getMethods()) { + InvocationConfiguration iConfig = new InvocationConfiguration(method); + iConfigMap.put(method, iConfig); + } + QualifiedName qName = new QualifiedName(component.getName() + QualifiedName.NAME_SEPARATOR + service.getName()); + ProxyConfiguration pConfiguration = new ProxyConfiguration(qName, iConfigMap, contract.getInterface().getClassLoader(), msgFactory); + proxyFactory.setBusinessInterface(contract.getInterface()); + proxyFactory.setProxyConfiguration(pConfiguration); + configuredService.setProxyFactory(proxyFactory); + if (referenceBuilder != null) { + // invoke the reference builder to handle target-side metadata + referenceBuilder.build(configuredService, context); + } + // add tail interceptor + for (InvocationConfiguration iConfig : (Collection<InvocationConfiguration>) iConfigMap.values()) { + iConfig.addTargetInterceptor(new InvokerInterceptor()); + } + config.addTargetProxyFactory(service.getName(), proxyFactory); + } + + // handle references + List<ConfiguredReference> configuredReferences = component.getConfiguredReferences(); + if (configuredReferences != null) { + for (ConfiguredReference reference : configuredReferences) { + ProxyFactory proxyFactory = factory.createProxyFactory(); + ServiceContract interfaze = reference.getReference().getServiceContract(); + Map<Method, InvocationConfiguration> iConfigMap = new MethodHashMap(); + for (Method method : interfaze.getInterface().getMethods()) { + InvocationConfiguration iConfig = new InvocationConfiguration(method); + iConfigMap.put(method, iConfig); + } + String targetCompName = reference.getTargetConfiguredServices().get(0).getAggregatePart().getName(); + String targetSerivceName = reference.getTargetConfiguredServices().get(0).getService().getName(); + + QualifiedName qName = new QualifiedName(targetCompName + "/" + targetSerivceName); + + // QualifiedName qName = new QualifiedName(reference.getPart().getName() + "/" + // + reference.getPort().getName()); + ProxyConfiguration pConfiguration = new ProxyConfiguration(qName, iConfigMap, interfaze.getInterface().getClassLoader(), msgFactory); + proxyFactory.setBusinessInterface(interfaze.getInterface()); + proxyFactory.setProxyConfiguration(pConfiguration); + reference.setProxyFactory(proxyFactory); + if (referenceBuilder != null) { + // invoke the reference builder to handle metadata associated with the reference + referenceBuilder.build(reference, context); + } + config.addSourceProxyFactory(reference.getReference().getName(), proxyFactory); + } + } + component.getComponentImplementation().setRuntimeConfiguration(config); + } + } + } + + /** + * Creates a representation of the JavaScript implementation script that is used to perform invocations + * + * @param name + * @param script the Script source + * @param properties configured properties for the component + * @return + */ + private RhinoScript createRhinoInvoker(String name, String script, Map properties) { + RhinoScript ri = new RhinoScript(name, script, properties); + return ri; + } +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/builder/JavaScriptTargetWireBuilder.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/builder/JavaScriptTargetWireBuilder.java new file mode 100644 index 0000000000..74433db823 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/builder/JavaScriptTargetWireBuilder.java @@ -0,0 +1,75 @@ +package org.apache.tuscany.container.js.builder; + +import java.lang.reflect.Method; + +import org.apache.tuscany.container.js.config.JavaScriptComponentRuntimeConfiguration; +import org.apache.tuscany.container.js.rhino.RhinoTargetInvoker; +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.invocation.InvocationConfiguration; +import org.apache.tuscany.core.invocation.spi.ProxyFactory; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +/** + * Responsible for bridging source- and target-side invocations chains when the target type is a JavaScript + * implementation + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class JavaScriptTargetWireBuilder implements WireBuilder { + + private RuntimeContext runtimeContext; + + @Autowire + public void setRuntimeContext(RuntimeContext context) { + runtimeContext = context; + } + + public JavaScriptTargetWireBuilder() { + } + + @Init(eager=true) + public void init() { + runtimeContext.addBuilder(this); + } + + public void connect(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope, + ScopeContext targetScopeContext) throws BuilderConfigException { + if (!(JavaScriptComponentRuntimeConfiguration.class.isAssignableFrom(targetType))) { + return; + } + for (InvocationConfiguration sourceInvocationConfig : sourceFactory.getProxyConfiguration().getInvocationConfigurations() + .values()) { + Method method = sourceInvocationConfig.getMethod(); + RhinoTargetInvoker invoker = new RhinoTargetInvoker(sourceFactory.getProxyConfiguration().getTargetName() + .getPartName(), method.getName(), targetScopeContext); + if (downScope) { + // the source scope is shorter than the target, so the invoker can cache the target instance + // invoker.setCacheable(true); + } else { + // invoker.setCacheable(false); + } + sourceInvocationConfig.setTargetInvoker(invoker); + } + } + + public void completeTargetChain(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) + throws BuilderConfigException { + if (!(JavaScriptComponentRuntimeConfiguration.class.isAssignableFrom(targetType))) { + return; + } + for (InvocationConfiguration targetInvocationConfig : targetFactory.getProxyConfiguration().getInvocationConfigurations() + .values()) { + Method method = targetInvocationConfig.getMethod(); + RhinoTargetInvoker invoker = new RhinoTargetInvoker(targetFactory.getProxyConfiguration().getTargetName() + .getPartName(), method.getName(), targetScopeContext); + targetInvocationConfig.setTargetInvoker(invoker); + } + } + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/config/JavaScriptComponentRuntimeConfiguration.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/config/JavaScriptComponentRuntimeConfiguration.java new file mode 100644 index 0000000000..b24f98f32a --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/config/JavaScriptComponentRuntimeConfiguration.java @@ -0,0 +1,101 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.config; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.container.js.context.JavaScriptComponentContext; +import org.apache.tuscany.container.js.rhino.RhinoScript; +import org.apache.tuscany.core.builder.ContextCreationException; +import org.apache.tuscany.core.builder.RuntimeConfiguration; +import org.apache.tuscany.core.context.SimpleComponentContext; +import org.apache.tuscany.core.invocation.spi.ProxyFactory; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Creates instance contexts for JavaScript component types + * + * @version $Rev$ $Date$ + */ +public class JavaScriptComponentRuntimeConfiguration implements RuntimeConfiguration<SimpleComponentContext> { + + private Scope scope; + + private String name; + + private Map<String, Class> services; + + private Map<String, Object> properties; + + private RhinoScript invoker; + + public JavaScriptComponentRuntimeConfiguration(String name, Scope scope, Map<String, Class> services, + Map<String, Object> properties, RhinoScript invoker) { + this.name = name; + this.scope = scope; + this.services = services; + this.properties = properties; + this.invoker = invoker; + } + + public SimpleComponentContext createInstanceContext() throws ContextCreationException { + return new JavaScriptComponentContext(name, services, properties, sourceProxyFactories, targetProxyFactories, invoker + .copy()); + } + + public Scope getScope() { + return scope; + } + + public String getName() { + return name; + } + + private Map<String, ProxyFactory> targetProxyFactories = new HashMap<String, ProxyFactory>(); + + public void addTargetProxyFactory(String serviceName, ProxyFactory factory) { + targetProxyFactories.put(serviceName, factory); + } + + public ProxyFactory getTargetProxyFactory(String serviceName) { + return targetProxyFactories.get(serviceName); + } + + public Map<String, ProxyFactory> getTargetProxyFactories() { + return targetProxyFactories; + } + + private Map<String, ProxyFactory> sourceProxyFactories = new HashMap<String, ProxyFactory>(); + + public void addSourceProxyFactory(String referenceName, ProxyFactory factory) { + sourceProxyFactories.put(referenceName, factory); + } + + public ProxyFactory getSourceProxyFactory(String referenceName) { + return sourceProxyFactories.get(referenceName); + } + + public Map<String, ProxyFactory> getSourceProxyFactories() { + return sourceProxyFactories; + } + + public void prepare() { + + } + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/context/JavaScriptComponentContext.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/context/JavaScriptComponentContext.java new file mode 100644 index 0000000000..8a4db7eb44 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/context/JavaScriptComponentContext.java @@ -0,0 +1,161 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.context; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.apache.tuscany.container.js.rhino.RhinoScript; +import org.apache.tuscany.core.context.AbstractContext; +import org.apache.tuscany.core.context.CoreRuntimeException; +import org.apache.tuscany.core.context.LifecycleEventListener; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.SimpleComponentContext; +import org.apache.tuscany.core.context.TargetException; +import org.apache.tuscany.core.invocation.spi.ProxyCreationException; +import org.apache.tuscany.core.invocation.spi.ProxyFactory; + +public class JavaScriptComponentContext extends AbstractContext implements SimpleComponentContext { + + private Map<String, Class> services; + + private RhinoScript rhinoInvoker; + + private Map<String, Object> properties; + + private Map<String, ProxyFactory> sourceProxyFactories; + + private Map<String, ProxyFactory> targetProxyFactories; + + private Object instance; + + public JavaScriptComponentContext(String name, Map<String, Class> services, Map<String, Object> properties, + Map<String, ProxyFactory> sourceProxyFactories, Map<String, ProxyFactory> targetProxyFactories, RhinoScript invoker) { + super(name); + assert (services != null) : "No service interface mapping specified"; + assert (properties != null) : "No properties specified"; + this.services = services; + this.properties = properties; + this.rhinoInvoker = invoker; + this.sourceProxyFactories = sourceProxyFactories; + this.targetProxyFactories = targetProxyFactories; + } + + public Object getInstance(QualifiedName qName) throws TargetException { + return getInstance(qName, true); + } + + public synchronized Object getInstance(QualifiedName qName, boolean notify) throws TargetException { + String portName=qName.getPortName(); + ProxyFactory targetFactory; + if (portName!=null) { + targetFactory = targetProxyFactories.get(portName); + } else { + //FIXME The port name is null here, either locateService needs more information (the expected interface) to + // select the correct port, or we need to return a factory that matches the whole set of services exposed by + // the component. + targetFactory = targetProxyFactories.values().iterator().next(); + } + if (targetFactory == null) { + TargetException e = new TargetException("Target service not found"); + e.setIdentifier(qName.getPortName()); + e.addContextName(getName()); + throw e; + } + try { + Object proxy = targetFactory.createProxy(); //createProxy(new Class[] { iface }); + notifyListeners(notify); + return proxy; + } catch (ProxyCreationException e) { + TargetException te = new TargetException("Error returning target", e); + e.setIdentifier(qName.getPortName()); + e.addContextName(getName()); + throw te; + } + } + + public Object getImplementationInstance() throws TargetException { + return getImplementationInstance(true); + } + + public Object getImplementationInstance(boolean notify) throws TargetException { + rhinoInvoker.updateScriptScope(properties); // create prop values + return rhinoInvoker; + } + +// private Object createProxy(Class[] ifaces) throws ProxyCreationException { +// // final RhinoInvoker rhinoInvoker = implementation.getRhinoInvoker().copy(); +// rhinoInvoker.updateScriptScope(properties); // create prop values +// final Map refs = createInvocationContext(); +// InvocationHandler ih = new InvocationHandler() { +// public Object invoke(Object proxy, Method method, Object[] args) { +// return rhinoInvoker.invoke(method.getName(), args, method.getReturnType(), refs); +// // return rhinoInvoker.invoke(method.getName(), args, method.getReturnType(),createInvocationContext()); +// } +// }; +// return Proxy.newProxyInstance(ifaces[0].getClassLoader(), ifaces, ih); +// } + + private void notifyListeners(boolean notify) { + if (notify) { + for (Iterator iter = contextListener.iterator(); iter.hasNext();) { + LifecycleEventListener listener = (LifecycleEventListener) iter.next(); + listener.onInstanceCreate(this); + } + } + } + + /** + * Creates a map containing any properties and their values + */ + // private Map createPropertyValues() { + // Map<String,Object> context = new HashMap<String,Object>(); + // List<ConfiguredProperty> configuredProperties = component.getConfiguredProperties(); + // if (configuredProperties != null) { + // for (ConfiguredProperty property : configuredProperties) { + // context.put(property.getProperty().getName(), property.getValue()); + // } + // } + // return context; + // } + /** + * Creates a map containing any ServiceReferences + */ + private Map createInvocationContext() throws ProxyCreationException { + Map<String, Object> context = new HashMap<String, Object>(); + for (Map.Entry<String, ProxyFactory> entry : sourceProxyFactories.entrySet()) { + context.put(entry.getKey(), entry.getValue().createProxy()); + } + return context; + } + + public boolean isEagerInit() { + return false; + } + + public boolean isDestroyable() { + return false; + } + + public void start() throws CoreRuntimeException { + } + + public void stop() throws CoreRuntimeException { + } + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/loader/JavaScriptSCDLModelLoader.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/loader/JavaScriptSCDLModelLoader.java new file mode 100644 index 0000000000..ed7d267c89 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/loader/JavaScriptSCDLModelLoader.java @@ -0,0 +1,77 @@ +package org.apache.tuscany.container.js.loader; + +import org.apache.tuscany.container.js.assembly.JavaScriptAssemblyFactory; +import org.apache.tuscany.container.js.assembly.JavaScriptImplementation; +import org.apache.tuscany.container.js.assembly.impl.JavaScriptAssemblyFactoryImpl; +import org.apache.tuscany.container.js.scdl.ScdlFactory; +import org.apache.tuscany.container.js.scdl.impl.ScdlPackageImpl; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.apache.tuscany.core.loader.SCDLModelLoaderRegistry; +import org.apache.tuscany.model.assembly.AssemblyModelContext; +import org.apache.tuscany.model.assembly.AssemblyModelObject; +import org.apache.tuscany.model.scdl.loader.SCDLModelLoader; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Reference; + +/** + * Populates the assembly model from an SCDL model + */ +@org.osoa.sca.annotations.Scope("MODULE") +public class JavaScriptSCDLModelLoader implements SCDLModelLoader { + + private RuntimeContext runtimeContext; + private SCDLModelLoaderRegistry loaderRegistry; + private JavaScriptAssemblyFactory jsFactory; + + static { + // Register the JavaScript SCDL model + SDOUtil.registerStaticTypes(ScdlFactory.class); + } + + /** + * @param runtimeContext The runtimeContext to set. + */ + @Autowire + public void setRuntimeContext(RuntimeContext runtimeContext) { + this.runtimeContext = runtimeContext; + } + +// @Reference + public void setLoaderRegistry(SCDLModelLoaderRegistry registry) { + this.loaderRegistry = registry; + } + + @Init(eager=true) + public void init() { + runtimeContext.addLoader(this); +// loaderRegistry.registerLoader(this); + } + + @Destroy + public void destroy() { +// loaderRegistry.unregisterLoader(this); + } + + /** + * Constructs a new JavaSCDLModelLoader. + */ + public JavaScriptSCDLModelLoader() { + this.jsFactory=new JavaScriptAssemblyFactoryImpl(); + } + + /** + * @see org.apache.tuscany.model.scdl.loader.SCDLModelLoader#load(org.apache.tuscany.model.assembly.AssemblyModelContext, java.lang.Object) + */ + public AssemblyModelObject load(AssemblyModelContext modelContext, Object object) { + if (object instanceof org.apache.tuscany.container.js.scdl.JavaScriptImplementation) { + org.apache.tuscany.container.js.scdl.JavaScriptImplementation scdlImplementation=(org.apache.tuscany.container.js.scdl.JavaScriptImplementation)object; + JavaScriptImplementation implementation=jsFactory.createJavaScriptImplementation(); + implementation.setScriptFile(scdlImplementation.getScriptFile()); + return implementation; + } else + return null; + } +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/rhino/RhinoScript.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/rhino/RhinoScript.java new file mode 100644 index 0000000000..4ddee12fe4 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/rhino/RhinoScript.java @@ -0,0 +1,298 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.rhino; + +import java.util.Iterator; +import java.util.Map; + +import org.mozilla.javascript.Context; +import org.mozilla.javascript.ContextFactory; +import org.mozilla.javascript.Function; +import org.mozilla.javascript.Script; +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.Wrapper; + +/** + * Represents, and is responsible for dispatching to, a JavaScript artifact in Rhino + */ +public class RhinoScript { + + private String scriptName; + + private String script; + + private Scriptable scriptScope; + + private Scriptable sharedScope; + + /* + * Enable dynamic scopes so a script can be used concurrently with a global shared scope and individual execution + * scopes. See http://www.mozilla.org/rhino/scopes.html TODO: need to review how ths fits in with Tuscany scopes + */ + private static class MyFactory extends ContextFactory { + protected boolean hasFeature(Context cx, int featureIndex) { + if (featureIndex == Context.FEATURE_DYNAMIC_SCOPE) { + return true; + } + return super.hasFeature(cx, featureIndex); + } + } + + static { + ContextFactory.initGlobal(new MyFactory()); + } + + /** + * Create a new RhinoInvoker. + * + * @param scriptName the name of the script. Can be anything, only used in messages to identify the script + * @param script the complete script + */ + public RhinoScript(String scriptName, String script) { + this(scriptName, script, (Map) null); + } + + /** + * Create a new RhinoInvoker. + * + * @param scriptName the name of the script. Can be anything, only used in messages to identify the script + * @param script the complete script + * @param context name-value pairs that are added in to the scope where the script is compiled. May be null. The + * value objects are made available to the script by using a variable with the name. + */ + public RhinoScript(String scriptName, String script, Map context) { + this.scriptName = scriptName; + this.script = script; + initScriptScope(scriptName, script, context); + initSharedScope(); + } + + /** + * Construct a RhinoInvoker from another RhinoInvoker object. This uses the original script scope so the script + * doesn't need to be recompiled. + */ + protected RhinoScript(String scriptName, String script, Scriptable scriptScope) { + this.scriptName = scriptName; + this.script = script; + this.scriptScope = scriptScope; + initSharedScope(); + } + + /** + * Invoke a script function + * + * @param functionName the name of the function to invoke. + * @param arg arguments to the function, may be a single object or an array of objects. + * @return the function return value. + */ + public Object invoke(String functionName, Object args) { + return invoke(functionName, args, null, null); + } + + /** + * Invoke a script function + * + * @param functionName the name of the function to invoke. + * @param arg arguments to the function, may be a single object or an array of objects. + * @param contexts a Map of name-value pairs which are added to the invocation Scope to enable the script to access + * the values by using the variable in name. + * @return the function return value. + */ + public Object invoke(String functionName, Object args, Map contexts) { + return invoke(functionName, args, null, contexts); + } + + /** + * Invoke a script function + * + * @param functionName the name of the function to invoke. + * @param arg arguments to the function, may be a single object or an array of objects. + * @param responseClass the desired class of the response object. + * @param contexts a Map of name-value pairs which are added to the invocation Scope to enable the script to access + * the values by using the variable in name. + * @return the function return value. + */ + public Object invoke(String functionName, Object arg, Class responseClass, Map contexts) { + Context cx = Context.enter(); + try { + Function function = getFunction(scriptScope, functionName); + Scriptable invocationScope = getInvocationScope(cx, contexts); + Object[] args = processArgs(arg, invocationScope); + Object jsResponse = function.call(cx, invocationScope, invocationScope, args); + Object response = processResponse(jsResponse, responseClass); + return response; + } finally { + Context.exit(); + } + } + + /** + * Turn args to JS objects and convert any OMElement to E4X XML + */ + protected Object[] processArgs(Object arg, Scriptable scope) { + // TODO: implement pluggable way to transform objects (eg SDO or AXIOM) to E4X XML objects + // if (arg instanceof OMElement) { + // try { + // arg = E4XAXIOMUtils.toScriptableObject((OMElement) arg, scope); + // } catch (XmlException e) { + // throw new RuntimeException(e); + // } + // } else if (arg instanceof MessageContext) { + // arg = new E4XMessageContext((MessageContext) arg, scope); + // } + Object[] args; + if (arg == null) { + args = new Object[] { null }; + } else if (arg.getClass().isArray()) { + args = (Object[]) arg; + for (int i = 0; i < args.length; i++) { + args[i] = Context.toObject(args[i], scope); + } + } else { + args = new Object[] { Context.toObject(arg, scope) }; + } + return args; + } + + /** + * Unwrap and convert response + */ + protected Object processResponse(Object response, Class responseClass) { + // TODO: implement pluggable way to transform E4X XML into specific objects (eg SDO or AXIOM) + // } else if (response instanceof XMLObject) { + // response = E4XAXIOMUtils.toOMElement((XMLObject) response); + if (Context.getUndefinedValue().equals(response)) { + response = null; + } else if (response instanceof Wrapper) { + response = ((Wrapper) response).unwrap(); + } else { + if (responseClass != null) { + response = Context.toType(response, responseClass); + } else { + response = Context.toType(response, String.class); + } + } + return response; + } + + /** + * Create a Rhino scope and compile the script into it + */ + protected void initScriptScope(String fileName, String scriptCode, Map context) { + Context cx = Context.enter(); + try { + + this.scriptScope = cx.initStandardObjects(null, true); + Script compiledScript = cx.compileString(scriptCode, fileName, 1, null); + compiledScript.exec(cx, scriptScope); + addContexts(scriptScope, context); + + } finally { + Context.exit(); + } + } + + /** + * Initializes the shared scope + */ + protected void initSharedScope() { + Context cx = Context.enter(); + try { + + this.sharedScope = cx.newObject(scriptScope); + sharedScope.setPrototype(scriptScope); + sharedScope.setParentScope(null); + + } finally { + Context.exit(); + } + } + + /** + * Get a Rhino scope for the function invocation. If the invocation has no context objects then this will use the + * shared scope otherwise a new scope is created to hold the context objects. Any new variables the executing script + * might define will go in the sharedScope. This new scope is just to hold the invocation specific context objects. + */ + protected Scriptable getInvocationScope(Context cx, Map contexts) { + + Scriptable scope; + if (contexts == null || contexts.size() == 0) { + scope = sharedScope; + } else { + scope = cx.newObject(sharedScope); + scope.setPrototype(sharedScope); + scope.setParentScope(null); + addContexts(scope, contexts); + } + + return scope; + } + + /** + * Add the context to the scope. This will make the objects available to a script by using the name it was added + * with. + */ + protected void addContexts(Scriptable scope, Map contexts) { + if (contexts != null) { + for (Iterator i = contexts.keySet().iterator(); i.hasNext();) { + String name = (String) i.next(); + Object value = contexts.get(name); + if (value != null) { + scope.put(name, scope, Context.toObject(value, scope)); + } + } + } + } + + /** + * Get the Rhino Function object for the named script function + */ + protected Function getFunction(Scriptable scope, String functionName) { + + Object handleObj = scope.get(functionName, scope); + + if (!(handleObj instanceof Function)) { + throw new RuntimeException("script function '" + functionName + "' is undefined or not a function in script " + + scriptName); + } + + return (Function) handleObj; + } + + /** + * Make a copy of this RhinoScript object. This shares the script scope to avoid the overhead of recompiling the + * script, and to allow any initialization done by the script to be shared. + */ + public RhinoScript copy() { + return new RhinoScript(scriptName, script, scriptScope); + } + + /** + * Update the scope where the script is complied with new context values + * + * @param properties + */ + public void updateScriptScope(Map context) { + Context.enter(); + try { + addContexts(scriptScope, context); + } finally { + Context.exit(); + } + } + +}
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/rhino/RhinoTargetInvoker.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/rhino/RhinoTargetInvoker.java new file mode 100644 index 0000000000..62cf40f333 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/rhino/RhinoTargetInvoker.java @@ -0,0 +1,81 @@ +package org.apache.tuscany.container.js.rhino; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.invocation.Interceptor; +import org.apache.tuscany.core.invocation.TargetInvoker; +import org.apache.tuscany.core.message.Message; + +public class RhinoTargetInvoker implements TargetInvoker { + + private ScopeContext container; + + private QualifiedName name; + + private String operation; + + private RhinoScript target; + + public RhinoTargetInvoker(String serviceName, String operation, ScopeContext container) { + assert (serviceName != null) : "No service name specified"; + assert (container != null) : "No scope container specified"; + assert (operation != null) : "No operation specified"; + this.name = new QualifiedName(serviceName); + this.container = container; + this.operation = operation; + } + + public Object invokeTarget(Object payload) throws InvocationTargetException { + if (cacheable) { + if (target == null) { + target = (RhinoScript) container.getContext(name.getPartName()).getImplementationInstance(); + } + return target.invoke(operation, payload); + } else { + return ((RhinoScript) container.getContext(name.getPartName()).getImplementationInstance()) + .invoke(operation, payload); + } + } + + private boolean cacheable; + + public boolean isCacheable() { + return cacheable; + } + + public void setCacheable(boolean val) { + cacheable = val; + } + + public Message invoke(Message msg) { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setBody(e.getCause()); + } catch (Throwable e) { + msg.setBody(e); + } + return msg; + } + + public void setNext(Interceptor next) { + throw new IllegalStateException("This interceptor must be the last interceptor in an interceptor chain"); + } + + public Object clone() { + try { + RhinoTargetInvoker invoker = (RhinoTargetInvoker) super.clone(); + invoker.container = this.container; + invoker.cacheable = this.cacheable; + invoker.name = this.name; + invoker.operation = this.operation; + invoker.target = null; + return invoker; + } catch (CloneNotSupportedException e) { + return null; // will not happen + } + } +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/resources/model/sca-implementation-js.xsd b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/resources/model/sca-implementation-js.xsd new file mode 100644 index 0000000000..c68161d7bd --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/resources/model/sca-implementation-js.xsd @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:js="http://org.apache.tuscany/xmlns/js/0.9" + xmlns:sca="http://www.osoa.org/xmlns/sca/0.9" + elementFormDefault="qualified" + xmlns:sdojava="commonj.sdo/java" + sdojava:package="org.apache.tuscany.container.js.scdl" + targetNamespace="http://org.apache.tuscany/xmlns/js/0.9"> + + <import namespace="http://www.osoa.org/xmlns/sca/0.9" schemaLocation="../../../../../model/src/main/resources/model/sca-core.xsd"/> + + <element name="implementation.js" substitutionGroup="sca:implementation" type="js:JavaScriptImplementation"/> + + <complexType name="JavaScriptImplementation"> + <complexContent> + <extension base="sca:Implementation"> + <sequence> + <any maxOccurs="unbounded" minOccurs="0" namespace="##other" processContents="lax"/> + </sequence> + <attribute name="scriptFile" type="NCName" use="required"/> + <anyAttribute namespace="##any" processContents="lax"/> + </extension> + </complexContent> + </complexType> + +</schema> diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/resources/org/apache/tuscany/container/js/handler/JavaScriptComponentConfigurationHandler.componentType b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/resources/org/apache/tuscany/container/js/handler/JavaScriptComponentConfigurationHandler.componentType new file mode 100644 index 0000000000..c737a08a0b --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/resources/org/apache/tuscany/container/js/handler/JavaScriptComponentConfigurationHandler.componentType @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<componentType xmlns="http://www.osoa.org/xmlns/sca/0.9"> + + <service name="handler"> + <interface.js interface="org.apache.tuscany.core.message.handler.MessageHandler"/> + </service> + +</componentType> diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/resources/system.fragment b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/resources/system.fragment new file mode 100644 index 0000000000..4c17a7ac1c --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/resources/system.fragment @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed 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.
+ -->
+<moduleFragment xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9"
+ xmlns:system="http://org.apache.tuscany/xmlns/system/0.9" + name="org.apache.tuscany.container.js">
+
+ <component name="org.apache.tuscany.container.js.builder.JavaScriptComponentContextBuilder">
+ <system:implementation.system class="org.apache.tuscany.container.js.builder.JavaScriptComponentContextBuilder"/>
+ </component>
+
+ <component name="org.apache.tuscany.container.js.loader.JavaScriptSCDLModelLoader"> + <system:implementation.system class="org.apache.tuscany.container.js.loader.JavaScriptSCDLModelLoader"/> + </component> + + <component name="org.apache.tuscany.container.js.builder.JavaScriptTargetWireBuilder"> + <system:implementation.system class="org.apache.tuscany.container.js.builder.JavaScriptTargetWireBuilder"/> + </component> + +</moduleFragment>
diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/HelloWorld.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/HelloWorld.java new file mode 100644 index 0000000000..ed03753557 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/HelloWorld.java @@ -0,0 +1,7 @@ +package org.apache.tuscany.container.js.sample.helloworld; + +public interface HelloWorld { + + public String getGreeting(String s); + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/HelloWorldImpl.componentType b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/HelloWorldImpl.componentType new file mode 100644 index 0000000000..cce77fab00 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/HelloWorldImpl.componentType @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="ASCII"?> + +<componentType xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + + <service name="HelloWorldService"> + <interface.java interface="org.apache.tuscany.container.js.sample.helloworld.HelloWorld"/> + </service> + +</componentType>
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/HelloWorldImpl.js b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/HelloWorldImpl.js new file mode 100644 index 0000000000..cb63914377 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/HelloWorldImpl.js @@ -0,0 +1,4 @@ + +function getGreeting(s) { + return "jsHello " + s; +}
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/Main.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/Main.java new file mode 100644 index 0000000000..2e63a5a21e --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/org/apache/tuscany/container/js/sample/helloworld/Main.java @@ -0,0 +1,25 @@ +package org.apache.tuscany.container.js.sample.helloworld; + +import org.apache.tuscany.core.client.TuscanyRuntime; +import org.osoa.sca.CurrentModuleContext; +import org.osoa.sca.ModuleContext; + +public class Main { + + public static final void main(String[] args) throws Exception { + + TuscanyRuntime tuscany = new TuscanyRuntime("jsHello", null); + tuscany.start(); + ModuleContext moduleContext = CurrentModuleContext.getContext(); + + HelloWorld s = + (HelloWorld) moduleContext.locateService("HelloWorldJSComponent"); + + String value = s.getGreeting("Petra"); + + System.out.println(value); + + tuscany.stop(); + } + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/sca.module b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/sca.module new file mode 100644 index 0000000000..25c35fa6d0 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/samples/java/sca.module @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 BEA Sytems Inc. + Copyright (c) 2005 International Business Machines + + Licensed 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. + --> +<module xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9" + name="sampleHelloworld"> + + <component name="HelloWorldJSComponent"> + <implementation.js scriptFile="org/apache/tuscany/container/js/sample/helloworld/HelloWorldImpl.js"/> + </component> + +</module> diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptImplementationTestCase.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptImplementationTestCase.java new file mode 100644 index 0000000000..c751b0a2ef --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptImplementationTestCase.java @@ -0,0 +1,75 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.impl; + +import junit.framework.TestCase; + +/** + * FIXME commented out until SCDL loading works + * + * @version $Rev: 368822 $ $Date: 2006-01-13 18:54:38 +0000 (Fri, 13 Jan 2006) $ + */ +public class JavaScriptImplementationTestCase extends TestCase { + + private JavaScriptImplementationImpl impl = (JavaScriptImplementationImpl) new JavaScriptAssemblyFactoryImpl() + .createJavaScriptImplementation(); + + public void testDummy(){} // remove when tests added back + +// public void testNoImplementationClass() { +// impl.setScriptFile("no.such.script.js"); +// try { +// impl.initialize(new AssemblyModelContextImpl(null, null)); +// impl.getComponentType(); +// fail("Expected IllegalArgumentException"); +// } catch (IllegalArgumentException e) { +// // ok +// } +// } + +// public void testHelloWorldWithSidefile() { +// impl.setScriptFile("org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.js"); +// impl.initialize(new AssemblyModelContextImpl(new AssemblyLoaderImpl(), ResourceLoaderFactory.getResourceLoader(Thread +// .currentThread().getContextClassLoader()))); +// ComponentType type = impl.getComponentType(); +// Assert.assertNotNull(type); +// List<Property> props = type.getProperties(); +// Assert.assertEquals(1, props.size()); +// Assert.assertTrue(props.get(0).getName().equals("text")); +// +// Assert.assertTrue(type.getReferences().isEmpty()); +// +// List<Service> services = type.getServices(); +// Assert.assertEquals(1, services.size()); +// Assert.assertTrue(services.get(0).getName().equals("HelloWorldService")); +// } + + // static { + // // bootstrap this somehow + // AssemblyPackage.eINSTANCE.getClass(); + // } + + protected void setUp() throws Exception { + super.setUp(); + Thread.currentThread().setContextClassLoader(JavaScriptImplementationTestCase.class.getClassLoader()); + } + + protected void tearDown() throws Exception { + Thread.currentThread().setContextClassLoader(null); + super.tearDown(); + } +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/mock/HelloWorldService.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/mock/HelloWorldService.java new file mode 100644 index 0000000000..8edb27a473 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/mock/HelloWorldService.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.mock; + +/** + * @version $Rev: 368822 $ $Date: 2006-01-13 18:54:38 +0000 (Fri, 13 Jan 2006) $ + */ +public interface HelloWorldService { + String hello(String name); +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/JavaScriptAssemblyLoaderTestCase.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/JavaScriptAssemblyLoaderTestCase.java new file mode 100644 index 0000000000..91ce8a73eb --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/JavaScriptAssemblyLoaderTestCase.java @@ -0,0 +1,76 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.tests; + +import junit.framework.TestCase; + +import org.apache.tuscany.model.assembly.AssemblyFactory; +import org.apache.tuscany.model.assembly.AssemblyModelContext; +import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; +import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl; + +/** + */ +public class JavaScriptAssemblyLoaderTestCase extends TestCase { + + private AssemblyModelContext modelContext; + + /** + * + */ + public JavaScriptAssemblyLoaderTestCase() { + super(); + } + + public void testLoader() { +/* + + AssemblyLoader loader = modelContext.getAssemblyLoader(); + Module module = loader.getModule(getClass().getResource("sca.module").toString()); + module.initialize(modelContext); + + Assert.assertTrue(module.getName().equals("tuscany.container.js.assembly.tests.bigbank.account")); + + Component component = module.getComponent("AccountServiceComponent"); + Assert.assertTrue(component != null); + + EntryPoint entryPoint = module.getEntryPoint("AccountService"); + Assert.assertTrue(entryPoint != null); + + Object value = component.getConfiguredProperty("currency").getValue(); + Assert.assertTrue(value.equals("EURO")); + + ConfiguredService configuredService = component.getConfiguredReference("accountDataService").getConfiguredServices().get(0); + Assert.assertTrue(configuredService.getPart().getName().equals("AccountDataServiceComponent")); + + InterfaceType interfaceType = configuredService.getService().getInterfaceContract().getInterfaceType(); + OperationType operationType = interfaceType.getOperationType("getCheckingAccount"); + Type type = operationType.getInputType(); + Property arg = (Property) type.getProperties().get(0); + Assert.assertTrue(arg.getType().getInstanceClass() == String.class); +*/ + + } + + protected void setUp() throws Exception { + super.setUp(); + + Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); + modelContext = new AssemblyModelContextImpl(null,null); + } + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountReport.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountReport.java new file mode 100644 index 0000000000..90c47d400c --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountReport.java @@ -0,0 +1,32 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.tests.bigbank.account.services.account; + +import java.util.List; + +/** + * @model + */ + +public interface AccountReport { + + /** + * @model type="services.account.AccountSummary" + */ + + List getAccountSummaries(); +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountService.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountService.java new file mode 100644 index 0000000000..ff555e178f --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountService.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.tests.bigbank.account.services.account; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface AccountService { + + public AccountReport getAccountReport(String customerID); +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountSummary.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountSummary.java new file mode 100644 index 0000000000..ad3b4ad737 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountSummary.java @@ -0,0 +1,46 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.tests.bigbank.account.services.account; + +/** + * @model + */ + +public interface AccountSummary { + + /** + * @model + */ + String getAccountNumber(); + + void setAccountNumber(String accountNumber); + + /** + * @model + */ + String getAccountType(); + + void setAccountType(String accountType); + + /** + * @model + */ + float getBalance(); + + void setBalance(float balance); +} + diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/AccountDataService.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/AccountDataService.java new file mode 100644 index 0000000000..42d8994392 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/AccountDataService.java @@ -0,0 +1,26 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.tests.bigbank.account.services.accountdata; + +public interface AccountDataService { + + CheckingAccount getCheckingAccount(String customerID); + + SavingsAccount getSavingsAccount(String customerID); + + StockAccount getStockAccount(String customerID); +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.java new file mode 100644 index 0000000000..24b91020f7 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.java @@ -0,0 +1,48 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.tests.bigbank.account.services.accountdata; + +public class AccountDataServiceImpl implements AccountDataService { + + public CheckingAccount getCheckingAccount(String customerID) { + + CheckingAccount checkingAccount = new CheckingAccount(); + checkingAccount.setAccountNumber(customerID + "_" + "CHA12345"); + checkingAccount.setBalance(1500.0f); + + return checkingAccount; + } + + public SavingsAccount getSavingsAccount(String customerID) { + + SavingsAccount savingsAccount = new SavingsAccount(); + savingsAccount.setAccountNumber(customerID + "_" + "SAA12345"); + savingsAccount.setBalance(1500.0f); + + return savingsAccount; + } + + public StockAccount getStockAccount(String customerID) { + + StockAccount stockAccount = new StockAccount(); + stockAccount.setAccountNumber(customerID + "_" + "STA12345"); + stockAccount.setSymbol("IBM"); + stockAccount.setQuantity(100); + + return stockAccount; + } +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/CheckingAccount.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/CheckingAccount.java new file mode 100644 index 0000000000..43b755e0fb --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/CheckingAccount.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.tests.bigbank.account.services.accountdata; + +public class CheckingAccount { + + private String accountNumber; + private float balance; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public float getBalance() { + return balance; + } + + public void setBalance(float balance) { + this.balance = balance; + } +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/SavingsAccount.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/SavingsAccount.java new file mode 100644 index 0000000000..3f8cb65ad7 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/SavingsAccount.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.tests.bigbank.account.services.accountdata; + +public class SavingsAccount { + + private String accountNumber; + private float balance; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public float getBalance() { + return balance; + } + + public void setBalance(float balance) { + this.balance = balance; + } +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/StockAccount.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/StockAccount.java new file mode 100644 index 0000000000..ae6cdd6ff6 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/StockAccount.java @@ -0,0 +1,48 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.tests.bigbank.account.services.accountdata; + +public class StockAccount { + + private String accountNumber; + private String symbol; + private int quantity; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteService.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteService.java new file mode 100644 index 0000000000..8720bcdaf6 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteService.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.tests.bigbank.account.services.stockquote; + +public interface StockQuoteService { + + public float getQuote(String symbol); +} + +
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.java new file mode 100644 index 0000000000..9765b67c2f --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.assembly.tests.bigbank.account.services.stockquote; + +/* Dummy'd up StockQuoteService, override webservice for now */ + +public class StockQuoteServiceImpl implements StockQuoteService { + + public float getQuote(String symbol) { + // Just hardcode for now + return 83.00f; + } + +}
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl new file mode 100644 index 0000000000..01df4ef054 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<wsdl:definitions targetNamespace="http://webservice.stockquote" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservice.stockquote" xmlns:intf="http://webservice.stockquote" xmlns:tns1="http://stockquote" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name=""> + <!--WSDL created by Apache Axis version: 1.2.1 +Built on Jun 14, 2005 (09:15:57 EDT)--> + <wsdl:types> + <schema elementFormDefault="qualified" targetNamespace="http://stockquote" xmlns="http://www.w3.org/2001/XMLSchema"> + <complexType name="GetQuoteRequest"> + <sequence> + <element name="symbol" nillable="true" type="xsd:string"/> + </sequence> + </complexType> + <complexType name="GetQuoteResponse"> + <sequence> + <element name="price" type="xsd:float"/> + </sequence> + </complexType> + </schema> + <schema elementFormDefault="qualified" targetNamespace="http://webservice.stockquote" xmlns="http://www.w3.org/2001/XMLSchema"> + <import namespace="http://stockquote"/> + <element name="request" type="tns1:GetQuoteRequest"/> + <element name="getQuoteReturn" type="tns1:GetQuoteResponse"/> + </schema> + </wsdl:types> + + <wsdl:message name="getQuoteResponse"> + + <wsdl:part element="impl:getQuoteReturn" name="getQuoteReturn"/> + + </wsdl:message> + + <wsdl:message name="getQuoteRequest"> + + <wsdl:part element="impl:request" name="request"/> + + </wsdl:message> + + <wsdl:portType name="StockQuoteWebService"> + + <wsdl:operation name="getQuote" parameterOrder="request"> + + <wsdl:input message="impl:getQuoteRequest" name="getQuoteRequest"/> + + <wsdl:output message="impl:getQuoteResponse" name="getQuoteResponse"/> + + </wsdl:operation> + + </wsdl:portType> + + <wsdl:binding name="StockQuoteWebServiceSoapBinding" type="impl:StockQuoteWebService"> + + <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + + <wsdl:operation name="getQuote"> + + <wsdlsoap:operation soapAction=""/> + + <wsdl:input name="getQuoteRequest"> + + <wsdlsoap:body use="literal"/> + + </wsdl:input> + + <wsdl:output name="getQuoteResponse"> + + <wsdlsoap:body use="literal"/> + + </wsdl:output> + + </wsdl:operation> + + </wsdl:binding> + + <wsdl:service name="StockQuoteWebServiceService"> + + <wsdl:port binding="impl:StockQuoteWebServiceSoapBinding" name="StockQuoteWebService"> + + <wsdlsoap:address location="http://localhost:8123/StockQuoteWebService/services/StockQuoteWebService"/> + + </wsdl:port> + + </wsdl:service> + +</wsdl:definitions> diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/builder/JSComponentContextBuilderTestCase.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/builder/JSComponentContextBuilderTestCase.java new file mode 100644 index 0000000000..d21c17636a --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/builder/JSComponentContextBuilderTestCase.java @@ -0,0 +1,51 @@ +package org.apache.tuscany.container.js.builder; + +import java.util.Collection; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; +import org.apache.tuscany.container.js.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.js.config.JavaScriptComponentRuntimeConfiguration; +import org.apache.tuscany.container.js.mock.MockAssemblyFactory; +import org.apache.tuscany.core.builder.RuntimeConfiguration; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.InstanceContext; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.impl.EventContextImpl; +import org.apache.tuscany.core.context.scope.ModuleScopeContext; +import org.apache.tuscany.core.invocation.jdk.JDKProxyFactoryFactory; +import org.apache.tuscany.core.invocation.spi.ProxyFactory; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.SimpleComponent; +import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; +import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl; +import org.apache.tuscany.model.scdl.loader.impl.SCDLAssemblyModelLoaderImpl; + +public class JSComponentContextBuilderTestCase extends TestCase { + + public void testBasicInvocation() throws Exception { + JavaScriptComponentContextBuilder jsBuilder = new JavaScriptComponentContextBuilder(); + jsBuilder.setProxyFactoryFactory(new JDKProxyFactoryFactory()); + JavaScriptTargetWireBuilder jsWireBuilder = new JavaScriptTargetWireBuilder(); + SimpleComponent component = MockAssemblyFactory.createComponent("foo", + "org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.js", HelloWorldService.class, Scope.MODULE); + component.initialize(new AssemblyModelContextImpl(new AssemblyFactoryImpl(), new SCDLAssemblyModelLoaderImpl(null), new ResourceLoaderImpl(Thread.currentThread().getContextClassLoader()))); + jsBuilder.build(component, null); + ModuleScopeContext context = new ModuleScopeContext(new EventContextImpl()); + RuntimeConfiguration<InstanceContext> config = (RuntimeConfiguration) component.getComponentImplementation() + .getRuntimeConfiguration(); + context.registerConfiguration(config); + context.start(); + context.onEvent(EventContext.MODULE_START, null); + for (ProxyFactory proxyFactory : (Collection<ProxyFactory>) config.getTargetProxyFactories().values()) { + jsWireBuilder.completeTargetChain(proxyFactory, JavaScriptComponentRuntimeConfiguration.class, context); + proxyFactory.initialize(); + } + InstanceContext ctx = config.createInstanceContext(); + HelloWorldService hello = (HelloWorldService) ctx.getInstance(new QualifiedName("foo/HelloWorldService")); + Assert.assertNotNull(hello); + Assert.assertEquals("Hello foo", hello.hello("foo")); + } +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/builder/MockHandlerBuilder.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/builder/MockHandlerBuilder.java new file mode 100644 index 0000000000..5f5e8d769a --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/builder/MockHandlerBuilder.java @@ -0,0 +1,86 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.builder; + +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.invocation.InvocationConfiguration; +import org.apache.tuscany.core.invocation.MessageHandler; +import org.apache.tuscany.core.invocation.spi.ProxyFactory; +import org.apache.tuscany.model.assembly.AssemblyModelObject; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; + +/** + * Adds a handler to a source or target proxy configuration + * + * @version $Rev$ $Date$ + */ +public class MockHandlerBuilder implements RuntimeConfigurationBuilder { + + private MessageHandler handler; + + private boolean source; + + private boolean request; + + /** + * Creates the builder. + * + * @param handler the handler to add to the source or target proxy configuration + * @param source true if the handler should be added on the source side; false if the handler should be added to the + * target side + * @param request true if the handler is a request handler; false if the handler is a response handler + */ + public MockHandlerBuilder(MessageHandler handler, boolean source, boolean request) { + this.handler = handler; + this.source = source; + this.request = request; + } + + public void build(AssemblyModelObject modelObject, Context context) throws BuilderException { + if (source) { + if (!(modelObject instanceof ConfiguredReference)) { + return; + } else { + ConfiguredReference cref = (ConfiguredReference) modelObject; + ProxyFactory pFactory = (ProxyFactory) cref.getProxyFactory(); + for (InvocationConfiguration config : pFactory.getProxyConfiguration().getInvocationConfigurations().values()) { + if (request) { + config.addRequestHandler(handler); + } else { + config.addResponseHandler(handler); + } + } + } + } else { + if (!(modelObject instanceof ConfiguredService)) { + return; + } else { + ConfiguredService cservice = (ConfiguredService) modelObject; + ProxyFactory pFactory = (ProxyFactory) cservice.getProxyFactory(); + for (InvocationConfiguration config : pFactory.getProxyConfiguration().getInvocationConfigurations().values()) { + if (request) { + config.addRequestHandler(handler); + } else { + config.addResponseHandler(handler); + } + } + } + + } + } + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/builder/MockInterceptorBuilder.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/builder/MockInterceptorBuilder.java new file mode 100644 index 0000000000..0ed27101dd --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/builder/MockInterceptorBuilder.java @@ -0,0 +1,74 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.builder; + +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder; +import org.apache.tuscany.core.context.Context; +import org.apache.tuscany.core.invocation.Interceptor; +import org.apache.tuscany.core.invocation.InvocationConfiguration; +import org.apache.tuscany.core.invocation.spi.ProxyFactory; +import org.apache.tuscany.model.assembly.AssemblyModelObject; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; + +/** + * Adds an interceptor to a source or target proxy configuration + * + * @version $Rev$ $Date$ + */ +public class MockInterceptorBuilder implements RuntimeConfigurationBuilder { + + private Interceptor interceptor; + + private boolean source; + + /** + * Creates the builder + * + * @param interceptor the interceptor ot add + * @param source true if the interceptor should be added to the source side; false if the interceptor should be + * added to the target side + */ + public MockInterceptorBuilder(Interceptor interceptor, boolean source) { + this.interceptor = interceptor; + this.source = source; + } + + public void build(AssemblyModelObject modelObject, Context context) throws BuilderException { + if (source) { + if (!(modelObject instanceof ConfiguredReference)) { + return; + } else { + ConfiguredReference cref = (ConfiguredReference) modelObject; + ProxyFactory pFactory = (ProxyFactory) cref.getProxyFactory(); + for (InvocationConfiguration config : pFactory.getProxyConfiguration().getInvocationConfigurations().values()) { + config.addSourceInterceptor(interceptor); + } + } + } else { + if (!(modelObject instanceof ConfiguredService)) { + return; + } else { + ConfiguredService cservice = (ConfiguredService) modelObject; + ProxyFactory pFactory = (ProxyFactory) cservice.getProxyFactory(); + for (InvocationConfiguration config : pFactory.getProxyConfiguration().getInvocationConfigurations().values()) { + config.addTargetInterceptor(interceptor); + } + } + + } + } + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/config/ModuleComponentConfigurationLoaderTestCase.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/config/ModuleComponentConfigurationLoaderTestCase.java new file mode 100644 index 0000000000..4f9ba1ab49 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/config/ModuleComponentConfigurationLoaderTestCase.java @@ -0,0 +1,78 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.config; + +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; +import org.apache.tuscany.container.js.assembly.impl.JavaScriptImplementationImpl; +import org.apache.tuscany.container.js.loader.JavaScriptSCDLModelLoader; +import org.apache.tuscany.core.config.ConfigurationException; +import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader; +import org.apache.tuscany.core.config.impl.ModuleComponentConfigurationLoaderImpl; +import org.apache.tuscany.model.assembly.AssemblyModelContext; +import org.apache.tuscany.model.assembly.Component; +import org.apache.tuscany.model.assembly.ComponentImplementation; +import org.apache.tuscany.model.assembly.Module; +import org.apache.tuscany.model.assembly.ModuleComponent; +import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; +import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl; +import org.apache.tuscany.model.assembly.loader.AssemblyModelLoader; +import org.apache.tuscany.model.scdl.loader.SCDLModelLoader; +import org.apache.tuscany.model.scdl.loader.impl.SCDLAssemblyModelLoaderImpl; + +/** + * @version $Rev: 368822 $ $Date: 2006-01-13 18:54:38 +0000 (Fri, 13 Jan 2006) $ + */ +public class ModuleComponentConfigurationLoaderTestCase extends TestCase { + private ModuleComponentConfigurationLoader loader; + + public void testFoo() throws ConfigurationException { + URL xml = ModuleComponentConfigurationLoaderTestCase.class.getResource("ModuleComponentLoaderTest1.module"); + ModuleComponent moduleComponent = loader.loadModuleComponent("test", "test", xml.toString()); + Assert.assertEquals("test", moduleComponent.getName()); + Module module = moduleComponent.getModuleImplementation(); + Assert.assertEquals("ModuleComponentLoaderTest1", module.getName()); + List<Component> components = module.getComponents(); + Assert.assertEquals(1, components.size()); + Component component = components.get(0); + Assert.assertEquals("HelloWorldServiceComponent", component.getName()); + + component = module.getComponent("HelloWorldServiceComponent"); + Assert.assertEquals("HelloWorldServiceComponent", component.getName()); + + ComponentImplementation implementation = component.getComponentImplementation(); + Assert.assertTrue(implementation instanceof JavaScriptImplementationImpl); + } + + protected void setUp() throws Exception { + super.setUp(); + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + List<SCDLModelLoader> scdlLoaders=new ArrayList<SCDLModelLoader>(); + JavaScriptSCDLModelLoader jsLoader=new JavaScriptSCDLModelLoader(); + scdlLoaders.add(jsLoader); + AssemblyModelLoader modelLoader=new SCDLAssemblyModelLoaderImpl(scdlLoaders); + AssemblyModelContext modelContext=new AssemblyModelContextImpl( + new AssemblyFactoryImpl(), modelLoader,new ResourceLoaderImpl(this.getClass().getClassLoader())); + loader = new ModuleComponentConfigurationLoaderImpl(modelContext); + } +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/integration/JSComponentContextTestCase.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/integration/JSComponentContextTestCase.java new file mode 100644 index 0000000000..cd29f59327 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/integration/JSComponentContextTestCase.java @@ -0,0 +1,91 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.integration; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.container.js.assembly.mock.HelloWorldService; +import org.apache.tuscany.container.js.builder.JavaScriptComponentContextBuilder; +import org.apache.tuscany.container.js.builder.JavaScriptTargetWireBuilder; +import org.apache.tuscany.container.js.builder.MockInterceptorBuilder; +import org.apache.tuscany.container.js.invocation.mock.MockSyncInterceptor; +import org.apache.tuscany.container.js.mock.MockAssemblyFactory; +import org.apache.tuscany.container.js.mock.MockModuleFactory; +import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.builder.impl.HierarchicalBuilder; +import org.apache.tuscany.core.context.AggregateContext; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.impl.AggregateContextImpl; +import org.apache.tuscany.core.invocation.jdk.JDKProxyFactoryFactory; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.message.impl.MessageFactoryImpl; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.runtime.RuntimeContextImpl; +import org.apache.tuscany.core.system.builder.SystemComponentContextBuilder; +import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder; +import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder; +import org.apache.tuscany.model.assembly.Scope; + +/** + * Integration tests for JavaScript components and aggregate contexts + * + * @version $Rev$ $Date$ + */ +public class JSComponentContextTestCase extends TestCase { + + public void testBasicInvocation() throws Exception { + MessageFactory msgFactory = new MessageFactoryImpl(); + + List<RuntimeConfigurationBuilder> builders = new ArrayList(); + builders.add((new SystemComponentContextBuilder())); + builders.add(new SystemEntryPointBuilder()); + builders.add(new SystemExternalServiceBuilder()); + + JavaScriptComponentContextBuilder javaBuilder = new JavaScriptComponentContextBuilder(); + javaBuilder.setMessageFactory(msgFactory); + javaBuilder.setProxyFactoryFactory(new JDKProxyFactoryFactory()); + + MockSyncInterceptor mockInterceptor = new MockSyncInterceptor(); + MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, true); + HierarchicalBuilder refBuilder = new HierarchicalBuilder(); + refBuilder.addBuilder(interceptorBuilder); + javaBuilder.setReferenceBuilder(refBuilder); + builders.add(javaBuilder); + + DefaultWireBuilder defaultWireBuilder = new DefaultWireBuilder(); + + RuntimeContext runtime = new RuntimeContextImpl(null, null, builders, defaultWireBuilder); + runtime.addBuilder(new JavaScriptTargetWireBuilder()); + runtime.start(); + runtime.getRootContext().registerModelObject( + MockAssemblyFactory.createSystemComponent("test.module", AggregateContextImpl.class.getName(), + Scope.AGGREGATE)); + AggregateContext child = (AggregateContext) runtime.getRootContext().getContext("test.module"); + child.registerModelObject(MockModuleFactory.createModule()); + child.fireEvent(EventContext.MODULE_START, null); + HelloWorldService source = (HelloWorldService) child.locateInstance("source/HelloWorldService"); + Assert.assertNotNull(source); + Assert.assertEquals("Hello foo",source.hello("foo")); + //Assert.assertEquals(1, mockInterceptor.getCount()); + child.fireEvent(EventContext.MODULE_STOP, null); + runtime.stop(); + } + +} + diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/invocation/mock/MockHandler.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/invocation/mock/MockHandler.java new file mode 100644 index 0000000000..7064ec5d65 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/invocation/mock/MockHandler.java @@ -0,0 +1,27 @@ +/** + * + */ +package org.apache.tuscany.container.js.invocation.mock; + +import org.apache.tuscany.core.invocation.MessageHandler; +import org.apache.tuscany.core.message.Message; + +/** + * A test handler + * + * @version $Rev$ $Date$ + */ +public class MockHandler implements MessageHandler { + + private int count =0; + + public boolean processMessage(Message message) { + //System.out.println("Invoking handler"); + count++; + return true; + } + + public int getCount(){ + return count; + } +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/invocation/mock/MockSyncInterceptor.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/invocation/mock/MockSyncInterceptor.java new file mode 100644 index 0000000000..caab4b3756 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/invocation/mock/MockSyncInterceptor.java @@ -0,0 +1,50 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.invocation.mock; + +import org.apache.tuscany.core.invocation.Interceptor; +import org.apache.tuscany.core.message.Message; + +/** + * A test interceptor + * + * @version $Rev$ $Date$ + */ +public class MockSyncInterceptor implements Interceptor { + + private int count; + + private Interceptor next; + + public MockSyncInterceptor() { + } + + public Message invoke(Message msg) { + ++count; + //System.out.println("Invoking interceptor"); + return next.invoke(msg); + } + + public int getCount() { + return count; + } + + public void setNext(Interceptor next) { + this.next=next; + } +} + diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/mock/MockAssemblyFactory.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/mock/MockAssemblyFactory.java new file mode 100644 index 0000000000..5cb80b29aa --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/mock/MockAssemblyFactory.java @@ -0,0 +1,156 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.mock; + +import org.apache.tuscany.container.js.assembly.JavaScriptAssemblyFactory; +import org.apache.tuscany.container.js.assembly.JavaScriptImplementation; +import org.apache.tuscany.container.js.assembly.impl.JavaScriptAssemblyFactoryImpl; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.context.AggregateContext; +import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; +import org.apache.tuscany.core.system.assembly.SystemImplementation; +import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; +import org.apache.tuscany.model.assembly.AssemblyModelContext; +import org.apache.tuscany.model.assembly.Component; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.assembly.SimpleComponent; +import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl; +import org.apache.tuscany.model.types.java.JavaServiceContract; + +/** + * Generates test components and module assemblies + * + * @version $Rev: 377775 $ $Date: 2006-02-14 09:18:31 -0800 (Tue, 14 Feb 2006) $ + */ +public class MockAssemblyFactory { + + private static JavaScriptAssemblyFactory factory = new JavaScriptAssemblyFactoryImpl(); + + private static SystemAssemblyFactory systemFactory = new SystemAssemblyFactoryImpl(); + + public static SimpleComponent createComponent(String name, String scriptFile, Class type, Scope scope) { + SimpleComponent sc = factory.createSimpleComponent(); + JavaScriptImplementation impl = factory.createJavaScriptImplementation(); + impl.setComponentType(factory.createComponentType()); + impl.setScriptFile(scriptFile); + sc.setComponentImplementation(impl); + Service s = factory.createService(); + String serviceName = type.getName().substring(type.getName().lastIndexOf('.')+1); + s.setName(serviceName); + JavaServiceContract contract = factory.createJavaServiceContract(); + s.setServiceContract(contract); + contract.setScope(scope); + contract.setInterface(type); + impl.getComponentType().getServices().add(s); + ConfiguredService cService = factory.createConfiguredService(); + cService.setService(s); + cService.initialize(new AssemblyModelContextImpl(null,null)); + sc.getConfiguredServices().add(cService); + sc.setName(name); + sc.setComponentImplementation(impl); + return sc; + } + + public static Component createSystemComponent(String name, String type, Scope scope) throws NoSuchMethodException, + ClassNotFoundException { + Class claz = JavaIntrospectionHelper.loadClass(type); + Component sc = null; + if (AggregateContext.class.isAssignableFrom(claz)) { + sc = systemFactory.createModuleComponent(); + } else { + sc = systemFactory.createSimpleComponent(); + } + SystemImplementation impl = systemFactory.createSystemImplementation(); + impl.setImplementationClass(claz); + sc.setComponentImplementation(impl); + Service s = systemFactory.createService(); + JavaServiceContract ji = systemFactory.createJavaServiceContract(); + s.setServiceContract(ji); + ji.setScope(scope); + impl.setComponentType(systemFactory.createComponentType()); + impl.getComponentType().getServices().add(s); + sc.setName(name); + sc.setComponentImplementation(impl); + return sc; + } + + // public static SimpleComponent createComponent(String name, String scriptFile, String serviceName, ScopeEnum + // scope) + // throws NoSuchMethodException, ClassNotFoundException { + // SimpleComponent sc = new PojoSimpleComponent(); + // PojoJavaScriptImplementation impl = new PojoJavaScriptImplementation(); + // impl.setScriptFile(scriptFile); + // impl.initialize(new AssemblyModelContextImpl()); + // + // sc.setComponentImplementation(impl); + // Service s = new PojoService(); + // s.setName(serviceName.substring(serviceName.lastIndexOf('.') + 1)); + // PojoJavaInterface ji = new PojoJavaInterface(); + // ji.setInterface(serviceName); + // Class claz = JavaIntrospectionHelper.loadClass(serviceName); + // PojoInterfaceType iType = new PojoInterfaceType(); + // iType.setInstanceClass(claz); + // for (Method m : claz.getMethods()) { + // // assume no method overloading + // PojoOperationType type = new PojoOperationType(); + // type.setName(m.getName()); + // for (Class inputType : m.getParameterTypes()) { + // type.setOutputType(new SDOType(null,null,inputType,Collections.EMPTY_LIST)); + // } + // iType.addOperationType(type); + // } + // ji.setInterfaceType(iType); + // + // + // s.setInterfaceContract(ji); + // ji.setScope(scope); + // impl.getServices().add(s); + // sc.setName(name); + // sc.setComponentImplementation(impl); + // PojoConfiguredService cService = new PojoConfiguredService(); + // cService.setService(s); + // sc.getConfiguredServices().add(cService); + // return sc; + // } + // + // public static Component createSystemComponent(String name, String type, ScopeEnum scope) throws + // NoSuchMethodException, + // ClassNotFoundException { + // + // Class claz = JavaIntrospectionHelper.loadClass(type); + // PojoComponent sc = null; + // if (AggregateContext.class.isAssignableFrom(claz)) { + // sc = new PojoAggregateComponent(); + // } else { + // sc = new PojoSimpleComponent(); + // } + // SystemImplementation impl = new PojoSystemImplementation(); + // impl.setClass(type); + // sc.setComponentImplementation(impl); + // Service s = new PojoService(); + // JavaInterface ji = new PojoJavaInterface(); + // s.setInterfaceContract(ji); + // ji.setScope(scope); + // impl.getServices().add(s); + // sc.setName(name); + // sc.setComponentImplementation(impl); + // return sc; + // } + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/mock/MockModuleFactory.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/mock/MockModuleFactory.java new file mode 100644 index 0000000000..fe66104000 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/mock/MockModuleFactory.java @@ -0,0 +1,115 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.js.mock; + +import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; +import org.apache.tuscany.container.js.assembly.mock.HelloWorldService; +import org.apache.tuscany.model.assembly.AssemblyFactory; +import org.apache.tuscany.model.assembly.AssemblyModelContext; +import org.apache.tuscany.model.assembly.Component; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.Module; +import org.apache.tuscany.model.assembly.Reference; +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; +import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl; +import org.apache.tuscany.model.scdl.loader.impl.SCDLAssemblyModelLoaderImpl; +import org.apache.tuscany.model.types.java.JavaServiceContract; + +/** + * Generates mock modules + * + * @version $Rev$ $Date$ + */ +public class MockModuleFactory { + + private static AssemblyFactory factory = new AssemblyFactoryImpl(); + + private static AssemblyModelContext assemblyContext = new AssemblyModelContextImpl(new AssemblyFactoryImpl(), + new SCDLAssemblyModelLoaderImpl(null), new ResourceLoaderImpl(Thread.currentThread().getContextClassLoader())); + + private MockModuleFactory() { + } + + public static Module createModule() throws Exception { + Component sourceComponent = MockAssemblyFactory.createComponent("source", + "org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.js", HelloWorldService.class, Scope.MODULE); + Component targetComponent = MockAssemblyFactory.createComponent("target", + "org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.js", HelloWorldService.class, Scope.MODULE); + + Service targetService = factory.createService(); + JavaServiceContract targetContract = factory.createJavaServiceContract(); + targetContract.setInterface(HelloWorldService.class); + targetService.setServiceContract(targetContract); + targetService.setName("GenericComponent"); + ConfiguredService cTargetService = factory.createConfiguredService(); + cTargetService.setService(targetService); + cTargetService.initialize(assemblyContext); + targetComponent.getConfiguredServices().add(cTargetService); + targetComponent.initialize(assemblyContext); + + Reference ref = factory.createReference(); + ConfiguredReference cref = factory.createConfiguredReference(); + ref.setName("setGenericComponent"); + JavaServiceContract inter = factory.createJavaServiceContract(); + inter.setInterface(HelloWorldService.class); + ref.setServiceContract(inter); + cref.setReference(ref); + cref.getTargetConfiguredServices().add(cTargetService); + cref.initialize(assemblyContext); + sourceComponent.getConfiguredReferences().add(cref); + sourceComponent.initialize(assemblyContext); + + Module module = factory.createModule(); + module.setName("test.module"); + module.getComponents().add(sourceComponent); + module.getComponents().add(targetComponent); + module.initialize(assemblyContext); + return module; + } + + // public static Module createModule() throws Exception { + // Component sourceComponent = + // MockAssemblyFactory.createComponent("source","org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.js",HelloWorldService.class.getCanonicalName(),ScopeEnum.MODULE_LITERAL); + // Component targetComponent = + // MockAssemblyFactory.createComponent("target","org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.js",HelloWorldService.class.getCanonicalName(),ScopeEnum.MODULE_LITERAL); + // PojoReference ref = new PojoReference(); + // PojoConfiguredReference cref = new PojoConfiguredReference(); + // ref.setName("helloWorld"); + // PojoInterface inter = new PojoJavaInterface(); + // PojoInterfaceType type = new PojoInterfaceType(); + // type.setInstanceClass(HelloWorldService.class); + // PojoOperationType oType = new PojoOperationType(); + // oType.setName("hello"); + // SDOType inputType = new SDOType("String","",String.class,null); + // oType.setInputType(inputType); + // type.addOperationType(oType); + // inter.setInterfaceType(type); + // ref.setInterfaceContract(inter); + // cref.setReference(ref); + // cref.setPart(targetComponent); + // PojoPort port = new PojoPort(); + // port.setName("HelloWorldService"); + // cref.setPort(port); + // sourceComponent.getConfiguredReferences().add(cref); + // PojoModule module = new PojoModule(); + // module.setName("test.module"); + // module.addComponent(sourceComponent); + // module.addComponent(targetComponent); + // return module; + // } + +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/rhino/RhinoInvokerTestCase.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/rhino/RhinoInvokerTestCase.java new file mode 100644 index 0000000000..9269c1cf7e --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/rhino/RhinoInvokerTestCase.java @@ -0,0 +1,184 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + * + * Licensed 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.js.rhino; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import org.mozilla.javascript.EcmaError; + +/** + * Tests for the RhinoInvoker + */ +public class RhinoInvokerTestCase extends TestCase { + + private static final String scriptName = "RhinoInvokerTestCase.js"; + private String script; + + protected void setUp() throws Exception { + super.setUp(); + this.script = readResource(scriptName); + } + + public void testSimpleInvocation() { + RhinoScript ri = new RhinoScript(scriptName, script); + Object x = ri.invoke("echo", "petra", null); + assertEquals("petra", x); + } + + public void testCopy() { + RhinoScript ri = new RhinoScript(scriptName, script); + Object x = ri.invoke("echo", "petra", null); + assertEquals("petra", x); + + ri = ri.copy(); + x = ri.invoke("echo", "sue", null); + assertEquals("sue", x); + + } + + public void testContexts1() { + RhinoScript ri = new RhinoScript(scriptName, script); + Map<String, Object> contexts = new HashMap<String, Object>(); + contexts.put("a", "petra"); + Object x = ri.invoke("getA", null, contexts); + assertEquals("petra", x); + } + + /** + * Tests context not accessable across invocations + */ + public void testContexts2() { + RhinoScript ri = new RhinoScript(scriptName, script); + Map<String, Object> contexts = new HashMap<String, Object>(); + contexts.put("a", "petra"); + Object x = ri.invoke("getA", null, contexts); + assertEquals("petra", x); + + try { + x = ri.invoke("getA", null, null); + assertTrue("expected ReferenceError", false); + } catch (EcmaError e) { + assertEquals("ReferenceError", e.getName()); + } + } + + /** + * Tests shared scope is accessable across invocations + */ + public void testScopes1() { + RhinoScript ri = new RhinoScript(scriptName, script); + ri.invoke("setGlobalVarY", "petra", null); + + Object x = ri.invoke("getGlobalVarY", null, null); + assertEquals("petra", x); + } + + /** + * Tests local vars are NOT accessable across invocations + */ + public void testScopes2() { + RhinoScript ri = new RhinoScript(scriptName, script); + ri.invoke("setLocalVarY", "petra", null); + + try { + ri.invoke("getGlobalVarY", null, null); + assertTrue("expected ReferenceError", false); + } catch (EcmaError e) { + assertEquals("ReferenceError", e.getName()); + } + } + + /** + * Tests shared scope is accessable when using contexts (ie an invocation scope) + */ + public void testScopes3() { + RhinoScript ri = new RhinoScript(scriptName, script); + ri.invoke("setGlobalVarY", "petra", null); + + Map<String, Object> contexts = new HashMap<String, Object>(); + contexts.put("a", "sue"); + Object x = ri.invoke("getGlobalVarY", null, contexts); + assertEquals("petra", x); + + x = ri.invoke("getA", null, contexts); + assertEquals("sue", x); + + } + + /** + * Tests a copy only retains the script scope not the shared scope + */ + public void testScopes4() { + RhinoScript ri = new RhinoScript(scriptName, script); + ri.invoke("setGlobalVarY", "petra", null); + + ri = ri.copy(); + try { + ri.invoke("getGlobalVarY", null, null); + assertTrue("expected ReferenceError", false); + } catch (EcmaError e) { + assertEquals("ReferenceError", e.getName()); + } + try { + ri.invoke("getA", null, null); + assertTrue("expected ReferenceError", false); + } catch (EcmaError e) { + assertEquals("ReferenceError", e.getName()); + } + + } + + public void testGetInt() { + RhinoScript ri = new RhinoScript(scriptName, script); + Object x = ri.invoke("getInt", null, Integer.TYPE, null); + assertEquals(Integer.class, x.getClass()); + } + + /** + * Read a resource into a String + */ + private String readResource(String name) { + try { + URL url = getClass().getResource(name); + if (url == null) { + throw new RuntimeException("resource not found: " + name); + } + InputStream inputStream = url.openStream(); + + StringBuffer resource = new StringBuffer(); + int n = 0; + + while ((n = inputStream.read()) != -1) { + resource.append((char) n); + } + + inputStream.close(); + + String s = resource.toString(); + return s; + + } catch (IOException e) { + throw new RuntimeException("IOException reading resource " + name, e); + } + } + +}
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.componentType b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.componentType new file mode 100644 index 0000000000..3e9bb5bc28 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.componentType @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<componentType xmlns="http://www.osoa.org/xmlns/sca/0.9" + xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <service name="HelloWorldService"> + <interface.java interface="org.apache.tuscany.container.js.assembly.mock.HelloWorldService" remoteable="true"/> + </service> + <property name="text" type="xsd:string"/> +</componentType>
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.js b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.js new file mode 100644 index 0000000000..6c5f697040 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/mock/HelloWorldImpl.js @@ -0,0 +1,4 @@ + +function hello(name) { + return "Hello " + name; +} diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/AccountService.wsdl b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/AccountService.wsdl new file mode 100644 index 0000000000..ecd07d3934 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/AccountService.wsdl @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" + xmlns:tns="http://www.bigbank.com/AccountService/" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.bigbank.com/AccountService/" + + name="AccountService"> + + <wsdl:types> + <xsd:schema targetNamespace="http://www.bigbank.com/AccountService/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + + <xsd:element name="customerID" type="xsd:string"/> + <xsd:element name="getAccountReportResponse" type="tns:AccountReport"/> + + <xsd:complexType name="AccountReport"> + <xsd:sequence> + <xsd:element name="accountSummary" type="tns:AccountSummary" maxOccurs="unbounded"/> + </xsd:sequence> + </xsd:complexType> + <xsd:complexType name="AccountSummary"> + <xsd:sequence> + <xsd:element name="accountNumber" type="xsd:string"/> + <xsd:element name="accountType" type="xsd:string"/> + <xsd:element name="balance" type="xsd:float"/> + </xsd:sequence> + </xsd:complexType> + + </xsd:schema> + </wsdl:types> + <wsdl:message name="getAccountReportRequest"> + <wsdl:part element="tns:customerID" name="getAccountReportRequest"/> + </wsdl:message> + <wsdl:message name="getAccountReportResponse"> + <wsdl:part element="tns:getAccountReportResponse" name="getAccountReportResponse"/> + </wsdl:message> + <wsdl:portType name="AccountService"> + <wsdl:operation name="getAccountReport"> + <wsdl:input message="tns:getAccountReportRequest"/> + <wsdl:output message="tns:getAccountReportResponse"/> + </wsdl:operation> + </wsdl:portType> + <wsdl:binding name="AccountServiceSOAP" type="tns:AccountService"> + <soap:binding style="document" + transport="http://schemas.xmlsoap.org/soap/http"/> + <wsdl:operation name="getAccountReport"> + <soap:operation + soapAction="http://www.bigbank.com/AccountService/getAccountReport"/> + <wsdl:input> + <soap:body use="literal"/> + </wsdl:input> + <wsdl:output> + <soap:body use="literal"/> + </wsdl:output> + </wsdl:operation> + </wsdl:binding> + <wsdl:service name="AccountService"> + <wsdl:port binding="tns:AccountServiceSOAP" + name="AccountServiceSOAP"> + <soap:address location=""/> + </wsdl:port> + </wsdl:service> +</wsdl:definitions> diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/AccountServiceImpl.componentType b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/AccountServiceImpl.componentType new file mode 100644 index 0000000000..9f75ba9134 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/AccountServiceImpl.componentType @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="ASCII"?> + +<componentType xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + + <service name="test1MediatorService"> + <interface.java interface="org.apache.tuscany.container.js.assembly.tests.bigbank.account.services.account.AccountService"/> + </service> + + <reference name="accountDataService"> + <interface.java interface="org.apache.tuscany.container.js.assembly.tests.bigbank.account.services.accountdata.AccountDataService"/> + </reference> + + <reference name="stockQuoteService"> + <interface.java interface="org.apache.tuscany.container.js.assembly.tests.bigbank.account.services.stockquote.StockQuoteService"/> + </reference> + + <property name="currency" type="xsd:string" default="USD"/> + +</componentType>
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountService.wsdl b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountService.wsdl new file mode 100644 index 0000000000..ecd07d3934 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountService.wsdl @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" + xmlns:tns="http://www.bigbank.com/AccountService/" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.bigbank.com/AccountService/" + + name="AccountService"> + + <wsdl:types> + <xsd:schema targetNamespace="http://www.bigbank.com/AccountService/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + + <xsd:element name="customerID" type="xsd:string"/> + <xsd:element name="getAccountReportResponse" type="tns:AccountReport"/> + + <xsd:complexType name="AccountReport"> + <xsd:sequence> + <xsd:element name="accountSummary" type="tns:AccountSummary" maxOccurs="unbounded"/> + </xsd:sequence> + </xsd:complexType> + <xsd:complexType name="AccountSummary"> + <xsd:sequence> + <xsd:element name="accountNumber" type="xsd:string"/> + <xsd:element name="accountType" type="xsd:string"/> + <xsd:element name="balance" type="xsd:float"/> + </xsd:sequence> + </xsd:complexType> + + </xsd:schema> + </wsdl:types> + <wsdl:message name="getAccountReportRequest"> + <wsdl:part element="tns:customerID" name="getAccountReportRequest"/> + </wsdl:message> + <wsdl:message name="getAccountReportResponse"> + <wsdl:part element="tns:getAccountReportResponse" name="getAccountReportResponse"/> + </wsdl:message> + <wsdl:portType name="AccountService"> + <wsdl:operation name="getAccountReport"> + <wsdl:input message="tns:getAccountReportRequest"/> + <wsdl:output message="tns:getAccountReportResponse"/> + </wsdl:operation> + </wsdl:portType> + <wsdl:binding name="AccountServiceSOAP" type="tns:AccountService"> + <soap:binding style="document" + transport="http://schemas.xmlsoap.org/soap/http"/> + <wsdl:operation name="getAccountReport"> + <soap:operation + soapAction="http://www.bigbank.com/AccountService/getAccountReport"/> + <wsdl:input> + <soap:body use="literal"/> + </wsdl:input> + <wsdl:output> + <soap:body use="literal"/> + </wsdl:output> + </wsdl:operation> + </wsdl:binding> + <wsdl:service name="AccountService"> + <wsdl:port binding="tns:AccountServiceSOAP" + name="AccountServiceSOAP"> + <soap:address location=""/> + </wsdl:port> + </wsdl:service> +</wsdl:definitions> diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountServiceImpl.componentType b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountServiceImpl.componentType new file mode 100644 index 0000000000..9f75ba9134 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountServiceImpl.componentType @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="ASCII"?> + +<componentType xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + + <service name="test1MediatorService"> + <interface.java interface="org.apache.tuscany.container.js.assembly.tests.bigbank.account.services.account.AccountService"/> + </service> + + <reference name="accountDataService"> + <interface.java interface="org.apache.tuscany.container.js.assembly.tests.bigbank.account.services.accountdata.AccountDataService"/> + </reference> + + <reference name="stockQuoteService"> + <interface.java interface="org.apache.tuscany.container.js.assembly.tests.bigbank.account.services.stockquote.StockQuoteService"/> + </reference> + + <property name="currency" type="xsd:string" default="USD"/> + +</componentType>
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.componentType b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.componentType new file mode 100644 index 0000000000..0217420bea --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.componentType @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="ASCII"?> + +<componentType xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + + <service name="AccountDataService"> + <interface.java interface="org.apache.tuscany.container.js.assembly.tests.bigbank.account.services.accountdata.AccountDataService"/> + </service> + +</componentType>
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.componentType b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.componentType new file mode 100644 index 0000000000..e67876ba35 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.componentType @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="ASCII"?> + +<componentType xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + + <service name="StockQuoteService"> + <interface.java interface="org.apache.tuscany.container.js.assembly.tests.bigbank.account.services.stockquote.StockQuoteService"/> + </service> + +</componentType>
\ No newline at end of file diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl new file mode 100644 index 0000000000..01df4ef054 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteWebService.wsdl @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<wsdl:definitions targetNamespace="http://webservice.stockquote" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservice.stockquote" xmlns:intf="http://webservice.stockquote" xmlns:tns1="http://stockquote" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name=""> + <!--WSDL created by Apache Axis version: 1.2.1 +Built on Jun 14, 2005 (09:15:57 EDT)--> + <wsdl:types> + <schema elementFormDefault="qualified" targetNamespace="http://stockquote" xmlns="http://www.w3.org/2001/XMLSchema"> + <complexType name="GetQuoteRequest"> + <sequence> + <element name="symbol" nillable="true" type="xsd:string"/> + </sequence> + </complexType> + <complexType name="GetQuoteResponse"> + <sequence> + <element name="price" type="xsd:float"/> + </sequence> + </complexType> + </schema> + <schema elementFormDefault="qualified" targetNamespace="http://webservice.stockquote" xmlns="http://www.w3.org/2001/XMLSchema"> + <import namespace="http://stockquote"/> + <element name="request" type="tns1:GetQuoteRequest"/> + <element name="getQuoteReturn" type="tns1:GetQuoteResponse"/> + </schema> + </wsdl:types> + + <wsdl:message name="getQuoteResponse"> + + <wsdl:part element="impl:getQuoteReturn" name="getQuoteReturn"/> + + </wsdl:message> + + <wsdl:message name="getQuoteRequest"> + + <wsdl:part element="impl:request" name="request"/> + + </wsdl:message> + + <wsdl:portType name="StockQuoteWebService"> + + <wsdl:operation name="getQuote" parameterOrder="request"> + + <wsdl:input message="impl:getQuoteRequest" name="getQuoteRequest"/> + + <wsdl:output message="impl:getQuoteResponse" name="getQuoteResponse"/> + + </wsdl:operation> + + </wsdl:portType> + + <wsdl:binding name="StockQuoteWebServiceSoapBinding" type="impl:StockQuoteWebService"> + + <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + + <wsdl:operation name="getQuote"> + + <wsdlsoap:operation soapAction=""/> + + <wsdl:input name="getQuoteRequest"> + + <wsdlsoap:body use="literal"/> + + </wsdl:input> + + <wsdl:output name="getQuoteResponse"> + + <wsdlsoap:body use="literal"/> + + </wsdl:output> + + </wsdl:operation> + + </wsdl:binding> + + <wsdl:service name="StockQuoteWebServiceService"> + + <wsdl:port binding="impl:StockQuoteWebServiceSoapBinding" name="StockQuoteWebService"> + + <wsdlsoap:address location="http://localhost:8123/StockQuoteWebService/services/StockQuoteWebService"/> + + </wsdl:port> + + </wsdl:service> + +</wsdl:definitions> diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/sca.module b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/sca.module new file mode 100644 index 0000000000..86f516c128 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/assembly/tests/sca.module @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<module xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9" + xmlns:js="http://org.apache.tuscany/xmlns/js/0.9" + name="tuscany.container.js.assembly.tests.bigbank.account"> + + <entryPoint name="AccountService"> + <interface.java interface="org.apache.tuscany.container.js.assembly.tests.bigbank.account.services.account.AccountService"/> + <binding.ws port="http://www.bigbank.com/AccountService#AccountServiceSOAP"/> + <reference>AccountServiceComponent</reference> + </entryPoint> + + <component name="AccountServiceComponent"> + <js:implementation.js scriptFile="org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/account/AccountServiceImpl.js"/> + <properties> + <v:currency>EURO</v:currency> + </properties> + <references> + <v:accountDataService>AccountDataServiceComponent</v:accountDataService> + <v:stockQuoteService>StockQuoteService</v:stockQuoteService> + </references> + </component> + + <component name="AccountDataServiceComponent"> + <js:implementation.js scriptFile="org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/accountdata/AccountDataServiceImpl.js"/> + </component> + + <component name="StockQuoteService"> + <js:implementation.js scriptFile="org/apache/tuscany/container/js/assembly/tests/bigbank/account/services/stockquote/StockQuoteServiceImpl.js"/> + </component> + + <!-- + <externalService name="StockQuoteService"> + <interface.java interface="org.apache.tuscany.container.js.assembly.tests.bigbank.account.services.stockquote"/> + <binding.ws port="http://www.quickstockquote.com/StockQuoteService#StockQuoteServiceSOAP"/> + </externalService> + --> + +</module> + diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/config/ModuleComponentLoaderTest1.module b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/config/ModuleComponentLoaderTest1.module new file mode 100644 index 0000000000..d8e2c425ea --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/config/ModuleComponentLoaderTest1.module @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<module xmlns="http://www.osoa.org/xmlns/sca/0.9" + xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9" + xmlns:js="http://org.apache.tuscany/xmlns/js/0.9" + name="ModuleComponentLoaderTest1"> + + <component name="HelloWorldServiceComponent"> + <js:implementation.js scriptFile="org.apache.tuscany.container.js.assembly.mock.HelloWorldImpl.js"/> + </component> +</module> diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/rhino/RhinoInvokerTestCase.js b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/rhino/RhinoInvokerTestCase.js new file mode 100644 index 0000000000..2de740d5f8 --- /dev/null +++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/resources/org/apache/tuscany/container/js/rhino/RhinoInvokerTestCase.js @@ -0,0 +1,22 @@ + +function echo(x) { + return x; +} + +function getA(x) { + return a; +} + +function setGlobalVarY(x) { + y = x; +} +function setLocalVarY(x) { + var y = x; +} +function getGlobalVarY(x) { + return y; +} + +function getInt(x) { + return 42; +} |