You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/05/02 06:33:40 UTC
svn commit: r534302 [2/3] - in /incubator/tuscany/java/sca:
itest/spec-api/src/test/java/org/apache/tuscany/sca/test/spec/
modules/binding-rmi/src/test/java/helloworld/
modules/core-spi/src/main/java/org/apache/tuscany/core/
modules/core-spi/src/main/j...
Added: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeActivatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeActivatorImpl.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeActivatorImpl.java (added)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeActivatorImpl.java Tue May 1 21:33:36 2007
@@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.runtime;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+
+import org.apache.tuscany.assembly.AssemblyFactory;
+import org.apache.tuscany.assembly.Composite;
+import org.apache.tuscany.contribution.Contribution;
+import org.apache.tuscany.core.ExtensionPointRegistry;
+import org.apache.tuscany.core.ModuleActivator;
+import org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.scope.AbstractScopeContainer;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.component.scope.RequestScopeContainer;
+import org.apache.tuscany.core.component.scope.ScopeRegistryImpl;
+import org.apache.tuscany.core.component.scope.StatelessScopeContainer;
+import org.apache.tuscany.core.util.IOHelper;
+import org.apache.tuscany.core.work.Jsr237WorkScheduler;
+import org.apache.tuscany.core.work.ThreadPoolWorkManager;
+import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.interfacedef.IncompatibleInterfaceContractException;
+import org.apache.tuscany.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.interfacedef.impl.DefaultInterfaceContractMapper;
+import org.apache.tuscany.policy.PolicyFactory;
+import org.apache.tuscany.policy.impl.DefaultPolicyFactory;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.component.WorkContextTunnel;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.wire.WirePostProcessorRegistry;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.Constants;
+
+import commonj.work.WorkManager;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class RuntimeActivatorImpl<I extends RuntimeInfo> implements RuntimeActivator<I> {
+
+ protected final XMLInputFactory xmlFactory;
+ protected Class<I> runtimeInfoType;
+ protected ClassLoader hostClassLoader;
+
+ /**
+ * Information provided by the host about its runtime environment.
+ */
+ protected I runtimeInfo;
+
+ protected DefaultCompositeActivator compositeActivator;
+ protected ScopeRegistry scopeRegistry;
+ protected Collection<ModuleActivator> activators;
+
+ protected ThreadPoolWorkManager workManager;
+
+ protected ExtensionPointRegistry extensionPointRegistry;
+ protected Composite domain;
+ protected AssemblyFactory assemblyFactory;
+ protected PolicyFactory policyFactory;
+ protected InterfaceContractMapper interfaceContractMapper;
+
+ protected RuntimeActivatorImpl(Class<I> runtimeInfoType,
+ I runtimeInfo,
+ ClassLoader hostClassLoader,
+ ExtensionPointRegistry extensionPointRegistry) {
+ this.runtimeInfoType = runtimeInfoType;
+ this.runtimeInfo = runtimeInfo;
+ this.hostClassLoader = hostClassLoader;
+ xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", getClass().getClassLoader());
+ this.extensionPointRegistry = extensionPointRegistry;
+ this.scopeRegistry = createScopeRegistry();
+ }
+
+ public void init() throws ActivationException {
+ // Create default factories
+ assemblyFactory = new RuntimeAssemblyFactory();
+ policyFactory = new DefaultPolicyFactory();
+ interfaceContractMapper = new DefaultInterfaceContractMapper();
+
+ extensionPointRegistry.addExtensionPoint(AssemblyFactory.class, assemblyFactory);
+ extensionPointRegistry.addExtensionPoint(PolicyFactory.class, policyFactory);
+ extensionPointRegistry.addExtensionPoint(InterfaceContractMapper.class, interfaceContractMapper);
+
+ // Create a work context
+ // WorkContext workContext = new SimpleWorkContext();
+ WorkContext workContext = new WorkContextImpl();
+ extensionPointRegistry.addExtensionPoint(WorkContext.class, workContext);
+ WorkContextTunnel.setThreadWorkContext(workContext);
+
+ workManager = new ThreadPoolWorkManager(10);
+ WorkScheduler workScheduler = new Jsr237WorkScheduler(workManager);
+
+ WirePostProcessorRegistry wirePostProcessorRegistry = new WirePostProcessorRegistryImpl();
+ extensionPointRegistry.addExtensionPoint(WirePostProcessorRegistry.class, wirePostProcessorRegistry);
+
+ // Create the composite activator
+ compositeActivator = new DefaultCompositeActivator(assemblyFactory, interfaceContractMapper, workContext,
+ workScheduler, wirePostProcessorRegistry);
+
+ // Create the default SCA domain
+ domain = assemblyFactory.createComposite();
+ domain.setName(new QName(Constants.SCA_NS, "sca.domain"));
+ domain.setURI("sca://local/");
+ }
+
+ public void start() throws ActivationException {
+ activators = getInstances(hostClassLoader, ModuleActivator.class);
+ for (ModuleActivator activator : activators) {
+ Map<Class, Object> extensionPoints = activator.getExtensionPoints();
+ if (extensionPoints != null) {
+ for (Map.Entry<Class, Object> e : extensionPoints.entrySet()) {
+ extensionPointRegistry.addExtensionPoint(e.getKey(), e.getValue());
+ }
+ }
+ }
+
+ // Start all the extension modules
+ for (ModuleActivator activator : activators) {
+ activator.start(extensionPointRegistry);
+ }
+
+ }
+
+ public void stop() throws ActivationException {
+ compositeActivator.stop(domain);
+
+ workManager.destroy();
+
+ for (ModuleActivator activator : activators) {
+ activator.stop(extensionPointRegistry);
+ }
+ }
+
+ /**
+ * Create a basic ScopeRegistry containing the ScopeContainers that are
+ * available to components in the system definition. The implementation
+ * returned only support COMPOSITE scope.
+ *
+ * @return a new ScopeRegistry
+ */
+ private ScopeRegistry createScopeRegistry() {
+ ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
+ AbstractScopeContainer[] containers = new AbstractScopeContainer[] {new CompositeScopeContainer(),
+ new StatelessScopeContainer(),
+ new RequestScopeContainer(),
+ // new ConversationalScopeContainer(monitor),
+ // new HttpSessionScopeContainer(monitor)
+ };
+ for (AbstractScopeContainer c : containers) {
+ c.start();
+ scopeRegistry.register(c);
+ }
+
+ return scopeRegistry;
+ }
+
+ protected ScopeRegistry getScopeRegistry() {
+ return scopeRegistry;
+ }
+
+ protected WorkContext getWorkContext() {
+ return extensionPointRegistry.getExtensionPoint(WorkContext.class);
+ }
+
+ /**
+ * Read the service name from a configuration file
+ *
+ * @param classLoader
+ * @param name The name of the service class
+ * @return A class name which extends/implements the service class
+ * @throws IOException
+ */
+ private static Set<String> getServiceNames(ClassLoader classLoader, String name) throws IOException {
+ Set<String> set = new HashSet<String>();
+ Enumeration<URL> urls = classLoader.getResources("META-INF/services/" + name);
+ while (urls.hasMoreElements()) {
+ URL url = urls.nextElement();
+ Set<String> service = getServiceNames(url);
+ if (service != null) {
+ set.addAll(service);
+
+ }
+ }
+ return set;
+ }
+
+ private static Set<String> getServiceNames(URL url) throws IOException {
+ Set<String> names = new HashSet<String>();
+ InputStream is = IOHelper.getInputStream(url);
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(is));
+ while (true) {
+ String line = reader.readLine();
+ if (line == null) {
+ break;
+ }
+ line = line.trim();
+ if (!line.startsWith("#") && !"".equals(line)) {
+ names.add(line.trim());
+ }
+ }
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ return names;
+ }
+
+ private static <T> Collection<T> getInstances(final ClassLoader classLoader, Class<T> serviceClass) {
+ List<T> instances = new ArrayList<T>();
+ try {
+ Set<String> services = getServiceNames(classLoader, serviceClass.getName());
+ for (String className : services) {
+ Class cls = Class.forName(className, true, classLoader);
+ instances.add(serviceClass.cast(cls.newInstance())); // NOPMD
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ return instances;
+ }
+
+ public ComponentContext getComponentContext(String componentName) {
+ for (org.apache.tuscany.assembly.Component component : domain.getComponents()) {
+ if (component.getName().equals(componentName)) {
+ return (ComponentContext)component;
+ }
+ }
+ return null;
+ }
+
+ public void start(Contribution contribution) throws ActivationException {
+ // Add the deployable composites to the SCA domain by "include"
+ for (Composite composite : contribution.getDeployables()) {
+ domain.getIncludes().add(composite);
+ }
+
+ // Activate the SCA domain composite
+ try {
+ compositeActivator.activate(domain);
+ } catch (IncompatibleInterfaceContractException e) {
+ throw new ActivationException(e);
+
+ }
+ }
+
+ public void stop(Contribution contribution) throws ActivationException {
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeActivatorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeActivatorImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeAssemblyFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeAssemblyFactory.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeAssemblyFactory.java (added)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeAssemblyFactory.java Tue May 1 21:33:36 2007
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.runtime;
+
+import org.apache.tuscany.assembly.Component;
+import org.apache.tuscany.assembly.ComponentReference;
+import org.apache.tuscany.assembly.SCABinding;
+import org.apache.tuscany.assembly.impl.DefaultAssemblyFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RuntimeAssemblyFactory extends DefaultAssemblyFactory {
+
+ @Override
+ public Component createComponent() {
+ return new RuntimeComponentImpl();
+ }
+
+ @Override
+ public ComponentReference createComponentReference() {
+ return new RuntimeComponentReferenceImpl();
+ }
+
+ @Override
+ public SCABinding createSCABinding() {
+ return new RuntimeSCABindingImpl();
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeAssemblyFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeAssemblyFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentImpl.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentImpl.java (added)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentImpl.java Tue May 1 21:33:36 2007
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.runtime;
+
+import java.util.List;
+
+import org.apache.tuscany.assembly.ComponentReference;
+import org.apache.tuscany.assembly.Property;
+import org.apache.tuscany.assembly.impl.ComponentImpl;
+import org.apache.tuscany.core.RuntimeComponent;
+import org.apache.tuscany.core.RuntimeComponentReference;
+import org.apache.tuscany.core.RuntimeWire;
+import org.apache.tuscany.core.component.ServiceReferenceImpl;
+import org.apache.tuscany.core.invocation.JDKProxyService;
+import org.apache.tuscany.core.invocation.WireObjectFactory;
+import org.apache.tuscany.interfacedef.impl.DefaultInterfaceContractMapper;
+import org.apache.tuscany.invocation.ProxyFactory;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RuntimeComponentImpl extends ComponentImpl implements RuntimeComponent {
+ public static final String SELF_REFERENCE_PREFIX = "$self$.";
+ protected Object implementationConfiguration;
+ protected ProxyFactory proxyService;
+
+ public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface) {
+ return getServiceReference(businessInterface, SELF_REFERENCE_PREFIX);
+ }
+
+ public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface, String serviceName) {
+ return getServiceReference(businessInterface, SELF_REFERENCE_PREFIX + serviceName);
+ }
+
+ public <B> B getProperty(Class<B> type, String propertyName) {
+ for (Property p : getProperties()) {
+ if (p.getName().equals(propertyName)) {
+ // FIXME: Need to use the property object factory to create the
+ // instance
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public RequestContext getRequestContext() {
+ return null;
+ }
+
+ public <B> B getService(Class<B> businessInterface, String referenceName) {
+ List<ComponentReference> refs = getReferences();
+ for (ComponentReference ref : refs) {
+ if (ref.getName().equals(referenceName)) {
+ RuntimeComponentReference attachPoint = (RuntimeComponentReference)ref;
+ RuntimeWire wire = attachPoint.getRuntimeWires().get(0);
+ return new JDKProxyService(null, new DefaultInterfaceContractMapper()).createProxy(businessInterface,
+ wire);
+ }
+ }
+ return null;
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
+ List<ComponentReference> refs = getReferences();
+ for (ComponentReference ref : refs) {
+ if (ref.getName().equals(referenceName) || referenceName.equals("$self$.")
+ && ref.getName().startsWith(referenceName)) {
+ RuntimeComponentReference attachPoint = (RuntimeComponentReference)ref;
+ RuntimeWire wire = attachPoint.getRuntimeWires().get(0);
+ JDKProxyService proxyService = new JDKProxyService(null, new DefaultInterfaceContractMapper());
+ WireObjectFactory<B> factory = new WireObjectFactory<B>(businessInterface, wire, proxyService);
+ return new ServiceReferenceImpl<B>(businessInterface, factory);
+ }
+ }
+ return null;
+
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ Object ref = proxyService.cast(target);
+ return (R) ref;
+ }
+
+ public Object getImplementationConfiguration() {
+ return implementationConfiguration;
+ }
+
+ public void setImplementationConfiguration(Object implementationConfiguration) {
+ this.implementationConfiguration = implementationConfiguration;
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentReferenceImpl.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentReferenceImpl.java (added)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentReferenceImpl.java Tue May 1 21:33:36 2007
@@ -0,0 +1,21 @@
+package org.apache.tuscany.core.runtime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.assembly.impl.ComponentReferenceImpl;
+import org.apache.tuscany.core.RuntimeComponentReference;
+import org.apache.tuscany.core.RuntimeWire;
+
+public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implements RuntimeComponentReference {
+ private List<RuntimeWire> wires = new ArrayList<RuntimeWire>();
+ public void addRuntimeWire(RuntimeWire wire) {
+ wires.add(wire);
+ }
+
+ public List<RuntimeWire> getRuntimeWires() {
+ return wires;
+ }
+
+
+}
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentReferenceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeComponentReferenceImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeSCABindingImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeSCABindingImpl.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeSCABindingImpl.java (added)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeSCABindingImpl.java Tue May 1 21:33:36 2007
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.runtime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.assembly.Binding;
+import org.apache.tuscany.assembly.Component;
+import org.apache.tuscany.assembly.ComponentReference;
+import org.apache.tuscany.assembly.Reference;
+import org.apache.tuscany.assembly.SCABinding;
+import org.apache.tuscany.assembly.impl.SCABindingImpl;
+import org.apache.tuscany.core.ReferenceBindingProvider;
+import org.apache.tuscany.core.RuntimeWire;
+import org.apache.tuscany.interfacedef.InterfaceContract;
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RuntimeSCABindingImpl extends SCABindingImpl implements SCABinding, ReferenceBindingProvider {
+ private List<RuntimeWire> wires = new ArrayList<RuntimeWire>();
+
+ public void addWire(RuntimeWire wire) {
+ wires.add(wire);
+ }
+
+ public Interceptor createInterceptor(Reference reference, Binding binding, Operation operation, boolean isCallback) {
+ return null;
+ }
+
+ public InterfaceContract getBindingInterfaceContract(ComponentReference reference) {
+ return reference.getInterfaceContract();
+ }
+
+ public List<RuntimeWire> getWires() {
+ return wires;
+ }
+
+ public Interceptor createInterceptor(Component component, ComponentReference reference, Operation operation, boolean isCallback) {
+ return null;
+ }
+
+
+}
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeSCABindingImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeSCABindingImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeWireImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeWireImpl.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeWireImpl.java (added)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeWireImpl.java Tue May 1 21:33:36 2007
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.runtime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.assembly.Binding;
+import org.apache.tuscany.assembly.ComponentReference;
+import org.apache.tuscany.assembly.ComponentService;
+import org.apache.tuscany.assembly.SCABinding;
+import org.apache.tuscany.core.RuntimeWire;
+import org.apache.tuscany.spi.wire.InvocationChain;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RuntimeWireImpl implements RuntimeWire {
+ private ComponentReference source;
+ private Binding sourceBinding;
+ private ComponentService target;
+ private Binding targetBinding;
+ private final List<InvocationChain> chains = new ArrayList<InvocationChain>();
+ private final List<InvocationChain> callbackChains = new ArrayList<InvocationChain>();
+
+ /**
+ * @param source
+ * @param target
+ */
+ public RuntimeWireImpl(ComponentReference source, ComponentService target) {
+ super();
+ this.source = source;
+ this.target = target;
+ }
+
+ /**
+ * Create a wire for a promoted reference
+ * @param source
+ * @param sourceBinding
+ */
+ public RuntimeWireImpl(ComponentReference source,
+ Binding sourceBinding) {
+ this.source = source;
+ this.sourceBinding = sourceBinding;
+ assert !(sourceBinding instanceof SCABinding);
+ }
+
+ public RuntimeWireImpl(ComponentReference source,
+ Binding sourceBinding,
+ ComponentService target,
+ Binding targetBinding) {
+ super();
+ this.source = source;
+ this.sourceBinding = sourceBinding;
+ this.target = target;
+ this.targetBinding = targetBinding;
+ }
+
+ public List<InvocationChain> getCallbackInvocationChains() {
+ return callbackChains;
+ }
+
+ public List<InvocationChain> getInvocationChains() {
+ return chains;
+ }
+
+ public ComponentReference getSource() {
+ return source;
+ }
+
+ public ComponentService getTarget() {
+ return target;
+ }
+
+ public Binding getSourceBinding() {
+ return sourceBinding;
+ }
+
+ public void setSourceBinding(Binding sourceBinding) {
+ this.sourceBinding = sourceBinding;
+ }
+
+ public Binding getTargetBinding() {
+ return targetBinding;
+ }
+
+ public void setTargetBinding(Binding targetBinding) {
+ this.targetBinding = targetBinding;
+ }
+
+ public boolean isOptimizable() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeWireImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeWireImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.java?view=diff&rev=534302&r1=534301&r2=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.java Tue May 1 21:33:36 2007
@@ -20,11 +20,8 @@
import java.net.URI;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
-import javax.xml.namespace.QName;
-
import org.apache.tuscany.interfacedef.InterfaceContract;
import org.apache.tuscany.spi.component.AtomicComponent;
import org.apache.tuscany.spi.component.TargetResolutionException;
@@ -33,7 +30,7 @@
/**
* Default implementation of a Wire
- *
+ *
* @version $Rev$ $Date$
*/
public class WireImpl implements Wire {
@@ -42,8 +39,8 @@
private InterfaceContract sourceContract;
private InterfaceContract targetContract;
private boolean optimizable;
- private List<InvocationChain> chains = new ArrayList<InvocationChain>();
- private List<InvocationChain> callbackChains = new ArrayList<InvocationChain>();
+ private final List<InvocationChain> chains = new ArrayList<InvocationChain>();
+ private final List<InvocationChain> callbackChains = new ArrayList<InvocationChain>();
private AtomicComponent target;
/**
@@ -76,7 +73,6 @@
this.sourceContract = contract;
}
-
public InterfaceContract getTargetContract() {
return targetContract;
}
@@ -105,7 +101,7 @@
}
public List<InvocationChain> getInvocationChains() {
- return Collections.unmodifiableList(chains);
+ return chains;
}
public void addInvocationChain(InvocationChain chain) {
@@ -113,7 +109,7 @@
}
public List<InvocationChain> getCallbackInvocationChains() {
- return Collections.unmodifiableList(callbackChains);
+ return callbackChains;
}
public void addCallbackInvocationChain(InvocationChain chain) {
Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java?view=diff&rev=534302&r1=534301&r2=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java Tue May 1 21:33:36 2007
@@ -34,7 +34,6 @@
/**
* Uses a wire to return an object instance
*
- * @Deprecated
* @version $Rev$ $Date$
*/
public class WireObjectFactory<T> implements ObjectFactory<T> {
Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java?view=diff&rev=534302&r1=534301&r2=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java Tue May 1 21:33:36 2007
@@ -19,7 +19,6 @@
package org.apache.tuscany.core.wire;
import java.lang.reflect.Method;
-import java.lang.reflect.TypeVariable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Modified: incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java?view=diff&rev=534302&r1=534301&r2=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java Tue May 1 21:33:36 2007
@@ -18,8 +18,6 @@
*/
package org.apache.tuscany.core.wire;
-import java.lang.reflect.Type;
-
import junit.framework.TestCase;
import org.apache.tuscany.interfacedef.Operation;
@@ -48,7 +46,7 @@
Wire wire = new WireImpl();
InvocationChain chain = new InvocationChainImpl(operation);
chain.addInterceptor(new OptimizableInterceptor());
- wire.addInvocationChain(chain);
+ wire.getInvocationChains().add(chain);
assertTrue(WireUtils.isOptimizable(wire));
}
@@ -58,7 +56,7 @@
Wire wire = new WireImpl();
InvocationChain chain = new InvocationChainImpl(operation);
chain.addInterceptor(new NonOptimizableInterceptor());
- wire.addInvocationChain(chain);
+ wire.getInvocationChains().add(chain);
assertFalse(WireUtils.isOptimizable(wire));
}
Modified: incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java?view=diff&rev=534302&r1=534301&r2=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java Tue May 1 21:33:36 2007
@@ -44,7 +44,7 @@
JavaFactory javaFactory = new DefaultJavaFactory();
op.setInterface(javaFactory.createJavaInterface());
InvocationChain chain = new InvocationChainImpl(op);
- wire.addInvocationChain(chain);
+ wire.getInvocationChains().add(chain);
Map<Method, ChainHolder> chains = WireUtils.createInterfaceToWireMapping(Foo.class, wire);
assertEquals(1, chains.size());
assertNotNull(chains.get(m));
@@ -57,7 +57,7 @@
JavaFactory javaFactory = new DefaultJavaFactory();
op.setInterface(javaFactory.createJavaInterface());
InvocationChain chain = new InvocationChainImpl(op);
- wire.addInvocationChain(chain);
+ wire.getInvocationChains().add(chain);
try {
WireUtils.createInterfaceToWireMapping(Foo.class, wire);
fail();
Added: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/SCARuntimeActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/SCARuntimeActivator.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/SCARuntimeActivator.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/SCARuntimeActivator.java Tue May 1 21:33:36 2007
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.host.embedded;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.apache.tuscany.host.embedded.impl.DefaultSCARuntime;
+import org.apache.tuscany.host.embedded.impl.DefaultSCARuntimeActivator;
+import org.osoa.sca.ComponentContext;
+
+/**
+ * SCARuntime is used to start a Tuscany SCA runtime.
+ */
+public abstract class SCARuntimeActivator {
+
+ private static SCARuntimeActivator instance;
+
+ /**
+ * Read the service name from a configuration file
+ *
+ * @param classLoader
+ * @param name The name of the service class
+ * @return A class name which extends/implements the service class
+ * @throws IOException
+ */
+ private static String getServiceName(ClassLoader classLoader, String name) throws IOException {
+ InputStream is = classLoader.getResourceAsStream("META-INF/services/" + name);
+ if (is == null) {
+ return null;
+ }
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(is));
+ while (true) {
+ String line = reader.readLine();
+ if (line == null) {
+ break;
+ } else if (!line.startsWith("#")) {
+ return line.trim();
+ }
+ }
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns a SCARuntime instance. If the system property
+ * "org.apache.tuscany.api.SCARuntime" is set, its value is used as the name
+ * of the implementation class. Otherwise, if the resource
+ * "META-INF/services/org.apache.tuscany.api.SCARuntime" can be loaded from
+ * the supplied classloader. Otherwise, it will use
+ * "org.apache.tuscany.host.embedded.DefaultSCARuntime" as the default.
+ * The named class is loaded from the supplied classloader and instantiated
+ * using its default (no-arg) constructor.
+ *
+ * @return
+ */
+ private static SCARuntimeActivator newInstance(final ClassLoader classLoader) {
+
+ try {
+ final String name = SCARuntimeActivator.class.getName();
+ String className = AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty(name);
+ }
+ });
+
+ if (className == null) {
+ className = getServiceName(classLoader, name);
+ }
+ if (className == null) {
+ return new DefaultSCARuntimeActivator();
+ }
+ Class cls = Class.forName(className, true, classLoader);
+ return (SCARuntimeActivator)cls.newInstance(); // NOPMD lresende
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Get an instance of SCA Runtime
+ *
+ * @return The instance
+ */
+ public static synchronized SCARuntimeActivator getInstance() { // NOPMD
+ if (instance != null) {
+ return instance;
+ }
+ ClassLoader classLoader = SCARuntimeActivator.class.getClassLoader();
+ instance = newInstance(classLoader);
+ return instance;
+ }
+
+ /**
+ * Start the Tuscany runtime using default SCDLs
+ */
+ public static void start() {
+ try {
+ getInstance().startup(null, null);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Start the SCA Runtime with the given SCDL
+ *
+ * @param application The URL for the application SCDL
+ */
+ public static void start(URL application, String compositePath) {
+ try {
+ getInstance().startup(application, compositePath);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Start the SCA Runtime with the given composite file.
+ *
+ * @param compositePath The path of the composite file.
+ */
+ public static void start(String compositePath) {
+ try {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ URL applicationURL = cl.getResource(compositePath);
+ getInstance().startup(applicationURL, compositePath);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Get the ComponentContext by name
+ *
+ * @param componentName
+ * @return
+ */
+ public static ComponentContext getComponentContext(String componentName) {
+ return getInstance().getContext(componentName);
+ }
+
+ /**
+ * Stop the SCA Runtime
+ */
+ public static void stop() {
+ try {
+ getInstance().shutdown();
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ } finally {
+ instance = null;
+ }
+ }
+
+ /**
+ * Look up the ComponentContext by name
+ *
+ * @param componentName
+ * @return
+ */
+ protected abstract ComponentContext getContext(String componentName);
+
+ /**
+ * Start up the runtime
+ *
+ * @param application The URL of the SCDL for the application composite
+ * @param compositePath The path of the application composite relative to
+ * the application URL
+ * @throws Exception
+ */
+ protected abstract void startup(URL application, String compositePath)
+ throws Exception;
+
+ /**
+ * Shutdown the runtime
+ *
+ * @throws Exception
+ */
+ protected abstract void shutdown() throws Exception;
+}
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/SCARuntimeActivator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/SCARuntimeActivator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/DefaultSCARuntimeActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/DefaultSCARuntimeActivator.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/DefaultSCARuntimeActivator.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/DefaultSCARuntimeActivator.java Tue May 1 21:33:36 2007
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.host.embedded.impl;
+
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tuscany.host.embedded.SCARuntimeActivator;
+import org.osoa.sca.ComponentContext;
+
+/**
+ * Default implementation of SCARuntime.
+ *
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings("deprecation")
+public class DefaultSCARuntimeActivator extends SCARuntimeActivator {
+
+ protected MiniRuntimeImpl runtime;
+
+ protected void startup(URL applicationSCDL, String compositePath) throws Exception {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ URI contributionURI = URI.create("/default");
+ SimpleRuntimeInfo runtimeInfo = new SimpleRuntimeInfoImpl(cl, contributionURI, applicationSCDL, compositePath);
+ runtime = new MiniRuntimeImpl(runtimeInfo);
+
+ try {
+ runtime.start();
+ } catch (Exception e) {
+ throw e;
+ }
+
+ }
+
+ protected void shutdown() throws Exception {
+ runtime.stop();
+ }
+
+ @Override
+ protected ComponentContext getContext(String componentName) {
+ return runtime.getComponentContext(componentName);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/DefaultSCARuntimeActivator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/DefaultSCARuntimeActivator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/MiniRuntimeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/MiniRuntimeImpl.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/MiniRuntimeImpl.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/MiniRuntimeImpl.java Tue May 1 21:33:36 2007
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.host.embedded.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+
+import org.apache.tuscany.assembly.xml.ComponentTypeDocumentProcessor;
+import org.apache.tuscany.assembly.xml.ComponentTypeProcessor;
+import org.apache.tuscany.assembly.xml.CompositeDocumentProcessor;
+import org.apache.tuscany.assembly.xml.CompositeProcessor;
+import org.apache.tuscany.assembly.xml.ConstrainingTypeDocumentProcessor;
+import org.apache.tuscany.assembly.xml.ConstrainingTypeProcessor;
+import org.apache.tuscany.contribution.Contribution;
+import org.apache.tuscany.contribution.impl.DefaultContributionFactory;
+import org.apache.tuscany.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.contribution.processor.DefaultURLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.contribution.processor.PackageProcessorExtensionPoint;
+import org.apache.tuscany.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.contribution.processor.impl.DefaultPackageProcessorExtensionPoint;
+import org.apache.tuscany.contribution.processor.impl.FolderContributionProcessor;
+import org.apache.tuscany.contribution.processor.impl.JarContributionProcessor;
+import org.apache.tuscany.contribution.resolver.DefaultArtifactResolver;
+import org.apache.tuscany.contribution.service.ContributionRepository;
+import org.apache.tuscany.contribution.service.ContributionService;
+import org.apache.tuscany.contribution.service.impl.ContributionRepositoryImpl;
+import org.apache.tuscany.contribution.service.impl.ContributionServiceImpl;
+import org.apache.tuscany.contribution.service.impl.PackageTypeDescriberImpl;
+import org.apache.tuscany.contribution.service.util.FileHelper;
+import org.apache.tuscany.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.core.runtime.ActivationException;
+import org.apache.tuscany.core.runtime.RuntimeActivatorImpl;
+import org.apache.tuscany.spi.Scope;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MiniRuntimeImpl extends RuntimeActivatorImpl<SimpleRuntimeInfo> {
+ public MiniRuntimeImpl(SimpleRuntimeInfo runtimeInfo) {
+ super(SimpleRuntimeInfo.class, runtimeInfo, runtimeInfo.getClassLoader(), new DefaultExtensionPointRegistry());
+ }
+
+ private static URL getContributionLocation(URL applicationSCDL, String compositePath) {
+ URL root = null;
+ // "jar:file://....../something.jar!/a/b/c/app.composite"
+ try {
+ String scdlUrl = applicationSCDL.toExternalForm();
+ String protocol = applicationSCDL.getProtocol();
+ if ("file".equals(protocol)) {
+ // directory contribution
+ if (scdlUrl.endsWith(compositePath)) {
+ String location = scdlUrl.substring(0, scdlUrl.lastIndexOf(compositePath));
+ // workaround from evil url/uri form maven
+ root = FileHelper.toFile(new URL(location)).toURI().toURL();
+ }
+
+ } else if ("jar".equals(protocol)) {
+ // jar contribution
+ String location = scdlUrl.substring(4, scdlUrl.lastIndexOf("!/"));
+ // workaround from evil url/uri form maven
+ root = FileHelper.toFile(new URL(location)).toURI().toURL();
+ }
+ } catch (MalformedURLException mfe) {
+ throw new IllegalArgumentException(mfe);
+ }
+
+ return root;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void start() throws ActivationException {
+ super.init();
+
+ ContributionService contributionService = createContributionService();
+
+ super.start();
+
+ // Contribute and activate the SCA contribution
+ URI uri = URI.create("sca://default/");
+ URL root = getContributionLocation(runtimeInfo.getApplicationSCDL(), runtimeInfo.getCompositePath());
+ try {
+ contributionService.contribute(uri, root, false);
+ } catch (Exception e) {
+ throw new ActivationException(e);
+ }
+ Contribution contribution = contributionService.getContribution(uri);
+
+ super.start(contribution);
+ }
+
+ protected ContributionService createContributionService() throws ActivationException {
+ // Add artifact processor extension points
+ DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint();
+ extensionPointRegistry.addExtensionPoint(StAXArtifactProcessorExtensionPoint.class, staxProcessors);
+ DefaultURLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint();
+ extensionPointRegistry.addExtensionPoint(URLArtifactProcessorExtensionPoint.class, documentProcessors);
+
+ // Register base artifact processors
+ staxProcessors.addExtension(new CompositeProcessor(assemblyFactory, policyFactory, interfaceContractMapper,
+ staxProcessors));
+ staxProcessors.addExtension(new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessors));
+ staxProcessors.addExtension(new ConstrainingTypeProcessor(assemblyFactory, policyFactory, staxProcessors));
+
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", getClass()
+ .getClassLoader());
+ documentProcessors.addExtension(new CompositeDocumentProcessor(staxProcessors, inputFactory));
+ documentProcessors.addExtension(new ComponentTypeDocumentProcessor(staxProcessors, inputFactory));
+ documentProcessors.addExtension(new ConstrainingTypeDocumentProcessor(staxProcessors, inputFactory));
+
+ // Create package processor extension point
+ PackageTypeDescriberImpl describer = new PackageTypeDescriberImpl();
+ PackageProcessorExtensionPoint packageProcessors = new DefaultPackageProcessorExtensionPoint(describer);
+ extensionPointRegistry.addExtensionPoint(PackageProcessorExtensionPoint.class, packageProcessors);
+
+ // Register base package processors
+ new JarContributionProcessor(packageProcessors);
+ new FolderContributionProcessor(packageProcessors);
+
+ // Create contribution service
+ ContributionRepository repository;
+ try {
+ repository = new ContributionRepositoryImpl("target");
+ } catch (IOException e) {
+ throw new ActivationException(e);
+ }
+
+ DefaultArtifactResolver artifactResolver = new DefaultArtifactResolver(hostClassLoader);
+ ContributionService contributionService = new ContributionServiceImpl(repository, packageProcessors,
+ documentProcessors, artifactResolver,
+ assemblyFactory,
+ new DefaultContributionFactory());
+ return contributionService;
+ }
+
+ public <T> T getExtensionPoint(Class<T> type) throws TargetResolutionException {
+ return extensionPointRegistry.getExtensionPoint(type);
+ }
+
+ @Override
+ public void stop() throws ActivationException {
+ getWorkContext().setIdentifier(Scope.COMPOSITE, null);
+ super.stop();
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/MiniRuntimeImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/MiniRuntimeImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/SimpleCompositeContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/SimpleCompositeContextImpl.java?view=diff&rev=534302&r1=534301&r2=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/SimpleCompositeContextImpl.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/host/embedded/impl/SimpleCompositeContextImpl.java Tue May 1 21:33:36 2007
@@ -105,7 +105,7 @@
if (context == null) {
throw new ServiceRuntimeException("Service not found: " + serviceName);
}
- ServiceReference<T> serviceReference = context.createSelfReference(serviceType);
+ ServiceReference<T> serviceReference = context.createSelfReference(serviceType, componentService.getName());
return serviceReference.getService();
}
}
@@ -137,7 +137,8 @@
if (context == null) {
throw new ServiceRuntimeException("Service not found: " + serviceName);
}
- ServiceReference<T> serviceReference = context.createSelfReference(serviceType);
+ // FIXME: The service name has to be provided if there are more than one services
+ ServiceReference<T> serviceReference = context.createSelfReference(serviceType, serviceType.getSimpleName());
return serviceReference.getService();
}
}
@@ -150,7 +151,7 @@
if (context == null) {
throw new ServiceRuntimeException("Component not found: " + componentName);
}
- ServiceReference<T> serviceReference = context.createSelfReference(serviceType);
+ ServiceReference<T> serviceReference = context.createSelfReference(serviceType, serviceName);
return serviceReference.getService();
}
}
Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUD.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUD.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUD.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUD.java Tue May 1 21:33:36 2007
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package crud;
+
+/**
+ * The service interface of the single CRUD service provided by CRUD components.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CRUD {
+
+ /**
+ * Create a new resource.
+ * @param resource
+ * @return
+ */
+ String create(Object resource);
+
+ /**
+ * Retrieve a resource.
+ * @param id
+ * @return
+ */
+ Object retrieve(String id);
+
+ /**
+ * Update a resource.
+ * @param id
+ * @param resource
+ * @return
+ */
+ Object update(String id, Object resource);
+
+ /**
+ * Delete a resource.
+ * @param id
+ */
+ void delete(String id);
+
+}
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUD.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUD.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDAtomicComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDAtomicComponent.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDAtomicComponent.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDAtomicComponent.java Tue May 1 21:33:36 2007
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package crud;
+
+import java.net.URI;
+import java.util.List;
+
+import org.apache.tuscany.assembly.Component;
+import org.apache.tuscany.assembly.ComponentReference;
+import org.apache.tuscany.core.RuntimeComponentReference;
+import org.apache.tuscany.core.RuntimeWire;
+import org.apache.tuscany.core.component.ComponentContextImpl;
+import org.apache.tuscany.core.component.ComponentContextProvider;
+import org.apache.tuscany.core.component.ServiceReferenceImpl;
+import org.apache.tuscany.core.component.scope.InstanceWrapperBase;
+import org.apache.tuscany.core.invocation.JDKProxyService;
+import org.apache.tuscany.core.invocation.WireObjectFactory;
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.interfacedef.impl.DefaultInterfaceContractMapper;
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.SingletonObjectFactory;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.extension.AtomicComponentExtension;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * The runtime instantiation of CRUD component implementations. FIXME We need to
+ * remove the requirement for such a class, implementing the implementation
+ * model should be sufficient.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CRUDAtomicComponent extends AtomicComponentExtension implements ComponentContextProvider {
+ private ComponentContext componentContext;
+ private ResourceManager resourceManager;
+ private Component component;
+ private CRUDImplementation implementation;
+
+ public CRUDAtomicComponent(URI uri, URI groupId, Component component, CRUDImplementation implementation) {
+ super(uri, null, null, groupId, 50);
+ this.component = component;
+ this.implementation = implementation;
+ componentContext = new ComponentContextImpl(this);
+ resourceManager = new ResourceManager(implementation.getDirectory());
+ }
+
+ public Object createInstance() throws ObjectCreationException {
+ return resourceManager;
+ }
+
+ public InstanceWrapper createInstanceWrapper() throws ObjectCreationException {
+ return new InstanceWrapperBase(createInstance());
+ }
+
+ public Object getTargetInstance() throws TargetResolutionException {
+ return resourceManager;
+ }
+
+ public void attachCallbackWire(Wire arg0) {
+ }
+
+ public void attachWire(Wire arg0) {
+ }
+
+ public void attachWires(List<Wire> arg0) {
+ }
+
+ public List<Wire> getWires(String arg0) {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, final Operation operation, boolean callback)
+ throws TargetInvokerCreationException {
+ return new CRUDTargetInvoker(operation, resourceManager);
+ }
+
+ @Override
+ public ComponentContext getComponentContext() {
+ return componentContext;
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) {
+ return null;
+ }
+
+ public <B> B getProperty(Class<B> type, String propertyName) {
+ return null;
+ }
+
+ public <B> B getService(Class<B> businessInterface, String referenceName) {
+ List<ComponentReference> refs = component.getReferences();
+ for (ComponentReference ref : refs) {
+ if (ref.getName().equals(referenceName)) {
+ RuntimeComponentReference attachPoint = (RuntimeComponentReference)ref;
+ RuntimeWire wire = attachPoint.getRuntimeWires().get(0);
+ return new JDKProxyService(null, new DefaultInterfaceContractMapper()).createProxy(businessInterface,
+ wire);
+ }
+ }
+ return null;
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
+ List<ComponentReference> refs = component.getReferences();
+ for (ComponentReference ref : refs) {
+ if (ref.getName().equals(referenceName) || referenceName.equals("$self$_")
+ && ref.getName().startsWith(referenceName)) {
+ RuntimeComponentReference attachPoint = (RuntimeComponentReference)ref;
+ RuntimeWire wire = attachPoint.getRuntimeWires().get(0);
+ JDKProxyService proxyService = new JDKProxyService(null, new DefaultInterfaceContractMapper());
+ WireObjectFactory<B> factory = new WireObjectFactory<B>(businessInterface, wire, proxyService);
+ return new ServiceReferenceImpl<B>(businessInterface, factory);
+ }
+ }
+ return null;
+
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDAtomicComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDAtomicComponent.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDComponentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDComponentBuilder.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDComponentBuilder.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDComponentBuilder.java Tue May 1 21:33:36 2007
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package crud;
+
+import java.net.URI;
+
+import org.apache.tuscany.assembly.Component;
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.builder.ComponentBuilder;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+/**
+ * A builder that builds a Java-based atomic context from an implementation
+ * model. FIXME We need to remove the requirement for builders.
+ *
+ * @version $$Rev$$ $$Date: 2007-04-23 19:18:54 -0700 (Mon, 23 Apr
+ * 2007) $$
+ */
+public class CRUDComponentBuilder implements ComponentBuilder {
+
+ public AtomicComponent build(Component definition, DeploymentContext context) throws BuilderConfigException {
+ URI uri = URI.create(context.getComponentId() + definition.getName());
+ CRUDAtomicComponent component = new CRUDAtomicComponent(uri, context.getGroupId(), definition,
+ (CRUDImplementation)definition.getImplementation());
+ return component;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDComponentBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDComponentBuilder.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementation.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementation.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementation.java Tue May 1 21:33:36 2007
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package crud;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.tuscany.assembly.AssemblyFactory;
+import org.apache.tuscany.assembly.ComponentService;
+import org.apache.tuscany.assembly.ConstrainingType;
+import org.apache.tuscany.assembly.Implementation;
+import org.apache.tuscany.assembly.Property;
+import org.apache.tuscany.assembly.Service;
+import org.apache.tuscany.assembly.impl.ComponentTypeImpl;
+import org.apache.tuscany.core.ImplementationActivator;
+import org.apache.tuscany.core.ImplementationProvider;
+import org.apache.tuscany.core.RuntimeComponent;
+import org.apache.tuscany.interfacedef.InterfaceContract;
+import org.apache.tuscany.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.interfacedef.java.JavaFactory;
+import org.apache.tuscany.interfacedef.java.JavaInterface;
+import org.apache.tuscany.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.interfacedef.java.introspect.JavaInterfaceIntrospector;
+import org.apache.tuscany.policy.Intent;
+import org.apache.tuscany.policy.PolicySet;
+import org.apache.tuscany.spi.Scope;
+import org.apache.tuscany.spi.wire.Interceptor;
+
+/**
+ * The model representing a sample CRUD implementation in an SCA assembly model.
+ * The sample CRUD implementation is not a full blown implementation, it only
+ * supports a subset of what a component implementation can support: - a single
+ * fixed service (as opposed to a list of services typed by different
+ * interfaces) - a directory attribute used to specify where a CRUD component is
+ * going to persist resources - no references or properties - no policy intents
+ * or policy sets
+ *
+ * @version $$Rev$$ $$Date: 2007-04-23 19:18:54 -0700 (Mon, 23 Apr
+ * 2007) $$
+ */
+public class CRUDImplementation extends ComponentTypeImpl implements Implementation, ImplementationProvider,
+ ImplementationActivator {
+
+ private Service crudService;
+ private String directory;
+
+ private AssemblyFactory assemblyFactory;
+
+ /**
+ * Constructs a new CRUD implementation.
+ */
+ public CRUDImplementation(AssemblyFactory assemblyFactory,
+ JavaFactory javaFactory,
+ JavaInterfaceIntrospector introspector) {
+
+ // CRUD implementation always provide a single service exposing
+ // the CRUD interface, and have no references and properties
+ crudService = assemblyFactory.createService();
+ crudService.setName("CRUD");
+ JavaInterface javaInterface;
+ try {
+ javaInterface = introspector.introspect(CRUD.class);
+ } catch (InvalidInterfaceException e) {
+ throw new IllegalArgumentException(e);
+ }
+ JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+ interfaceContract.setInterface(javaInterface);
+ crudService.setInterfaceContract(interfaceContract);
+ this.assemblyFactory = assemblyFactory;
+ }
+
+
+ /**
+ * Returns the directory used by CRUD implementations to persist resources.
+ *
+ * @return the directory used to persist resources
+ */
+ public String getDirectory() {
+ return directory;
+ }
+
+ /**
+ * Sets the directory used by CRUD implementations to persist resources.
+ *
+ * @param directory the directory used to persist resources
+ */
+ public void setDirectory(String directory) {
+ this.directory = directory;
+ }
+
+ public ConstrainingType getConstrainingType() {
+ // CRUD implementations do not support constrainingTypes
+ return null;
+ }
+
+ public List<Property> getProperties() {
+ // CRUD implementations do not support properties
+ return Collections.emptyList();
+ }
+
+ public List<Service> getServices() {
+ // CRUD implementations provide a single fixed CRUD service
+ return Collections.singletonList(crudService);
+ }
+
+ public String getURI() {
+ // CRUD implementations don't have a URI
+ return null;
+ }
+
+ public void setConstrainingType(ConstrainingType constrainingType) {
+ // CRUD implementations do not support constrainingTypes
+ }
+
+ public void setURI(String uri) {
+ // CRUD implementations don't have a URI
+ }
+
+ public List<PolicySet> getPolicySets() {
+ // CRUD implementations do not support policy sets
+ return Collections.emptyList();
+ }
+
+ public List<Intent> getRequiredIntents() {
+ // CRUD implementations do not support intents
+ return Collections.emptyList();
+ }
+
+ public List<Object> getExtensions() {
+ // CRUD implementations do not support extensions
+ return Collections.emptyList();
+ }
+
+ public boolean isUnresolved() {
+ // CRUD implementations are always resolved
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ // CRUD implementations are always resolved
+ }
+
+ public Interceptor createInterceptor(RuntimeComponent component,
+ ComponentService service,
+ Operation operation,
+ boolean isCallback) {
+ CRUDImplementation impl = (CRUDImplementation)component.getImplementation();
+ CRUDTargetInvoker invoker = new CRUDTargetInvoker(operation, new ResourceManager(impl.getDirectory()));
+ return invoker;
+ }
+
+ public InterfaceContract getImplementationInterfaceContract(ComponentService service) {
+ return service.getInterfaceContract();
+ }
+
+ public Scope getScope() {
+ return null;
+ }
+
+ public void start(RuntimeComponent component) {
+ System.out.println("Starting " + component.getName());
+ }
+
+ public void stop(RuntimeComponent component) {
+ System.out.println("Stopping " + component.getName());
+ }
+
+ public void configure(RuntimeComponent component) {
+ System.out.println("Configuring " + component.getName());
+ }
+
+ public Object createInstance(RuntimeComponent component, ComponentService service) {
+ return null;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementation.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProcessor.java?view=auto&rev=534302
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProcessor.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProcessor.java Tue May 1 21:33:36 2007
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package crud;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.assembly.AssemblyFactory;
+import org.apache.tuscany.contribution.processor.StAXArtifactProcessorExtension;
+import org.apache.tuscany.contribution.resolver.ArtifactResolver;
+import org.apache.tuscany.contribution.service.ContributionReadException;
+import org.apache.tuscany.contribution.service.ContributionResolveException;
+import org.apache.tuscany.contribution.service.ContributionWireException;
+import org.apache.tuscany.contribution.service.ContributionWriteException;
+import org.apache.tuscany.interfacedef.java.JavaFactory;
+import org.apache.tuscany.interfacedef.java.introspect.JavaInterfaceIntrospector;
+
+/**
+ * Implements a STAX artifact processor for CRUD implementations.
+ *
+ * The artifact processor is responsible for processing <implementation.crud>
+ * elements in SCA assembly XML composite files and populating the CRUD
+ * implementation model, resolving its references to other artifacts in the SCA
+ * contribution, and optionally write the model back to SCA assembly XML.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CRUDImplementationProcessor implements StAXArtifactProcessorExtension<CRUDImplementation> {
+ private static final QName IMPLEMENTATION_CRUD = new QName("http://crud", "implementation.crud");
+
+ private AssemblyFactory assemblyFactory;
+ private JavaFactory javaFactory;
+ private JavaInterfaceIntrospector introspector;
+
+ public CRUDImplementationProcessor(AssemblyFactory assemblyFactory, JavaFactory javaFactory, JavaInterfaceIntrospector introspector) {
+ this.assemblyFactory = assemblyFactory;
+ this.javaFactory = javaFactory;
+ this.introspector = introspector;
+ }
+
+ public QName getArtifactType() {
+ // Returns the qname of the XML element processed by this processor
+ return IMPLEMENTATION_CRUD;
+ }
+
+ public Class<CRUDImplementation> getModelType() {
+ // Returns the type of model processed by this processor
+ return CRUDImplementation.class;
+ }
+
+ public CRUDImplementation read(XMLStreamReader reader) throws ContributionReadException {
+ assert IMPLEMENTATION_CRUD.equals(reader.getName());
+
+ // Read an <implementation.crud> element
+ try {
+ // Read the directory attribute. This is where the sample
+ // CRUD implementation will persist resources.
+ String directory = reader.getAttributeValue(null, "directory");
+
+ // Create an initialize the CRUD implementation model
+ CRUDImplementation implementation = new CRUDImplementation(assemblyFactory, javaFactory, introspector);
+ implementation.setDirectory(directory);
+
+ // Skip to end element
+ while (reader.hasNext()) {
+ if (reader.next() == END_ELEMENT && IMPLEMENTATION_CRUD.equals(reader.getName())) {
+ break;
+ }
+ }
+
+ return implementation;
+ } catch (XMLStreamException e) {
+ throw new ContributionReadException(e);
+ }
+ }
+
+ public void resolve(CRUDImplementation impl, ArtifactResolver resolver) throws ContributionResolveException {
+ }
+
+ public void wire(CRUDImplementation model) throws ContributionWireException {
+ }
+
+ public void write(CRUDImplementation model, XMLStreamWriter outputSource) throws ContributionWriteException {
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProcessor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org