summaryrefslogtreecommitdiffstats
path: root/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly')
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java37
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java137
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointSerializer.java38
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java74
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java876
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java108
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParameterProcessor.java101
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParametersImpl.java139
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentImpl.java111
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java144
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java163
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java100
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java100
-rw-r--r--tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java680
14 files changed, 2808 insertions, 0 deletions
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java
new file mode 100644
index 0000000000..c86c876075
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.assembly;
+
+
+/**
+ * Denotes an error starting the runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public class ActivationException extends Exception {
+ private static final long serialVersionUID = 8612661660934426123L;
+
+ public ActivationException(String message) {
+ super(message);
+ }
+
+ public ActivationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java
new file mode 100644
index 0000000000..939afa40a8
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.core.context.CompositeContext;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * Start/stop a composite
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CompositeActivator {
+ /**
+ * Activate a composite
+ * @param composite
+ */
+ void activate(Composite composite) throws ActivationException;
+
+ /**
+ * Activate a component reference
+ * @param component
+ * @param ref
+ */
+ void start(RuntimeComponent component, RuntimeComponentReference ref);
+
+ /**
+ * Activate a component reference
+ * @param component
+ * @param ref
+ */
+ void activate(RuntimeComponent component, RuntimeComponentReference ref);
+
+ /**
+ * Activate a component reference
+ * @param component
+ * @param ref
+ */
+ void activate(RuntimeComponent component, RuntimeComponentService service);
+
+ /**
+ * De-activate a component reference
+ * @param component
+ * @param ref
+ */
+ void deactivate(RuntimeComponent component, RuntimeComponentReference ref);
+
+ /**
+ * De-activate a component reference
+ * @param component
+ * @param ref
+ */
+ void deactivate(RuntimeComponent component, RuntimeComponentService service);
+
+ /**
+ * Stop a composite
+ * @param composite
+ */
+ void deactivate(Composite composite) throws ActivationException;
+
+ /**
+ * Start a component
+ * @param component
+ */
+ void start(Component component) throws ActivationException;
+
+ /**
+ * Stop a component
+ * @param component
+ */
+ void stop(Component component) throws ActivationException;
+
+ /**
+ * Start components in a composite
+ * @param composite
+ */
+ void start(Composite composite) throws ActivationException;
+
+ /**
+ * Stop components in a composite
+ * @param composite
+ */
+ void stop(Composite composite) throws ActivationException;
+
+ /**
+ * Get the component context helper
+ * @return
+ */
+ CompositeContext getCompositeContext();
+
+ /**
+ * Configure the runtime component with component context
+ * @param component
+ */
+ void configureComponentContext(RuntimeComponent component);
+
+ /**
+ * Resolve a component by URI in the domain
+ * @param componentURI
+ * @return
+ */
+ Component resolve(String componentURI);
+
+ /**
+ * Set the domain composite
+ * @param domainComposite
+ */
+ void setDomainComposite(Composite domainComposite);
+
+ /**
+ * Get the domain composite
+ * @return
+ */
+ Composite getDomainComposite();
+
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointSerializer.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointSerializer.java
new file mode 100644
index 0000000000..4617901c5b
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointSerializer.java
@@ -0,0 +1,38 @@
+/*
+ * 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.sca.core.assembly;
+
+import java.io.IOException;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+
+/**
+ * A utility to seralize/deserialize Endpoint/EndpointReference objects
+ */
+public interface EndpointSerializer {
+ void read(Endpoint endpoint, String xml) throws IOException;
+
+ String write(Endpoint endpoint) throws IOException;
+
+ void read(EndpointReference endpointReference, String xml) throws IOException;
+
+ String write(EndpointReference endpointReference) throws IOException;
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java
new file mode 100644
index 0000000000..8c84a9e399
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java
@@ -0,0 +1,74 @@
+/*
+ * 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.sca.core.assembly;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentImpl;
+import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentReferenceImpl;
+import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentServiceImpl;
+import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointImpl;
+import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointReferenceImpl;
+
+
+/**
+ * The runtime version of assembly factory
+ * @version $Rev$ $Date$
+ */
+public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements AssemblyFactory {
+
+ public RuntimeAssemblyFactory(ExtensionPointRegistry registry) {
+ super(registry);
+ }
+
+ @Override
+ public Component createComponent() {
+ return new RuntimeComponentImpl();
+ }
+
+ @Override
+ public ComponentReference createComponentReference() {
+ return new RuntimeComponentReferenceImpl();
+ }
+
+ @Override
+ public ComponentService createComponentService() {
+ return new RuntimeComponentServiceImpl();
+ }
+
+ @Override
+ public Endpoint createEndpoint() {
+ // Create an instance of EndpointImpl that can be serialized/deserialized using the Tuscany
+ // runtime extension points and extensions
+ return new RuntimeEndpointImpl(registry);
+ }
+
+ @Override
+ public EndpointReference createEndpointReference() {
+ return new RuntimeEndpointReferenceImpl(registry);
+ }
+
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
new file mode 100644
index 0000000000..27fad24b1f
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
@@ -0,0 +1,876 @@
+/*
+ * 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.sca.core.assembly.impl;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.context.ComponentContextFactory;
+import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint;
+import org.apache.tuscany.sca.context.PropertyValueFactory;
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.context.CompositeContext;
+import org.apache.tuscany.sca.core.context.impl.CompositeContextImpl;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.invocation.ExtensibleWireProcessor;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.scope.Scope;
+import org.apache.tuscany.sca.core.scope.ScopeContainer;
+import org.apache.tuscany.sca.core.scope.ScopeRegistry;
+import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent;
+import org.apache.tuscany.sca.core.scope.impl.ConversationalScopeContainer;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.PolicyProviderFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeActivatorImpl implements CompositeActivator {
+ final Logger logger = Logger.getLogger(CompositeActivatorImpl.class.getName());
+
+ private final ExtensionPointRegistry extensionPoints;
+ private final AssemblyFactory assemblyFactory;
+ private final MessageFactory messageFactory;
+ private final InterfaceContractMapper interfaceContractMapper;
+ private final ScopeRegistry scopeRegistry;
+ private final WorkScheduler workScheduler;
+ private final RuntimeWireProcessor wireProcessor;
+ private final ProviderFactoryExtensionPoint providerFactories;
+
+ private final ComponentContextFactory componentContextFactory;
+ private final RequestContextFactory requestContextFactory;
+ private final ProxyFactory proxyFactory;
+ private final JavaInterfaceFactory javaInterfaceFactory;
+ private final PropertyValueFactory propertyValueFactory;
+ private final EndpointRegistry endpointRegistry;
+
+ private final ConversationManager conversationManager;
+
+ private final CompositeContext compositeContext;
+
+ private Composite domainComposite;
+
+ public CompositeActivatorImpl(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+ this.compositeContext = new CompositeContextImpl(extensionPoints);
+ FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
+ this.messageFactory = factories.getFactory(MessageFactory.class);
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class);
+ this.scopeRegistry = utilities.getUtility(ScopeRegistry.class);
+ this.workScheduler = utilities.getUtility(WorkScheduler.class);
+ this.wireProcessor = new ExtensibleWireProcessor(extensionPoints.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class));
+ this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+ this.javaInterfaceFactory = compositeContext.getJavaInterfaceFactory();
+ this.propertyValueFactory = factories.getFactory(PropertyValueFactory.class);
+ ContextFactoryExtensionPoint contextFactories = extensionPoints.getExtensionPoint(ContextFactoryExtensionPoint.class);
+ this.componentContextFactory = contextFactories.getFactory(ComponentContextFactory.class);
+ this.requestContextFactory = contextFactories.getFactory(RequestContextFactory.class);
+ proxyFactory = compositeContext.getProxyFactory();
+ this.conversationManager = compositeContext.getConversationManager();
+ this.endpointRegistry = utilities.getUtility(EndpointRegistry.class);
+ }
+
+ //=========================================================================
+ // Activation
+ //=========================================================================
+
+ // Composite activation/deactivation
+
+ public void activate(Composite composite) throws ActivationException {
+ try {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Activating composite: " + composite.getName());
+ }
+ for (Component component : composite.getComponents()) {
+ activateComponent(component);
+ }
+ } catch (Exception e) {
+ throw new ActivationException(e);
+ }
+ }
+
+ public void deactivate(Composite composite) throws ActivationException {
+ try {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Deactivating composite: " + composite.getName());
+ }
+ for (Component component : composite.getComponents()) {
+ deactivateComponent(component);
+ }
+ } catch (Exception e) {
+ throw new ActivationException(e);
+ }
+ }
+
+ // Component activation/deactivation
+
+ public void activateComponent(Component component)
+ throws ActivationException {
+ try {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Activating component: " + component.getURI());
+ }
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ activate((Composite) implementation);
+ } else if (implementation != null) {
+ addImplementationProvider((RuntimeComponent) component,
+ implementation);
+ addScopeContainer(component);
+ }
+
+ for (ComponentService service : component.getServices()) {
+ activate((RuntimeComponent) component,
+ (RuntimeComponentService) service);
+ }
+
+ for (ComponentReference reference : component.getReferences()) {
+ activate((RuntimeComponent) component,
+ (RuntimeComponentReference) reference);
+ }
+ } catch (Exception e) {
+ throw new ActivationException(e);
+ }
+ }
+
+ public void deactivateComponent(Component component)
+ throws ActivationException {
+ try {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Deactivating component: " + component.getURI());
+ }
+ for (ComponentService service : component.getServices()) {
+ deactivate((RuntimeComponent) component,
+ (RuntimeComponentService) service);
+ }
+
+ for (ComponentReference reference : component.getReferences()) {
+ deactivate((RuntimeComponent) component,
+ (RuntimeComponentReference) reference);
+ }
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ deactivate((Composite) implementation);
+ } else if (implementation != null) {
+ removeImplementationProvider((RuntimeComponent) component);
+ removeScopeContainer(component);
+ }
+ } catch (Exception e) {
+ throw new ActivationException(e);
+ }
+ }
+
+ // add/remove artifacts required to get the implementation going
+
+ private void addImplementationProvider(RuntimeComponent component, Implementation implementation) {
+ ImplementationProviderFactory providerFactory =
+ (ImplementationProviderFactory)providerFactories.getProviderFactory(implementation.getClass());
+ if (providerFactory != null) {
+ @SuppressWarnings("unchecked")
+ ImplementationProvider implementationProvider =
+ providerFactory.createImplementationProvider(component, implementation);
+ if (implementationProvider != null) {
+ component.setImplementationProvider(implementationProvider);
+ }
+ } else {
+ throw new IllegalStateException("Provider factory not found for class: " + implementation.getClass()
+ .getName());
+ }
+ for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) {
+ PolicyProvider policyProvider = f.createImplementationPolicyProvider(component, implementation);
+ if (policyProvider != null) {
+ component.addPolicyProvider(policyProvider);
+ }
+ }
+
+ }
+
+ private void removeImplementationProvider(RuntimeComponent component) {
+ component.setImplementationProvider(null);
+ component.getPolicyProviders().clear();
+ }
+
+ private void addScopeContainer(Component component) {
+ if (!(component instanceof ScopedRuntimeComponent)) {
+ return;
+ }
+ ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
+ ScopeContainer scopeContainer = scopeRegistry.getScopeContainer(runtimeComponent);
+ if (scopeContainer != null && scopeContainer.getScope() == Scope.CONVERSATION) {
+ conversationManager.addListener((ConversationalScopeContainer)scopeContainer);
+ }
+ runtimeComponent.setScopeContainer(scopeContainer);
+ }
+
+ private void removeScopeContainer(Component component) {
+ if (!(component instanceof ScopedRuntimeComponent)) {
+ return;
+ }
+ ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
+ ScopeContainer scopeContainer = runtimeComponent.getScopeContainer();
+ if(scopeContainer != null && scopeContainer.getScope() == Scope.CONVERSATION) {
+ conversationManager.removeListener((ConversationalScopeContainer) scopeContainer);
+ }
+ runtimeComponent.setScopeContainer(null);
+ }
+
+
+ // Service activation/deactivation
+
+ public void activate(RuntimeComponent component, RuntimeComponentService service) {
+ if (service.getService() == null) {
+ if (logger.isLoggable(Level.WARNING)) {
+ logger.warning("Skipping component service not defined in the component type: " + component.getURI()
+ + "#"
+ + service.getName());
+ }
+ return;
+ }
+
+ /* TODO - EPR - activate services at all levels as promoted endpoin references are maintained
+ * on the higher level services
+ if (service.getService() instanceof CompositeService) {
+ return;
+ }
+ */
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Activating component service: " + component.getURI() + "#" + service.getName());
+ }
+
+ for (Endpoint endpoint : service.getEndpoints()) {
+ addServiceBindingProvider(component, service, endpoint.getBinding());
+ }
+ addServiceWires(component, service);
+ }
+
+ public void deactivate(RuntimeComponent component, RuntimeComponentService service) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Deactivating component service: " + component.getURI() + "#" + service.getName());
+ }
+ removeServiceWires(service);
+ for (Binding binding : service.getBindings()) {
+ removeServiceBindingProvider(component, service, binding);
+ }
+ }
+
+ private ServiceBindingProvider addServiceBindingProvider(
+ RuntimeComponent component, RuntimeComponentService service,
+ Binding binding) {
+ BindingProviderFactory providerFactory = (BindingProviderFactory) providerFactories
+ .getProviderFactory(binding.getClass());
+ if (providerFactory != null) {
+ @SuppressWarnings("unchecked")
+ ServiceBindingProvider bindingProvider = providerFactory
+ .createServiceBindingProvider((RuntimeComponent) component,
+ (RuntimeComponentService) service, binding);
+ if (bindingProvider != null) {
+ ((RuntimeComponentService) service).setBindingProvider(binding,
+ bindingProvider);
+ }
+ for (PolicyProviderFactory f : providerFactories
+ .getPolicyProviderFactories()) {
+ PolicyProvider policyProvider = f.createServicePolicyProvider(
+ component, service, binding);
+ if (policyProvider != null) {
+ service.addPolicyProvider(binding, policyProvider);
+ }
+ }
+ return bindingProvider;
+ } else {
+ throw new IllegalStateException(
+ "Provider factory not found for class: "
+ + binding.getClass().getName());
+ }
+ }
+
+ private void removeServiceBindingProvider(RuntimeComponent component,
+ RuntimeComponentService service, Binding binding) {
+ service.setBindingProvider(binding, null);
+ for (Binding b : service.getBindings()) {
+ List<PolicyProvider> pps = service.getPolicyProviders(b);
+ if (pps != null) {
+ pps.clear();
+ }
+ }
+ }
+
+ private void addServiceWires(Component serviceComponent, ComponentService service) {
+ if (!(service instanceof RuntimeComponentService)) {
+ return;
+ }
+
+ RuntimeComponentService runtimeService = (RuntimeComponentService)service;
+
+ // Add a wire for each service Endpoint
+ for ( Endpoint endpoint : runtimeService.getEndpoints()){
+
+ // fluff up a fake endpoint reference as we are on the service side
+ // so we need to represent the reference that will call us
+ EndpointReference endpointReference = assemblyFactory.createEndpointReference();
+ endpointReference.setBinding(endpoint.getBinding());
+ endpointReference.setTargetEndpoint(endpoint);
+
+ // create the interface contract for the binding and service ends of the wire
+ // that are created as forward only contracts
+ // FIXME: [rfeng] We might need a better way to get the impl interface contract
+ Service targetService = service.getService();
+ if (targetService == null) {
+ targetService = service;
+ }
+ endpoint.setInterfaceContract(targetService.getInterfaceContract().makeUnidirectional(false));
+ endpointReference.setInterfaceContract(getServiceBindingInterfaceContract(service, endpoint.getBinding()));
+
+ // create the wire
+ RuntimeWire wire = new RuntimeWireImpl(extensionPoints,
+ false,
+ endpointReference,
+ endpoint,
+ interfaceContractMapper,
+ workScheduler,
+ wireProcessor,
+ messageFactory,
+ conversationManager);
+
+ runtimeService.getRuntimeWires().add(wire);
+ }
+ }
+
+ private void removeServiceWires(ComponentService service) {
+ if (!(service instanceof RuntimeComponentService)) {
+ return;
+ }
+ RuntimeComponentService runtimeService = (RuntimeComponentService)service;
+ runtimeService.getRuntimeWires().clear();
+ }
+
+ private InterfaceContract getServiceBindingInterfaceContract(ComponentService service, Binding binding) {
+ InterfaceContract interfaceContract = service.getInterfaceContract();
+
+ ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding);
+ if (provider != null) {
+ InterfaceContract bindingContract = provider.getBindingInterfaceContract();
+ if (bindingContract != null) {
+ interfaceContract = bindingContract;
+ }
+ }
+ return interfaceContract.makeUnidirectional(false);
+ }
+
+ // Reference activation/deactivation
+
+ public void activate(RuntimeComponent component, RuntimeComponentReference reference) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Activating component reference: " + component.getURI() + "#" + reference.getName());
+ }
+
+ // set the parent component onto the reference. It's used at start time when the
+ // reference is asked to return it's runtime wires. If there are none the reference
+ // asks the component context to start the reference which creates the wires
+ reference.setComponent(component);
+
+ // TODO reference wires are added at component start for some reason
+ }
+
+ public void deactivate(RuntimeComponent component, RuntimeComponentReference reference) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Deactivating component reference: " + component.getURI() + "#" + reference.getName());
+ }
+ removeReferenceWires(reference);
+ for (EndpointReference endpointReference : reference.getEndpointReferences()) {
+ if (endpointReference.getBinding() != null){
+ removeReferenceBindingProvider(component, reference, endpointReference.getBinding());
+ }
+ }
+ }
+/*
+ private ReferenceBindingProvider addReferenceBindingProvider(
+ RuntimeComponent component, RuntimeComponentReference reference,
+ Binding binding) {
+ BindingProviderFactory providerFactory = (BindingProviderFactory) providerFactories
+ .getProviderFactory(binding.getClass());
+ if (providerFactory != null) {
+ @SuppressWarnings("unchecked")
+ ReferenceBindingProvider bindingProvider = providerFactory
+ .createReferenceBindingProvider(
+ (RuntimeComponent) component,
+ (RuntimeComponentReference) reference, binding);
+ if (bindingProvider != null) {
+ ((RuntimeComponentReference) reference).setBindingProvider(
+ binding, bindingProvider);
+ }
+ for (PolicyProviderFactory f : providerFactories
+ .getPolicyProviderFactories()) {
+ PolicyProvider policyProvider = f
+ .createReferencePolicyProvider(component, reference,
+ binding);
+ if (policyProvider != null) {
+ reference.addPolicyProvider(binding, policyProvider);
+ }
+ }
+
+ return bindingProvider;
+ } else {
+ throw new IllegalStateException(
+ "Provider factory not found for class: "
+ + binding.getClass().getName());
+ }
+ }
+*/
+ private void removeReferenceBindingProvider(RuntimeComponent component,
+ RuntimeComponentReference reference, Binding binding) {
+ reference.setBindingProvider(binding, null);
+ for (Binding b : reference.getBindings()) {
+ List<PolicyProvider> pps = reference.getPolicyProviders(b);
+ if (pps != null) {
+ pps.clear();
+ }
+ }
+ }
+
+ private void removeReferenceWires(ComponentReference reference) {
+ if (!(reference instanceof RuntimeComponentReference)) {
+ return;
+ }
+
+ // TODO - EPR what is this all about?
+ // [rfeng] Comment out the following statements to avoid the on-demand activation
+ // RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
+ // runtimeRef.getRuntimeWires().clear();
+ }
+
+ //=========================================================================
+ // Start
+ //=========================================================================
+
+ // Composite start/stop
+
+ public void start(Composite composite) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Starting composite: " + composite.getName());
+ }
+ for (Component component : composite.getComponents()) {
+ start(component);
+ }
+ }
+
+ public void stop(Composite composite) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Stopping composite: " + composite.getName());
+ }
+ for (final Component component : composite.getComponents()) {
+ stop(component);
+ }
+ }
+
+ // Component start/stop
+
+ public void start(Component component) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Starting component: " + component.getURI());
+ }
+ RuntimeComponent runtimeComponent = ((RuntimeComponent)component);
+ if(runtimeComponent.isStarted()) {
+ return;
+ }
+
+ configureComponentContext(runtimeComponent);
+
+ // Reference bindings aren't started until the wire is first used
+
+ for (ComponentService service : component.getServices()) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Starting component service: " + component.getURI() + "#" + service.getName());
+ }
+ RuntimeComponentService runtimeService = (RuntimeComponentService)service;
+ for (Endpoint endpoint : service.getEndpoints()) {
+ endpointRegistry.addEndpoint(endpoint);
+ final ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(endpoint.getBinding());
+ if (bindingProvider != null) {
+ // bindingProvider.start();
+ // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ bindingProvider.start();
+ return null;
+ }
+ });
+ }
+ }
+ }
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ start((Composite)implementation);
+ } else {
+ ImplementationProvider implementationProvider = runtimeComponent.getImplementationProvider();
+ if (implementationProvider != null) {
+ implementationProvider.start();
+ }
+ }
+
+ if (component instanceof ScopedRuntimeComponent) {
+ ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component;
+ if (scopedRuntimeComponent.getScopeContainer() != null) {
+ scopedRuntimeComponent.getScopeContainer().start();
+ }
+ }
+
+ runtimeComponent.setStarted(true);
+ }
+
+ public void stop(Component component) {
+ if (!((RuntimeComponent)component).isStarted()) {
+ return;
+ }
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Stopping component: " + component.getURI());
+ }
+ for (ComponentService service : component.getServices()) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Stopping component service: " + component.getURI() + "#" + service.getName());
+ }
+ for (Endpoint endpoint : service.getEndpoints()) {
+ endpointRegistry.removeEndpoint(endpoint);
+ final ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service).getBindingProvider(endpoint.getBinding());
+ if (bindingProvider != null) {
+ // Allow bindings to read properties. Requires PropertyPermission read in security policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ bindingProvider.stop();
+ return null;
+ }
+ });
+ }
+ }
+ }
+ for (ComponentReference reference : component.getReferences()) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName());
+ }
+ RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
+
+ for (EndpointReference endpointReference : reference.getEndpointReferences()) {
+ final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
+ if (bindingProvider != null) {
+ // Allow bindings to read properties. Requires PropertyPermission read in security policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ bindingProvider.stop();
+ return null;
+ }
+ });
+ }
+ }
+ }
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ stop((Composite)implementation);
+ } else {
+ final ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider();
+ if (implementationProvider != null) {
+ // Allow bindings to read properties. Requires PropertyPermission read in security policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ implementationProvider.stop();
+ return null;
+ }
+ });
+ }
+ }
+
+ if (component instanceof ScopedRuntimeComponent) {
+ ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
+ if (runtimeComponent.getScopeContainer() != null &&
+ runtimeComponent.getScopeContainer().getLifecycleState() != ScopeContainer.STOPPED) {
+ runtimeComponent.getScopeContainer().stop();
+ }
+ }
+
+ ((RuntimeComponent)component).setStarted(false);
+ }
+
+ public void configureComponentContext(RuntimeComponent runtimeComponent) {
+ RuntimeComponentContext componentContext = (RuntimeComponentContext) componentContextFactory.createComponentContext(runtimeComponent);
+ runtimeComponent.setComponentContext(componentContext);
+ }
+
+ // Service start/stop
+
+ // TODO - EPR done as part of the component start above
+
+ // Reference start/stop
+ // Used by component context start
+ // TODO - EPR I don't know why reference wires don't get added until component start
+
+ public void start(RuntimeComponent component, RuntimeComponentReference componentReference) {
+ synchronized (componentReference) {
+
+ if (!(componentReference instanceof RuntimeComponentReference)) {
+ return;
+ }
+
+ /* The way it was
+ // create a wire for each endpoint reference. An endpoint reference says that a
+ // target has been specified and hence the reference has been wired in some way.
+ // The service may not have been found yet, depending on the way the composite
+ // is deployed, but it is expected to be found. In the case where the reference
+ // is unwired (a target has not been specified) there will be no endpoint
+ // reference and this will lead to null being injected
+ for (EndpointReference2 endpointReference : componentReference.getEndpointReferences()){
+
+ // if there is a binding an endpoint has been found for the endpoint reference
+ if (endpointReference.getBinding() != null){
+
+ // add the binding provider. This is apparently a repeat
+ // of previous configuration as self references are created
+ // on the fly and miss the previous point where providers are added
+ RuntimeComponentReference runtimeRef = (RuntimeComponentReference)componentReference;
+
+ if (runtimeRef.getBindingProvider(endpointReference.getBinding()) == null) {
+ addReferenceBindingProvider(component, componentReference, endpointReference.getBinding());
+ }
+
+ // start the binding provider
+ final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
+
+ if (bindingProvider != null) {
+ // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ bindingProvider.start();
+ return null;
+ }
+ });
+ }
+
+ // add the wire
+ addReferenceWire(component, componentReference, endpointReference);
+ }
+ }
+ */
+
+ // create a wire for each endpoint reference. An endpoint reference says either that
+ // - a target has been specified and hence the reference has been wired in some way.
+ // - an unwired binding ha been specified
+ // and endpoint reference representing a wired reference may not at this point
+ // be resolved (the service to which it points may not be present in the
+ // current composite). Endpoint reference resolution takes place when the wire
+ // is first used (when the chains are created)
+ for (EndpointReference endpointReference : componentReference.getEndpointReferences()){
+ addReferenceWire(component, componentReference, endpointReference);
+ endpointRegistry.addEndpointReference(endpointReference);
+ }
+
+ }
+ }
+
+ public void stop(Component component, ComponentReference reference) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Stopping component reference: " + component.getURI() + "#" + reference.getName());
+ }
+ RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
+ for ( EndpointReference endpointReference : runtimeRef.getEndpointReferences()){
+ endpointRegistry.removeEndpointReference(endpointReference);
+ ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
+ if (bindingProvider != null) {
+ bindingProvider.stop();
+ }
+ }
+ }
+
+ private void addReferenceWire(Component component, ComponentReference reference, EndpointReference endpointReference) {
+ RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
+
+ // Use the interface contract of the reference on the component type and if there
+ // isn't one then use the one from the reference itself
+ Reference componentTypeRef = reference.getReference();
+
+ InterfaceContract sourceContract;
+ if (componentTypeRef == null || componentTypeRef.getInterfaceContract() == null) {
+ sourceContract = reference.getInterfaceContract();
+ } else {
+ sourceContract = componentTypeRef.getInterfaceContract();
+ }
+
+ // TODO - EPR - interface contract seems to be null in the implementation.web
+ // case. Not introspecting the CT properly?
+ if (sourceContract == null){
+ // TODO - Can't do this with move of matching to wire
+ // take the contract from the service to which the reference is connected
+ sourceContract = endpointReference.getTargetEndpoint().getInterfaceContract();
+ reference.setInterfaceContract(sourceContract);
+ }
+
+ endpointReference.setInterfaceContract(sourceContract.makeUnidirectional(false));
+
+/* TODO - EPR should have been done previously during matching
+ ComponentService callbackService = reference.getCallbackService();
+ if (callbackService != null) {
+ // select a reference callback binding to pass with invocations on this wire
+ Binding callbackBinding = null;
+ for (Binding binding : callbackService.getBindings()) {
+ // first look for a callback binding whose name matches the reference binding name
+ if (refBinding.getName().startsWith(binding.getName())) {
+ callbackBinding = binding;
+ break;
+ }
+ }
+ // if no callback binding found, try again based on reference binding type
+ if (callbackBinding == null) {
+ callbackBinding = callbackService.getBinding(refBinding.getClass());
+ }
+ InterfaceContract callbackContract = callbackService.getInterfaceContract();
+ EndpointReference callbackEndpoint =
+ new EndpointReferenceImpl((RuntimeComponent)refComponent, callbackService, callbackBinding,
+ callbackContract);
+ wireSource.setCallbackEndpoint(callbackEndpoint);
+ }
+*/
+
+/* TODO - EPR can't do this until the binding matches the EPR
+ InterfaceContract bindingContract = getInterfaceContract(reference, endpointReference.getBinding());
+ Endpoint2 endpoint = endpointReference.getTargetEndpoint();
+ endpoint.setInterfaceContract(bindingContract);
+*/
+
+/* TODO - EPR review in the light of new matching code
+ // TUSCANY-2029 - We should use the URI of the serviceBinding because the target may be a Component in a
+ // nested composite.
+ if (serviceBinding != null) {
+ wireTarget.setURI(serviceBinding.getURI());
+ }
+*/
+
+ // create the wire
+ // null endpoint passed in here as the endpoint reference may
+ // not be resolved yet
+ RuntimeWire wire = new RuntimeWireImpl(extensionPoints,
+ true,
+ endpointReference,
+ null,
+ interfaceContractMapper,
+ workScheduler,
+ wireProcessor,
+ messageFactory,
+ conversationManager);
+ runtimeRef.getRuntimeWires().add(wire);
+
+ }
+
+ private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) {
+ InterfaceContract interfaceContract = reference.getInterfaceContract();
+ ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
+ if (provider != null) {
+ InterfaceContract bindingContract = provider.getBindingInterfaceContract();
+ if (bindingContract != null) {
+ interfaceContract = bindingContract;
+ }
+ }
+ return interfaceContract.makeUnidirectional(false);
+ }
+
+
+
+ // Utility functions
+ // TODO - can we get rid of these?
+
+ public CompositeContext getCompositeContext() {
+ return compositeContext;
+ }
+
+ public Composite getDomainComposite() {
+ return domainComposite;
+ }
+
+ public void setDomainComposite(Composite domainComposite) {
+ this.domainComposite = domainComposite;
+ }
+
+ public Component resolve(String componentURI) {
+ for (Composite composite : domainComposite.getIncludes()) {
+ Component component = resolve(composite, componentURI);
+ if (component != null) {
+ return component;
+ }
+ }
+ return null;
+ }
+
+ public Component resolve(Composite composite, String componentURI) {
+ for (Component component : composite.getComponents()) {
+ String uri = component.getURI();
+ if (uri.equals(componentURI)) {
+ return component;
+ }
+ if (componentURI.startsWith(uri)) {
+ Implementation implementation = component.getImplementation();
+ if (!(implementation instanceof Composite)) {
+ return null;
+ }
+ return resolve((Composite)implementation, componentURI);
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java
new file mode 100644
index 0000000000..b9eb6c117b
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java
@@ -0,0 +1,108 @@
+/*
+ * 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.sca.core.assembly.impl;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.EndpointSerializer;
+
+public class EndpointSerializerImpl implements EndpointSerializer {
+ private XMLInputFactory inputFactory;
+ private XMLOutputFactory outputFactory;
+ private StAXArtifactProcessor<Endpoint> processor;
+ private StAXArtifactProcessor<EndpointReference> refProcessor;
+
+ public EndpointSerializerImpl(ExtensionPointRegistry registry) {
+ FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ inputFactory = factories.getFactory(XMLInputFactory.class);
+ outputFactory = factories.getFactory(XMLOutputFactory.class);
+ StAXArtifactProcessorExtensionPoint processors =
+ registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ processor = processors.getProcessor(Endpoint.class);
+ refProcessor = processors.getProcessor(EndpointReference.class);
+ }
+
+ public void read(Endpoint endpoint, String xml) throws IOException {
+ try {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xml));
+ Endpoint result = processor.read(reader);
+ endpoint.setComponent(result.getComponent());
+ endpoint.setService(result.getService());
+ endpoint.setBinding(result.getBinding());
+ endpoint.setInterfaceContract(result.getService().getInterfaceContract());
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+
+ }
+
+ public String write(Endpoint endpoint) throws IOException {
+ StringWriter sw = new StringWriter();
+ try {
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
+ processor.write(endpoint, writer);
+ writer.flush();
+ writer.close();
+ return sw.toString();
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ public void read(EndpointReference endpointReference, String xml) throws IOException {
+ try {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xml));
+ EndpointReference result = refProcessor.read(reader);
+ reader.close();
+ endpointReference.setComponent(result.getComponent());
+ endpointReference.setReference(result.getReference());
+ endpointReference.setBinding(result.getBinding());
+ endpointReference.setInterfaceContract(result.getReference().getInterfaceContract());
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ public String write(EndpointReference endpointReference) throws IOException {
+ StringWriter sw = new StringWriter();
+ try {
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
+ refProcessor.write(endpointReference, writer);
+ writer.flush();
+ writer.close();
+ return sw.toString();
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+} \ No newline at end of file
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParameterProcessor.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParameterProcessor.java
new file mode 100644
index 0000000000..2c833a885e
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParameterProcessor.java
@@ -0,0 +1,101 @@
+/*
+ * 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.sca.core.assembly.impl;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+
+/**
+ * Artifact processor for reference parameters.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReferenceParameterProcessor implements StAXArtifactProcessor<ReferenceParameters> {
+ private static final QName REFERENCE_PARAMETERS =
+ new QName("http://tuscany.apache.org/xmlns/sca/1.1", "referenceParameters", "tuscany");
+
+ /**
+ * Constructs a new processor.
+ *
+ * @param modelFactories
+ */
+ public ReferenceParameterProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#getArtifactType()
+ */
+ public QName getArtifactType() {
+ return REFERENCE_PARAMETERS;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#read(javax.xml.stream.XMLStreamReader)
+ */
+ public ReferenceParameters read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ ReferenceParameters parameters = new ReferenceParametersImpl();
+ parameters.setConversationID(reader.getAttributeValue(null, "conversationID"));
+ parameters.setCallbackID(reader.getAttributeValue(null, "callbackID"));
+ return parameters;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#write(java.lang.Object, javax.xml.stream.XMLStreamWriter)
+ */
+ public void write(ReferenceParameters model, XMLStreamWriter writer) throws ContributionWriteException,
+ XMLStreamException {
+ writer.writeStartElement(REFERENCE_PARAMETERS.getPrefix(),
+ REFERENCE_PARAMETERS.getLocalPart(),
+ REFERENCE_PARAMETERS.getNamespaceURI());
+ writer.writeNamespace(REFERENCE_PARAMETERS.getPrefix(), REFERENCE_PARAMETERS.getNamespaceURI());
+ if (model.getConversationID() != null) {
+ writer.writeAttribute("conversationID", model.getConversationID().toString());
+ }
+ if (model.getCallbackID() != null) {
+ writer.writeAttribute("callbackID", model.getCallbackID().toString());
+ }
+ writer.writeEndElement();
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#getModelType()
+ */
+ public Class<ReferenceParameters> getModelType() {
+ return ReferenceParameters.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#resolve(java.lang.Object, org.apache.tuscany.sca.contribution.resolver.ModelResolver)
+ */
+ public void resolve(ReferenceParameters model, ModelResolver resolver) throws ContributionResolveException {
+ }
+
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParametersImpl.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParametersImpl.java
new file mode 100644
index 0000000000..b2b8c86919
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParametersImpl.java
@@ -0,0 +1,139 @@
+/*
+ * 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.sca.core.assembly.impl;
+
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceParametersImpl implements ReferenceParameters {
+ private Object callbackID;
+ private Object conversationID;
+ private EndpointReference callbackReference;
+ private Object callbackObjectID;
+
+ /**
+ * @return the callbackID
+ */
+ public Object getCallbackID() {
+ return callbackID;
+ }
+ /**
+ * @param callbackID the callbackID to set
+ */
+ public void setCallbackID(Object callbackID) {
+ this.callbackID = callbackID;
+ }
+ /**
+ * @return the conversationID
+ */
+ public Object getConversationID() {
+ return conversationID;
+ }
+ /**
+ * @param conversationID the conversationID to set
+ */
+ public void setConversationID(Object conversationID) {
+ this.conversationID = conversationID;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.runtime.ReferenceParameters#getCallbackReference()
+ */
+ public EndpointReference getCallbackReference() {
+ return callbackReference;
+ }
+ /**
+ * @see org.apache.tuscany.sca.runtime.ReferenceParameters#setCallback(java.lang.Object)
+ */
+ public void setCallbackReference(EndpointReference callback) {
+ this.callbackReference = callback;
+ }
+
+ /**
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ /**
+ * @return the callbackObjectID
+ */
+ public Object getCallbackObjectID() {
+ return callbackObjectID;
+ }
+ /**
+ * @param callbackObjectID the callbackObjectID to set
+ */
+ public void setCallbackObjectID(Object callbackObjectID) {
+ this.callbackObjectID = callbackObjectID;
+ }
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((callbackID == null) ? 0 : callbackID.hashCode());
+ result = prime * result + ((callbackObjectID == null) ? 0 : callbackObjectID.hashCode());
+ result = prime * result + ((callbackReference == null) ? 0 : callbackReference.hashCode());
+ result = prime * result + ((conversationID == null) ? 0 : conversationID.hashCode());
+ return result;
+ }
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof ReferenceParametersImpl))
+ return false;
+ final ReferenceParametersImpl other = (ReferenceParametersImpl)obj;
+ if (callbackID == null) {
+ if (other.callbackID != null)
+ return false;
+ } else if (!callbackID.equals(other.callbackID))
+ return false;
+ if (callbackObjectID == null) {
+ if (other.callbackObjectID != null)
+ return false;
+ } else if (!callbackObjectID.equals(other.callbackObjectID))
+ return false;
+ if (callbackReference == null) {
+ if (other.callbackReference != null)
+ return false;
+ } else if (!callbackReference.equals(other.callbackReference))
+ return false;
+ if (conversationID == null) {
+ if (other.conversationID != null)
+ return false;
+ } else if (!conversationID.equals(other.conversationID))
+ return false;
+ return true;
+ }
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentImpl.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentImpl.java
new file mode 100644
index 0000000000..6032005b9a
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentImpl.java
@@ -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.sca.core.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.impl.ComponentImpl;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ResolverExtension;
+import org.apache.tuscany.sca.core.scope.ScopeContainer;
+import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RuntimeComponentImpl extends ComponentImpl implements RuntimeComponent,
+ ScopedRuntimeComponent, ResolverExtension {
+ protected RuntimeComponentContext componentContext;
+ protected ImplementationProvider implementationProvider;
+ protected List<PolicyProvider> policyProviders = new ArrayList<PolicyProvider>();
+ protected ScopeContainer scopeContainer;
+ protected boolean started;
+ protected ModelResolver modelResolver;
+
+ /**
+ */
+ public RuntimeComponentImpl() {
+ super();
+ }
+
+ public ImplementationProvider getImplementationProvider() {
+ return implementationProvider;
+ }
+
+ public void setImplementationProvider(ImplementationProvider provider) {
+ this.implementationProvider = provider;
+ }
+
+ public ScopeContainer getScopeContainer() {
+ return scopeContainer;
+ }
+
+ public void setScopeContainer(ScopeContainer scopeContainer) {
+ this.scopeContainer = scopeContainer;
+ }
+
+ public boolean isStarted() {
+ return started;
+ }
+
+ public void setStarted(boolean started) {
+ this.started = started;
+ }
+
+ /**
+ * @return the componentContext
+ */
+ public RuntimeComponentContext getComponentContext() {
+ return componentContext;
+ }
+
+ /**
+ * @param componentContext the componentContext to set
+ */
+ public void setComponentContext(RuntimeComponentContext componentContext) {
+ this.componentContext = componentContext;
+ }
+
+ public void addPolicyProvider(PolicyProvider policyProvider) {
+ policyProviders.add(policyProvider);
+ }
+
+ public List<PolicyProvider> getPolicyProviders() {
+ return policyProviders;
+ }
+
+ public ModelResolver getModelResolver() {
+ return modelResolver;
+ }
+
+ public void setModelResolver(ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java
new file mode 100644
index 0000000000..c0a9f616f6
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java
@@ -0,0 +1,144 @@
+/*
+ * 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.sca.core.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+
+/**
+ * Implementation of a Component Reference.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implements RuntimeComponentReference {
+ private ArrayList<RuntimeWire> wires;
+ private HashMap<Binding, ReferenceBindingProvider> bindingProviders =
+ new HashMap<Binding, ReferenceBindingProvider>();
+ private HashMap<Binding, List<PolicyProvider>> policyProviders = new HashMap<Binding, List<PolicyProvider>>();
+
+ private RuntimeComponent component;
+
+ public RuntimeComponentReferenceImpl() {
+ super();
+ }
+
+ public synchronized List<RuntimeWire> getRuntimeWires() {
+ if (wires == null) {
+ wires = new ArrayList<RuntimeWire>();
+ component.getComponentContext().start(this);
+ }
+ return wires;
+ }
+
+ // TODO - EPR - shouldn't rely on this anymore
+ public RuntimeWire getRuntimeWire(Binding binding) {
+ for (RuntimeWire wire : getRuntimeWires()) {
+ if (wire.getEndpointReference().getBinding() == binding) {
+ return wire;
+ }
+ }
+
+ return null;
+ }
+
+ public RuntimeWire getRuntimeWire(EndpointReference endpointReference) {
+ for (RuntimeWire wire : getRuntimeWires()) {
+ if (wire.getEndpointReference() == endpointReference) {
+ return wire;
+ }
+ }
+
+ return null;
+ }
+
+ public ReferenceBindingProvider getBindingProvider(Binding binding) {
+ return bindingProviders.get(binding);
+ }
+
+ public void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider) {
+ bindingProviders.put(binding, bindingProvider);
+ }
+
+ public Invoker getInvoker(Binding binding, Operation operation) {
+ RuntimeWire wire = getRuntimeWire(binding);
+ if (wire == null) {
+ return null;
+ }
+ InvocationChain chain = wire.getInvocationChain(operation);
+ return chain == null ? null : chain.getHeadInvoker();
+ }
+
+ /**
+ * @return the component
+ */
+ public RuntimeComponent getComponent() {
+ return component;
+ }
+
+ /**
+ * @param component the component to set
+ */
+ public void setComponent(RuntimeComponent component) {
+ this.component = component;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl#clone()
+ */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ RuntimeComponentReferenceImpl ref = (RuntimeComponentReferenceImpl)super.clone();
+ ref.wires = null;
+ ref.bindingProviders = new HashMap<Binding, ReferenceBindingProvider>();
+ ref.policyProviders = new HashMap<Binding, List<PolicyProvider>>();
+ return ref;
+ }
+
+ public void addPolicyProvider(Binding binding, PolicyProvider policyProvider) {
+ List<PolicyProvider> providers = policyProviders.get(binding);
+ if (providers == null) {
+ providers = new ArrayList<PolicyProvider>();
+ policyProviders.put(binding, providers);
+ }
+ providers.add(policyProvider);
+ }
+
+ public List<PolicyProvider> getPolicyProviders(Binding binding) {
+ return policyProviders.get(binding);
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java
new file mode 100644
index 0000000000..776d35327d
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java
@@ -0,0 +1,163 @@
+/*
+ * 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.sca.core.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.oasisopen.sca.ServiceRuntimeException;
+
+/**
+ * Implementation of a Component Service.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements RuntimeComponentService {
+ private ArrayList<RuntimeWire> wires = new ArrayList<RuntimeWire>();
+ private ArrayList<RuntimeWire> callbackWires = new ArrayList<RuntimeWire>();
+ private HashMap<Binding, ServiceBindingProvider> bindingProviders = new HashMap<Binding, ServiceBindingProvider>();
+ private HashMap<Binding, List<PolicyProvider>> policyProviders = new HashMap<Binding, List<PolicyProvider>>();
+
+ public RuntimeComponentServiceImpl() {
+ super();
+ }
+
+ public List<RuntimeWire> getRuntimeWires() {
+ return wires;
+ }
+
+ public RuntimeWire getRuntimeWire(Binding binding) {
+ for (RuntimeWire wire : wires) {
+ if (wire.getEndpoint().getBinding() == binding) {
+ return wire;
+ }
+ }
+ return null;
+ }
+
+ public RuntimeWire getRuntimeWire(Binding binding, InterfaceContract interfaceContract) {
+ RuntimeWire wire = getRuntimeWire(binding);
+ if (wire == null) {
+ return null;
+ }
+ if (interfaceContract != null && interfaceContract != wire.getEndpointReference().getInterfaceContract()) {
+ try {
+ // FIXME: [rfeng] We could avoid clone() using a better comparison of the two interface contracts
+ wire = (RuntimeWire)wire.clone();
+ wire.getEndpointReference().setInterfaceContract(interfaceContract);
+ wire.rebuild();
+ } catch (CloneNotSupportedException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ return wire;
+ }
+
+ public List<RuntimeWire> getCallbackWires() {
+ return callbackWires;
+ }
+
+ public ServiceBindingProvider getBindingProvider(Binding binding) {
+ return bindingProviders.get(binding);
+ }
+
+ public void setBindingProvider(Binding binding, ServiceBindingProvider bindingProvider) {
+ bindingProviders.put(binding, bindingProvider);
+ }
+
+ public Invoker getInvoker(Binding binding, Operation operation) {
+ return getInvoker(binding, null, operation);
+ }
+
+ public Invoker getInvoker(Binding binding, InterfaceContract interfaceContract, Operation operation) {
+ InvocationChain chain = getInvocationChain(binding, interfaceContract, operation);
+ if (chain != null) {
+ return chain.getHeadInvoker();
+ } else {
+ return null;
+ }
+ }
+
+ public InvocationChain getInvocationChain(Binding binding, InterfaceContract interfaceContract, Operation operation) {
+ RuntimeWire wire = getRuntimeWire(binding);
+ if (wire == null) {
+ return null;
+ }
+ if (interfaceContract != null && interfaceContract != wire.getEndpointReference().getInterfaceContract()) {
+ try {
+ // FIXME: [rfeng] We could avoid clone() using a better comparison of the two interface contracts
+ wire = (RuntimeWire)wire.clone();
+ wire.getEndpointReference().setInterfaceContract(interfaceContract);
+ wire.rebuild();
+ } catch (CloneNotSupportedException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+ return wire.getInvocationChain(operation);
+ }
+
+ public InvocationChain getInvocationChain(Binding binding, Operation operation) {
+ return getInvocationChain(binding, null, operation);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl#clone()
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ RuntimeComponentServiceImpl clone = (RuntimeComponentServiceImpl)super.clone();
+ clone.bindingProviders = (HashMap<Binding, ServiceBindingProvider>)bindingProviders.clone();
+ clone.wires = (ArrayList<RuntimeWire>)wires.clone();
+ clone.callbackWires = (ArrayList<RuntimeWire>)callbackWires.clone();
+ clone.policyProviders = (HashMap<Binding, List<PolicyProvider>>)policyProviders.clone();
+ return clone;
+ }
+
+ public void addPolicyProvider(Binding binding, PolicyProvider policyProvider) {
+ List<PolicyProvider> providers = policyProviders.get(binding);
+ if (providers == null) {
+ providers = new ArrayList<PolicyProvider>();
+ policyProviders.put(binding, providers);
+ }
+ providers.add(policyProvider);
+ }
+
+ public List<PolicyProvider> getPolicyProviders(Binding binding) {
+ return policyProviders.get(binding);
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java
new file mode 100644
index 0000000000..f2ec7f8019
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java
@@ -0,0 +1,100 @@
+/*
+ * 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.sca.core.assembly.impl;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.apache.tuscany.sca.assembly.impl.EndpointImpl;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.EndpointSerializer;
+
+/**
+ * Runtime model for Endpoint that supports java serialization
+ */
+public class RuntimeEndpointImpl extends EndpointImpl implements Externalizable {
+ private EndpointSerializer serializer;
+ private String xml;
+
+ /**
+ * No-arg constructor for Java serilization
+ */
+ public RuntimeEndpointImpl() {
+ super(null);
+ }
+
+ public RuntimeEndpointImpl(ExtensionPointRegistry registry) {
+ super(registry);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ this.uri = in.readUTF();
+ this.xml = in.readUTF();
+ // Defer the loading to resolve();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeUTF(getURI());
+ out.writeUTF(getSerializer().write(this));
+ }
+
+ private synchronized EndpointSerializer getSerializer() {
+ if (serializer == null) {
+ if (registry != null) {
+ serializer =
+ registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(EndpointSerializer.class);
+ } else {
+ throw new IllegalStateException("No extension registry is set");
+ }
+ }
+ return serializer;
+ }
+
+ @Override
+ protected void reset() {
+ super.reset();
+ this.xml = null;
+ }
+
+ @Override
+ protected void resolve() {
+ if (component == null && xml != null) {
+ try {
+ getSerializer().read(this, xml);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ super.resolve();
+ }
+
+ @Override
+ public void setExtensionPointRegistry(ExtensionPointRegistry registry) {
+ if (this.registry != registry) {
+ super.setExtensionPointRegistry(registry);
+ serializer = null;
+ }
+ // resolve();
+ }
+
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
new file mode 100644
index 0000000000..36f49eac5e
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
@@ -0,0 +1,100 @@
+/*
+ * 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.sca.core.assembly.impl;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.apache.tuscany.sca.assembly.impl.EndpointReferenceImpl;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.EndpointSerializer;
+
+/**
+ * Runtime model for Endpoint that supports java serialization
+ */
+public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implements Externalizable {
+ private EndpointSerializer serializer;
+ private String xml;
+
+ /**
+ * No-arg constructor for Java serilization
+ */
+ public RuntimeEndpointReferenceImpl() {
+ super(null);
+ }
+
+ public RuntimeEndpointReferenceImpl(ExtensionPointRegistry registry) {
+ super(registry);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ this.uri = in.readUTF();
+ this.xml = in.readUTF();
+ // Defer the loading to resolve();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeUTF(getURI());
+ out.writeUTF(getSerializer().write(this));
+ }
+
+ private synchronized EndpointSerializer getSerializer() {
+ if (serializer == null) {
+ if (registry != null) {
+ serializer =
+ registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(EndpointSerializer.class);
+ } else {
+ throw new IllegalStateException("No extension registry is set");
+ }
+ }
+ return serializer;
+ }
+
+ @Override
+ protected void reset() {
+ super.reset();
+ this.xml = null;
+ }
+
+ @Override
+ protected void resolve() {
+ if (component == null && xml != null) {
+ try {
+ getSerializer().read(this, xml);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ super.resolve();
+ }
+
+ @Override
+ public void setExtensionPointRegistry(ExtensionPointRegistry registry) {
+ if (this.registry != registry) {
+ super.setExtensionPointRegistry(registry);
+ serializer = null;
+ }
+ // resolve();
+ }
+
+}
diff --git a/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java
new file mode 100644
index 0000000000..ada355d32e
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC5/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java
@@ -0,0 +1,680 @@
+/*
+ * 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.sca.core.assembly.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor;
+import org.apache.tuscany.sca.core.invocation.RuntimeWireInvoker;
+import org.apache.tuscany.sca.core.invocation.impl.InvocationChainImpl;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.PolicyProviderFactory;
+import org.apache.tuscany.sca.provider.PolicyProviderRRB;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.provider.ReferenceBindingProviderRRB;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProviderRRB;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+import org.apache.tuscany.sca.work.WorkScheduler;
+import org.oasisopen.sca.ServiceRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RuntimeWireImpl implements RuntimeWire {
+
+ ExtensionPointRegistry extensionPoints;
+
+ private Boolean isReferenceWire = false;
+ private EndpointReference endpointReference;
+ private Endpoint endpoint;
+
+ private transient RuntimeWireProcessor wireProcessor;
+ private transient InterfaceContractMapper interfaceContractMapper;
+ private transient WorkScheduler workScheduler;
+ private transient MessageFactory messageFactory;
+ private transient ConversationManager conversationManager;
+ private transient RuntimeWireInvoker invoker;
+
+ // the following is a very simple cache that avoids re-cloning a wire
+ // when consecutive callbacks to the same endpoint are made
+ private Endpoint lastCallback;
+ private RuntimeWire cachedWire;
+ private boolean wireReserved;
+ private RuntimeWireImpl clonedFrom;
+
+ private List<InvocationChain> chains;
+ private InvocationChain bindingInvocationChain;
+
+ private EndpointReferenceBuilder endpointReferenceBuilder;
+ private final ProviderFactoryExtensionPoint providerFactories;
+
+ /**
+ * @param source
+ * @param target
+ * @param interfaceContractMapper
+ * @param workScheduler
+ * @param wireProcessor
+ * @param messageFactory
+ * @param conversationManager
+ */
+ public RuntimeWireImpl(ExtensionPointRegistry extensionPoints,
+ boolean isReferenceWire,
+ EndpointReference endpointReference,
+ Endpoint endpoint,
+ InterfaceContractMapper interfaceContractMapper,
+ WorkScheduler workScheduler,
+ RuntimeWireProcessor wireProcessor,
+ MessageFactory messageFactory,
+ ConversationManager conversationManager) {
+ super();
+ this.extensionPoints = extensionPoints;
+ this.isReferenceWire = isReferenceWire;
+ this.endpointReference = endpointReference;
+ this.endpoint = endpoint;
+ this.interfaceContractMapper = interfaceContractMapper;
+ this.workScheduler = workScheduler;
+ this.wireProcessor = wireProcessor;
+ this.messageFactory = messageFactory;
+ this.conversationManager = conversationManager;
+ this.invoker = new RuntimeWireInvoker(this.messageFactory, this.conversationManager, this);
+
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ this.endpointReferenceBuilder = utilities.getUtility(EndpointReferenceBuilder.class);
+ this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+ }
+
+ public synchronized List<InvocationChain> getInvocationChains() {
+ if (chains == null) {
+ initInvocationChains();
+ }
+ return chains;
+ }
+
+ public synchronized InvocationChain getBindingInvocationChain() {
+ if (bindingInvocationChain == null) {
+ bindingInvocationChain = new InvocationChainImpl(null, null, isReferenceWire);
+ if (isReferenceWire) {
+ initReferenceBindingInvocationChains();
+ } else {
+ initServiceBindingInvocationChains();
+ }
+ }
+ return bindingInvocationChain;
+ }
+
+ public InvocationChain getInvocationChain(Operation operation) {
+ for (InvocationChain chain : getInvocationChains()) {
+ Operation op = null;
+ if (isReferenceWire) {
+ op = chain.getSourceOperation();
+ } else {
+ op = chain.getTargetOperation();
+ }
+ if (interfaceContractMapper.isCompatible(operation, op, op.getInterface().isRemotable())) {
+ return chain;
+ }
+ }
+ return null;
+ }
+
+ public Object invoke(Message msg) throws InvocationTargetException {
+ return getBindingInvocationChain().getHeadInvoker().invoke(msg);
+ }
+
+ public Object invoke(Operation operation, Object[] args) throws InvocationTargetException {
+ Message msg = messageFactory.createMessage();
+ msg.setBody(args);
+ return invoker.invoke(operation, msg);
+ }
+
+ public Object invoke(Operation operation, Message msg) throws InvocationTargetException {
+ return invoker.invoke(operation, msg);
+ }
+
+ /**
+ * Navigate the component/componentType inheritence chain to find the leaf contract
+ * @param contract
+ * @return
+ */
+ private Contract getLeafContract(Contract contract) {
+ Contract prev = null;
+ Contract current = contract;
+ while (current != null) {
+ prev = current;
+ if (current instanceof ComponentReference) {
+ current = ((ComponentReference)current).getReference();
+ } else if (current instanceof CompositeReference) {
+ current = ((CompositeReference)current).getPromotedReferences().get(0);
+ } else if (current instanceof ComponentService) {
+ current = ((ComponentService)current).getService();
+ } else if (current instanceof CompositeService) {
+ current = ((CompositeService)current).getPromotedService();
+ } else {
+ break;
+ }
+ if (current == null) {
+ return prev;
+ }
+ }
+ return current;
+ }
+
+ private InterfaceContract getLeafInterfaceContract(EndpointReference epr) {
+ ComponentReference reference = epr.getReference();
+ if (reference == null) {
+ return epr.getInterfaceContract();
+ }
+ InterfaceContract interfaceContract = getLeafContract(reference).getInterfaceContract();
+ if (interfaceContract == null) {
+ interfaceContract = epr.getInterfaceContract();
+ }
+ return interfaceContract;
+ }
+
+ private InterfaceContract getLeafInterfaceContract(Endpoint ep) {
+ ComponentService service = ep.getService();
+ if (service == null) {
+ return ep.getInterfaceContract();
+ }
+ InterfaceContract interfaceContract = getLeafContract(service).getInterfaceContract();
+ if (interfaceContract == null) {
+ interfaceContract = ep.getInterfaceContract();
+ }
+ return interfaceContract;
+ }
+
+ /**
+ * Initialize the invocation chains
+ */
+ private void initInvocationChains() {
+ chains = new ArrayList<InvocationChain>();
+ InterfaceContract sourceContract = endpointReference.getInterfaceContract();
+ // TODO - EPR why is this looking at the component types. The endpoint reference should have the right interface contract by this time
+ //InterfaceContract sourceContract = getLeafInterfaceContract(endpointReference);
+
+ if (isReferenceWire) {
+ // It's the reference wire
+ resolveEndpointReference();
+
+ InterfaceContract targetContract = endpoint.getInterfaceContract();
+ // TODO - EPR why is this looking at the component types. The endpoint should have the right interface contract by this time
+ //InterfaceContract targetContract = getLeafInterfaceContract(endpoint);
+
+ RuntimeComponentReference reference = (RuntimeComponentReference)endpointReference.getReference();
+ Binding refBinding = endpointReference.getBinding();
+ for (Operation operation : sourceContract.getInterface().getOperations()) {
+ Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation);
+ if (targetOperation == null) {
+ throw new ServiceRuntimeException("No matching operation for " + operation.getName()
+ + " is found in reference "
+ + endpointReference.getComponent().getURI()
+ + "#"
+ + reference.getName());
+ }
+ InvocationChain chain = new InvocationChainImpl(operation, targetOperation, true);
+ if (operation.isNonBlocking()) {
+ addNonBlockingInterceptor(reference, refBinding, chain);
+ }
+ addReferenceBindingInterceptor(reference, refBinding, chain, operation);
+ chains.add(chain);
+ }
+
+ } else {
+ // It's the service wire
+ RuntimeComponentService service = (RuntimeComponentService)endpoint.getService();
+ RuntimeComponent serviceComponent = (RuntimeComponent)endpoint.getComponent();
+ Binding serviceBinding = endpoint.getBinding();
+ //InterfaceContract targetContract = endpoint.getInterfaceContract();
+ // TODO - EPR - why is this looking at the component types. The endpoint should have the right interface contract by this time
+ InterfaceContract targetContract = getLeafInterfaceContract(endpoint);
+ endpoint.setInterfaceContract(targetContract);
+ for (Operation operation : sourceContract.getInterface().getOperations()) {
+ Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation);
+ if (targetOperation == null) {
+ throw new ServiceRuntimeException("No matching operation for " + operation.getName()
+ + " is found in service "
+ + serviceComponent.getURI()
+ + "#"
+ + service.getName());
+ }
+ InvocationChain chain = new InvocationChainImpl(operation, targetOperation, false);
+ if (operation.isNonBlocking()) {
+ addNonBlockingInterceptor(service, serviceBinding, chain);
+ }
+ addServiceBindingInterceptor(service, serviceBinding, chain, operation);
+ addImplementationInterceptor(serviceComponent, service, chain, targetOperation);
+ chains.add(chain);
+ }
+
+ }
+ wireProcessor.process(this);
+ }
+
+
+ /**
+ * This code used to be in the activator but has moved here as
+ * the endpoint reference may not now be resolved until the wire
+ * is first used
+ */
+ private void resolveEndpointReference(){
+ endpointReferenceBuilder.build(endpointReference, null);
+
+ // set the endpoint based on the resolved endpoint
+ endpoint = endpointReference.getTargetEndpoint();
+
+ RuntimeComponentReference runtimeRef = (RuntimeComponentReference)endpointReference.getReference();
+
+ if (runtimeRef.getBindingProvider(endpointReference.getBinding()) == null) {
+ addReferenceBindingProvider((RuntimeComponent)endpointReference.getComponent(),
+ runtimeRef,
+ endpointReference.getBinding());
+ }
+
+ // start the binding provider
+ final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
+
+ if (bindingProvider != null) {
+ // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ bindingProvider.start();
+ return null;
+ }
+ });
+ }
+
+ InterfaceContract bindingContract = getInterfaceContract(endpointReference.getReference(), endpointReference.getBinding());
+ Endpoint endpoint = endpointReference.getTargetEndpoint();
+ endpoint.setInterfaceContract(bindingContract);
+ }
+
+ private ReferenceBindingProvider addReferenceBindingProvider(
+ RuntimeComponent component, RuntimeComponentReference reference,
+ Binding binding) {
+ BindingProviderFactory providerFactory = (BindingProviderFactory) providerFactories
+ .getProviderFactory(binding.getClass());
+ if (providerFactory != null) {
+ @SuppressWarnings("unchecked")
+ ReferenceBindingProvider bindingProvider = providerFactory
+ .createReferenceBindingProvider(
+ (RuntimeComponent) component,
+ (RuntimeComponentReference) reference, binding);
+ if (bindingProvider != null) {
+ ((RuntimeComponentReference) reference).setBindingProvider(
+ binding, bindingProvider);
+ }
+ for (PolicyProviderFactory f : providerFactories
+ .getPolicyProviderFactories()) {
+ PolicyProvider policyProvider = f
+ .createReferencePolicyProvider(component, reference,
+ binding);
+ if (policyProvider != null) {
+ reference.addPolicyProvider(binding, policyProvider);
+ }
+ }
+
+ return bindingProvider;
+ } else {
+ throw new IllegalStateException(
+ "Provider factory not found for class: "
+ + binding.getClass().getName());
+ }
+ }
+
+ private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) {
+ InterfaceContract interfaceContract = reference.getInterfaceContract();
+ if (interfaceContract == null) {
+ interfaceContract = endpoint.getInterfaceContract();
+ }
+ ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
+ if (provider != null) {
+ InterfaceContract bindingContract = provider.getBindingInterfaceContract();
+ if (bindingContract != null) {
+ interfaceContract = bindingContract;
+ }
+ }
+ return interfaceContract.makeUnidirectional(false);
+ }
+
+ private void initReferenceBindingInvocationChains() {
+ RuntimeComponentReference reference = (RuntimeComponentReference)endpointReference.getReference();
+ Binding referenceBinding = endpointReference.getBinding();
+
+ // add the binding interceptors to the reference binding wire
+ ReferenceBindingProvider provider = reference.getBindingProvider(referenceBinding);
+ if ((provider != null) && (provider instanceof ReferenceBindingProviderRRB)) {
+ ((ReferenceBindingProviderRRB)provider).configureBindingChain(this);
+ }
+
+ // add the policy interceptors to the service binding wire
+ // find out which policies are active
+ List<PolicyProvider> pps = ((RuntimeComponentReference)reference).getPolicyProviders(referenceBinding);
+ if (pps != null) {
+ for (PolicyProvider p : pps) {
+ if (p instanceof PolicyProviderRRB) {
+ Interceptor interceptor = ((PolicyProviderRRB)p).createBindingInterceptor();
+ if (interceptor != null) {
+ bindingInvocationChain.addInterceptor(p.getPhase(), interceptor);
+ }
+ }
+ }
+ }
+ }
+
+ private void initServiceBindingInvocationChains() {
+ RuntimeComponentService service = (RuntimeComponentService)endpoint.getService();
+ Binding serviceBinding = endpoint.getBinding();
+
+ // add the binding interceptors to the service binding wire
+ ServiceBindingProvider provider = service.getBindingProvider(serviceBinding);
+ if ((provider != null) && (provider instanceof ServiceBindingProviderRRB)) {
+ ((ServiceBindingProviderRRB)provider).configureBindingChain(this);
+ }
+
+ // add the policy interceptors to the service binding wire
+ List<PolicyProvider> pps = ((RuntimeComponentService)service).getPolicyProviders(serviceBinding);
+ if (pps != null) {
+ for (PolicyProvider p : pps) {
+ if (p instanceof PolicyProviderRRB) {
+ Interceptor interceptor = ((PolicyProviderRRB)p).createBindingInterceptor();
+ if (interceptor != null) {
+ bindingInvocationChain.addInterceptor(p.getPhase(), interceptor);
+ }
+ }
+ }
+ }
+
+ // TODO - add something on the end of the wire to invoke the
+ // invocation chain. Need to split out the runtime
+ // wire invoker into conversation, callback interceptors etc
+ bindingInvocationChain.addInvoker(invoker);
+
+ }
+
+ // ===============================================================
+ // TODO - EPR remove when we convert fully over to EndpointReference2
+
+ // TODO - remove. Just here during development
+/*
+ static EndpointReference epr;
+
+ public EndpointReference getSource() {
+ // TODO - EPR convert this into method that returns EndpointReference2
+
+ // convert the source info into old endpoint reference format
+ epr =
+ new EndpointReferenceImpl((RuntimeComponent)endpointReference.getComponent(), endpointReference
+ .getReference(), endpointReference.getBinding(), endpointReference.getInterfaceContract());
+
+ if (endpointReference.getCallbackEndpoint() != null) {
+ // convert the source callback endpoint into old endpoint reference format
+ EndpointReference cepr;
+ cepr =
+ new EndpointReferenceImpl((RuntimeComponent)endpointReference.getComponent(), endpointReference
+ .getCallbackEndpoint().getService(), endpointReference.getCallbackEndpoint().getBinding(),
+ endpointReference.getCallbackEndpoint().getInterfaceContract());
+ epr.setCallbackEndpoint(cepr);
+ }
+
+ // TODO - somtimes used to reset the interface contract so we
+ // copy it back in in the rebuild method below
+ return epr;
+ }
+
+ public EndpointReference getTarget() {
+ // TODO - EPR convert this into method that returns Endpoint2
+
+ Endpoint2 endpoint = this.endpoint != null ? this.endpoint : endpointReference.getTargetEndpoint();
+
+ // convert the target info into old endpoint reference format
+ EndpointReference epr =
+ new EndpointReferenceImpl((RuntimeComponent)endpoint.getComponent(), endpoint.getService(), endpoint
+ .getBinding(), endpoint.getInterfaceContract());
+ return epr;
+ }
+
+ public void setTarget(EndpointReference target) {
+ // TODO - can we use the idea of setTarget to rebuild the wire?
+
+ }
+*/
+
+ // ===================================================================
+
+ public void rebuild() {
+ // TODO - can we use the idea of setTarget to rebuild the wire?
+ // used at the moment by binding.sca when it resets the
+ // source interface contract for local wires
+ this.chains = null;
+
+ // TODO - cheating here as I fixed the RuntimeComponentService code
+ // to call this when it resets the interface contract
+ //endpointReference.setInterfaceContract(epr.getInterfaceContract());
+ }
+
+ public EndpointReference getEndpointReference() {
+ return endpointReference;
+ }
+
+ public Endpoint getEndpoint() {
+ return endpoint;
+ }
+
+ /**
+ * Add the interceptor for a reference binding
+ *
+ * @param reference
+ * @param binding
+ * @param chain
+ * @param operation
+ */
+ private void addReferenceBindingInterceptor(ComponentReference reference,
+ Binding binding,
+ InvocationChain chain,
+ Operation operation) {
+ ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
+ if (provider != null) {
+ Invoker invoker = provider.createInvoker(operation);
+ if (invoker != null) {
+ chain.addInvoker(invoker);
+ }
+ }
+ List<PolicyProvider> pps = ((RuntimeComponentReference)reference).getPolicyProviders(binding);
+ if (pps != null) {
+ for (PolicyProvider p : pps) {
+ Interceptor interceptor = p.createInterceptor(operation);
+ if (interceptor != null) {
+ chain.addInterceptor(p.getPhase(), p.createInterceptor(operation));
+ }
+ }
+ }
+ }
+
+ /**
+ * Add the interceptor for a binding
+ *
+ * @param reference
+ * @param binding
+ * @param chain
+ * @param operation
+ */
+ private void addServiceBindingInterceptor(ComponentService service,
+ Binding binding,
+ InvocationChain chain,
+ Operation operation) {
+ List<PolicyProvider> pps = ((RuntimeComponentService)service).getPolicyProviders(binding);
+ if (pps != null) {
+ for (PolicyProvider p : pps) {
+ Interceptor interceptor = p.createInterceptor(operation);
+ if (interceptor != null) {
+ chain.addInterceptor(p.getPhase(), p.createInterceptor(operation));
+ }
+ }
+ }
+ }
+
+ /**
+ * Add a non-blocking interceptor if the reference binding needs it
+ *
+ * @param reference
+ * @param binding
+ * @param chain
+ */
+ private void addNonBlockingInterceptor(ComponentReference reference, Binding binding, InvocationChain chain) {
+ ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
+ if (provider != null) {
+ boolean supportsOneWayInvocation = provider.supportsOneWayInvocation();
+ if (!supportsOneWayInvocation) {
+ chain.addInterceptor(Phase.REFERENCE, new NonBlockingInterceptor(workScheduler));
+ }
+ }
+ }
+
+ /**
+ * Add a non-blocking interceptor if the service binding needs it
+ *
+ * @param service
+ * @param binding
+ * @param chain
+ */
+ private void addNonBlockingInterceptor(ComponentService service, Binding binding, InvocationChain chain) {
+ ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding);
+ if (provider != null) {
+ if (!provider.supportsOneWayInvocation()) {
+ chain.addInterceptor(Phase.SERVICE, new NonBlockingInterceptor(workScheduler));
+ }
+ }
+ }
+
+ /**
+ * Add the interceptor for a component implementation
+ *
+ * @param component
+ * @param service
+ * @param chain
+ * @param operation
+ */
+ private void addImplementationInterceptor(Component component,
+ ComponentService service,
+ InvocationChain chain,
+ Operation operation) {
+ ImplementationProvider provider = ((RuntimeComponent)component).getImplementationProvider();
+ if (provider != null) {
+ Invoker invoker = null;
+ invoker = provider.createInvoker((RuntimeComponentService)service, operation);
+ chain.addInvoker(invoker);
+ }
+ List<PolicyProvider> pps = ((RuntimeComponent)component).getPolicyProviders();
+ if (pps != null) {
+ for (PolicyProvider p : pps) {
+ Interceptor interceptor = p.createInterceptor(operation);
+ if (interceptor != null) {
+ chain.addInterceptor(p.getPhase(), p.createInterceptor(operation));
+ }
+ }
+ }
+ }
+
+ /**
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ RuntimeWireImpl copy = (RuntimeWireImpl)super.clone();
+ copy.endpointReference = (EndpointReference)endpointReference.clone();
+ copy.endpoint = copy.endpointReference.getTargetEndpoint();
+ copy.invoker = new RuntimeWireInvoker(copy.messageFactory, copy.conversationManager, copy);
+ copy.cachedWire = null; // TUSCANY-2630
+ return copy;
+ }
+
+ /**
+ * @return the conversationManager
+ */
+ public ConversationManager getConversationManager() {
+ return conversationManager;
+ }
+
+ public synchronized RuntimeWire lookupCache(Endpoint callback) {
+ if (lastCallback != null &&
+ callback.getURI().equals(lastCallback.getURI()) &&
+ !wireReserved) {
+ wireReserved = true;
+ return cachedWire;
+ } else {
+ return null;
+ }
+ }
+
+ public synchronized void addToCache(Endpoint callback, RuntimeWire clonedWire) {
+ ((RuntimeWireImpl)clonedWire).setClonedFrom(this);
+ lastCallback = callback;
+ cachedWire = clonedWire;
+ wireReserved = true;
+ }
+
+ public synchronized void releaseClonedWire(RuntimeWire wire) {
+ if (cachedWire == wire) {
+ wireReserved = false;
+ }
+ }
+
+ public synchronized void releaseWire() {
+ clonedFrom.releaseClonedWire(this);
+ }
+
+ private void setClonedFrom(RuntimeWireImpl wire) {
+ clonedFrom = wire;
+ }
+}