summaryrefslogtreecommitdiffstats
path: root/java/sca/modules
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-02 00:38:31 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-02 00:38:31 +0000
commitefa0cb0a3d5564bf3880ad2aa20f1c418d63aa7b (patch)
tree514b04eb9d94a53d58902a832053215d52a0c917 /java/sca/modules
parent9d8f01864f34586fdaf5bf96bad30e2fe06226c1 (diff)
Make CompositeActivator a stateless utility by using CompositeContext to hold the context from the Node including the endpointRegistry
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@820854 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java2
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/CompositeContext.java119
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java32
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java21
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java64
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java5
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java488
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java39
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CompositeContextImpl.java340
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java443
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java1
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java20
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java10
-rw-r--r--java/sca/modules/node-impl/META-INF/MANIFEST.MF4
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/CompositeContextImpl.java59
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java41
16 files changed, 570 insertions, 1118 deletions
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java
index 134f49e7b0..d956689af3 100644
--- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java
@@ -33,5 +33,5 @@ public interface ComponentContextFactory {
* @param component The runtime component
* @return An instance of ComponentContext for the component
*/
- ComponentContext createComponentContext(RuntimeComponent component);
+ ComponentContext createComponentContext(CompositeContext compositeContext, RuntimeComponent component);
}
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/CompositeContext.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/CompositeContext.java
index 98a20d27d5..ee5482f07f 100644
--- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/CompositeContext.java
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/CompositeContext.java
@@ -19,27 +19,17 @@
package org.apache.tuscany.sca.context;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
-import javax.xml.stream.XMLStreamReader;
-
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.Endpoint;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
import org.apache.tuscany.sca.invocation.Message;
-import org.apache.tuscany.sca.runtime.CompositeActivator;
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.oasisopen.sca.ServiceRuntimeException;
/**
@@ -47,98 +37,6 @@ import org.oasisopen.sca.ServiceRuntimeException;
*/
public abstract class CompositeContext {
/**
- * Create a self-reference for a component service
- * @param component
- * @param service
- * @throws CloneNotSupportedException
- * @throws InvalidInterfaceException
- */
- public abstract ComponentReference createSelfReference(Component component,
- ComponentService service,
- Class<?> businessInterface)
- throws CloneNotSupportedException, InvalidInterfaceException;
-
- /**
- * Bind a component reference to a component service
- * @param <B>
- * @param businessInterface
- * @param reference
- * @param service
- * @return
- * @throws CloneNotSupportedException
- * @throws InvalidInterfaceException
- */
- public abstract RuntimeComponentReference bindComponentReference(Class<?> businessInterface,
- RuntimeComponentReference reference,
- RuntimeComponent component,
- RuntimeComponentService service)
- throws CloneNotSupportedException, InvalidInterfaceException;
-
- /**
- * @param component
- * @param reference
- * @param writer
- * @throws IOException
- */
- public abstract void write(Component component, ComponentReference reference, Writer writer) throws IOException;
-
- /**
- * @param component
- * @param reference
- * @param service
- * @param writer
- * @throws IOException
- */
- public abstract void write(Component component,
- ComponentReference reference,
- ComponentService service,
- Writer writer) throws IOException;
-
- /**
- * @param component
- * @param reference
- * @return
- * @throws IOException
- */
- public abstract String toXML(Component component, ComponentReference reference) throws IOException;
-
- /**
- * @param component
- * @param service
- * @return
- * @throws IOException
- */
- public abstract String toXML(Component component, ComponentService service) throws IOException;
-
- /**
- * @param reader
- * @return
- * @throws IOException
- */
- public abstract RuntimeComponent read(Reader reader) throws IOException;
-
- /**
- * @param streamReader
- * @return
- * @throws IOException
- */
- public abstract RuntimeComponent read(XMLStreamReader streamReader) throws IOException;
-
- /**
- * @param xml
- * @return
- * @throws IOException
- */
- public abstract Component fromXML(String xml) throws IOException;
-
- /**
- * @param streamReader
- * @return
- * @throws IOException
- */
- public abstract Component fromXML(XMLStreamReader streamReader) throws IOException;
-
- /**
* @return
*/
public static RuntimeComponent getCurrentComponent() {
@@ -157,22 +55,11 @@ public abstract class CompositeContext {
/**
* @return
*/
- public static CompositeActivator getCurrentCompositeActivator() {
+ public static CompositeContext getCurrentCompositeContext() {
RuntimeComponent component = getCurrentComponent();
if (component != null) {
RuntimeComponentContext context = component.getComponentContext();
- return context.getCompositeActivator();
- }
- return null;
- }
-
- /**
- * @return
- */
- public static CompositeContext getCurrentCompositeContext() {
- CompositeActivator activator = getCurrentCompositeActivator();
- if (activator != null) {
- return activator.getCompositeContext();
+ return context.getCompositeContext();
}
return null;
}
@@ -204,6 +91,8 @@ public abstract class CompositeContext {
return targetService;
}
+ public abstract void configureComponentContext(RuntimeComponent runtimeComponent);
+
public abstract ExtensionPointRegistry getExtensionPointRegistry();
/**
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java
index a80a14f7f2..3631684a54 100644
--- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java
@@ -80,48 +80,24 @@ public interface CompositeActivator {
* Start a component
* @param component
*/
- void start(Component component) throws ActivationException;
+ void start(CompositeContext compositeContext, Component component) throws ActivationException;
/**
* Stop a component
* @param component
*/
- void stop(Component component) throws ActivationException;
+ void stop(CompositeContext compositeContext, Component component) throws ActivationException;
/**
* Start components in a composite
* @param composite
*/
- void start(Composite composite) throws ActivationException;
+ void start(CompositeContext compositeContext, 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);
-
- /**
- * Set the domain composite
- * @param domainComposite
- */
- void setDomainComposite(Composite domainComposite);
-
- /**
- * Get the domain composite
- * @return
- */
- Composite getDomainComposite();
+ void stop(CompositeContext compositeContext, Composite composite) throws ActivationException;
}
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
index eadfccf064..5f9ff4fa7e 100644
--- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
@@ -19,10 +19,6 @@
package org.apache.tuscany.sca.runtime;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.EndpointReference;
import org.apache.tuscany.sca.context.CompositeContext;
@@ -41,22 +37,6 @@ public interface RuntimeComponentContext extends ComponentContext {
void start(RuntimeComponentReference reference);
/**
- * Deserialize the component reference
- * @param reader
- * @return A component that contains the reference
- * @throws IOException
- */
- RuntimeComponent read(Reader reader) throws IOException;
-
- /**
- * Serialize the component reference
- * @param reference
- * @param writer
- * @throws IOException
- */
- void write(RuntimeComponentReference reference, Writer writer) throws IOException;
-
- /**
* Get the CallableReference for a given component reference
* @param <B>
* @param businessInterface The business interface
@@ -103,6 +83,5 @@ public interface RuntimeComponentContext extends ComponentContext {
<B> ServiceReference<B> createSelfReference(Class<B> businessInterface, ComponentService service);
ExtensionPointRegistry getExtensionPointRegistry();
- CompositeActivator getCompositeActivator();
CompositeContext getCompositeContext();
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
index fd0302829d..838ab8a2a0 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
@@ -36,13 +36,10 @@ 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.CompositeContext;
-import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint;
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.context.impl.CompositeContextImpl;
import org.apache.tuscany.sca.core.invocation.ExtensibleWireProcessor;
import org.apache.tuscany.sca.core.scope.ScopeContainer;
import org.apache.tuscany.sca.core.scope.ScopeRegistry;
@@ -62,7 +59,6 @@ import org.apache.tuscany.sca.runtime.ActivationException;
import org.apache.tuscany.sca.runtime.CompositeActivator;
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;
@@ -85,18 +81,9 @@ public class CompositeActivatorImpl implements CompositeActivator {
private final RuntimeWireProcessor wireProcessor;
private final ProviderFactoryExtensionPoint providerFactories;
- private final ComponentContextFactory componentContextFactory;
- private final EndpointRegistry endpointRegistry;
-
- private final CompositeContext compositeContext;
-
- private Composite domainComposite;
-
public CompositeActivatorImpl(ExtensionPointRegistry extensionPoints) {
this.extensionPoints = extensionPoints;
UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- this.endpointRegistry = utilities.getUtility(EndpointRegistry.class);
- this.compositeContext = new CompositeContextImpl(extensionPoints, endpointRegistry);
FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
this.messageFactory = factories.getFactory(MessageFactory.class);
@@ -105,8 +92,6 @@ public class CompositeActivatorImpl implements CompositeActivator {
this.workScheduler = utilities.getUtility(WorkScheduler.class);
this.wireProcessor = new ExtensibleWireProcessor(extensionPoints.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class));
this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
- ContextFactoryExtensionPoint contextFactories = extensionPoints.getExtensionPoint(ContextFactoryExtensionPoint.class);
- this.componentContextFactory = contextFactories.getFactory(ComponentContextFactory.class);
}
//=========================================================================
@@ -482,27 +467,27 @@ public class CompositeActivatorImpl implements CompositeActivator {
// Composite start/stop
- public void start(Composite composite) {
+ public void start(CompositeContext compositeContext, Composite composite) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Starting composite: " + composite.getName());
}
for (Component component : composite.getComponents()) {
- start(component);
+ start(compositeContext, component);
}
}
- public void stop(Composite composite) {
+ public void stop(CompositeContext compositeContext, Composite composite) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Stopping composite: " + composite.getName());
}
for (final Component component : composite.getComponents()) {
- stop(component);
+ stop(compositeContext, component);
}
}
// Component start/stop
- public void start(Component component) {
+ public void start(CompositeContext compositeContext, Component component) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Starting component: " + component.getURI());
}
@@ -511,7 +496,7 @@ public class CompositeActivatorImpl implements CompositeActivator {
return;
}
- configureComponentContext(runtimeComponent);
+ compositeContext.configureComponentContext(runtimeComponent);
// Reference bindings aren't started until the wire is first used
@@ -536,14 +521,14 @@ public class CompositeActivatorImpl implements CompositeActivator {
return null;
}
});
- endpointRegistry.addEndpoint(endpoint);
+ compositeContext.getEndpointRegistry().addEndpoint(endpoint);
}
}
}
Implementation implementation = component.getImplementation();
if (implementation instanceof Composite) {
- start((Composite)implementation);
+ start(compositeContext, (Composite)implementation);
} else {
for (PolicyProvider policyProvider : runtimeComponent.getPolicyProviders()) {
policyProvider.start();
@@ -564,7 +549,7 @@ public class CompositeActivatorImpl implements CompositeActivator {
runtimeComponent.setStarted(true);
}
- public void stop(Component component) {
+ public void stop(CompositeContext compositeContext, Component component) {
if (!((RuntimeComponent)component).isStarted()) {
return;
}
@@ -576,7 +561,7 @@ public class CompositeActivatorImpl implements CompositeActivator {
logger.fine("Stopping component service: " + component.getURI() + "#" + service.getName());
}
for (Endpoint endpoint : service.getEndpoints()) {
- endpointRegistry.removeEndpoint(endpoint);
+ compositeContext.getEndpointRegistry().removeEndpoint(endpoint);
final ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service).getBindingProvider(endpoint.getBinding());
if (bindingProvider != null) {
// Allow bindings to read properties. Requires PropertyPermission read in security policy.
@@ -600,7 +585,7 @@ public class CompositeActivatorImpl implements CompositeActivator {
RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
for (EndpointReference endpointReference : reference.getEndpointReferences()) {
- endpointRegistry.removeEndpointReference(endpointReference);
+ compositeContext.getEndpointRegistry().removeEndpointReference(endpointReference);
final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
if (bindingProvider != null) {
// Allow bindings to read properties. Requires PropertyPermission read in security policy.
@@ -620,7 +605,7 @@ public class CompositeActivatorImpl implements CompositeActivator {
}
Implementation implementation = component.getImplementation();
if (implementation instanceof Composite) {
- stop((Composite)implementation);
+ stop(compositeContext, (Composite)implementation);
} else {
final ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider();
if (implementationProvider != null) {
@@ -648,11 +633,6 @@ public class CompositeActivatorImpl implements CompositeActivator {
((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
@@ -717,7 +697,7 @@ public class CompositeActivatorImpl implements CompositeActivator {
// is first used (when the chains are created)
for (EndpointReference endpointReference : componentReference.getEndpointReferences()){
addReferenceWire(component, componentReference, endpointReference);
- endpointRegistry.addEndpointReference(endpointReference);
+ component.getComponentContext().getCompositeContext().getEndpointRegistry().addEndpointReference(endpointReference);
}
}
@@ -728,6 +708,8 @@ public class CompositeActivatorImpl implements CompositeActivator {
logger.fine("Stopping component reference: " + component.getURI() + "#" + reference.getName());
}
RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
+ RuntimeComponent runtimeComponent = (RuntimeComponent) component;
+ EndpointRegistry endpointRegistry = runtimeComponent.getComponentContext().getCompositeContext().getEndpointRegistry();
for ( EndpointReference endpointReference : runtimeRef.getEndpointReferences()){
endpointRegistry.removeEndpointReference(endpointReference);
ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
@@ -832,22 +814,6 @@ public class CompositeActivatorImpl implements CompositeActivator {
}
-
- // Utility functions
- // TODO - EPR - can we get rid of these?
-
- public CompositeContext getCompositeContext() {
- return compositeContext;
- }
-
- public Composite getDomainComposite() {
- return domainComposite;
- }
-
- public void setDomainComposite(Composite domainComposite) {
- this.domainComposite = domainComposite;
- }
-
/* TODO - EPR - Resolved via registry now
public Component resolve(String componentURI) {
for (Composite composite : domainComposite.getIncludes()) {
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java
index 4e43518738..2de52bebb2 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java
@@ -20,6 +20,7 @@
package org.apache.tuscany.sca.core.context;
import org.apache.tuscany.sca.context.ComponentContextFactory;
+import org.apache.tuscany.sca.context.CompositeContext;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.context.impl.ComponentContextImpl;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -35,8 +36,8 @@ public class DefaultComponentContextFactory implements ComponentContextFactory {
this.registry = registry;
}
- public ComponentContext createComponentContext(RuntimeComponent component) {
- return new ComponentContextImpl(registry, component);
+ public ComponentContext createComponentContext(CompositeContext compositeContext, RuntimeComponent component) {
+ return new ComponentContextImpl(registry, compositeContext, component);
}
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java
deleted file mode 100644
index d6a029cd55..0000000000
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java
+++ /dev/null
@@ -1,488 +0,0 @@
-/*
- * 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.context.impl;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.UUID;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.tuscany.sca.assembly.AssemblyFactory;
-import org.apache.tuscany.sca.assembly.Binding;
-import org.apache.tuscany.sca.assembly.ComponentService;
-import org.apache.tuscany.sca.assembly.CompositeService;
-import org.apache.tuscany.sca.assembly.EndpointReference;
-import org.apache.tuscany.sca.assembly.Service;
-import org.apache.tuscany.sca.assembly.builder.BindingBuilder;
-import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint;
-import org.apache.tuscany.sca.context.CompositeContext;
-import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
-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.RuntimeAssemblyFactory;
-import org.apache.tuscany.sca.core.assembly.impl.ReferenceParametersImpl;
-import org.apache.tuscany.sca.core.context.ServiceReferenceExt;
-import org.apache.tuscany.sca.core.factory.ObjectCreationException;
-import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory;
-import org.apache.tuscany.sca.core.invocation.ProxyFactory;
-import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
-import org.apache.tuscany.sca.interfacedef.Interface;
-import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
-import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
-import org.apache.tuscany.sca.runtime.CompositeActivator;
-import org.apache.tuscany.sca.runtime.ReferenceParameters;
-import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
-import org.apache.tuscany.sca.runtime.RuntimeWire;
-import org.oasisopen.sca.ServiceRuntimeException;
-
-/**
- * The old base class for implementations of service and callback references. We have maintained
- * this in Tuscany 2.x for the time being even though SCA 1.1 only defines service references and
- * not callable reference
- *
- * @version $Rev$ $Date$
- * @param <B> the type of the business interface
- */
-public class CallableReferenceImpl<B> implements ServiceReferenceExt<B> {
- static final long serialVersionUID = -521548304761848325L;
-
- protected transient ProxyFactory proxyFactory;
- protected transient Class<B> businessInterface;
- protected transient Object proxy;
-
- protected Object callbackID; // The callbackID should be serializable
-
- protected transient RuntimeComponent component;
- protected transient RuntimeComponentReference reference;
- protected transient EndpointReference endpointReference;
-
- protected String scdl;
-
- private transient RuntimeComponentReference clonedRef;
- private transient ReferenceParameters refParams;
- private transient XMLStreamReader xmlReader;
-
- protected transient CompositeActivator compositeActivator;
- private ExtensionPointRegistry registry;
- private FactoryExtensionPoint modelFactories;
- protected RuntimeAssemblyFactory assemblyFactory;
- private StAXArtifactProcessorExtensionPoint staxProcessors;
- private StAXArtifactProcessor<EndpointReference> staxProcessor;
- private XMLInputFactory xmlInputFactory;
- private XMLOutputFactory xmlOutputFactory;
- private BuilderExtensionPoint builders;
-
- /*
- * Public constructor for Externalizable serialization/deserialization
- */
- public CallableReferenceImpl() {
- super();
- }
-
- /*
- * Public constructor for use by XMLStreamReader2CallableReference
- */
- // TODO - EPR - Is this required
- public CallableReferenceImpl(XMLStreamReader xmlReader) throws Exception {
- this.xmlReader = xmlReader;
- resolve();
- }
-
- protected CallableReferenceImpl(Class<B> businessInterface,
- RuntimeComponent component,
- RuntimeComponentReference reference,
- EndpointReference endpointReference,
- ProxyFactory proxyFactory,
- CompositeActivator compositeActivator) {
- this.proxyFactory = proxyFactory;
- this.businessInterface = businessInterface;
- this.component = component;
- this.reference = reference;
- this.endpointReference = endpointReference;
- this.compositeActivator = compositeActivator;
-
- getExtensions();
-
- // FIXME: The SCA Specification is not clear how we should handle multiplicity
- // for CallableReference
- if (this.endpointReference == null) {
-
- // TODO - EPR - If no endpoint reference specified assume the first one
- // This will happen when a self reference is created in which case the
- // the reference should only have one endpointReference so use that
- if (this.reference.getEndpointReferences().size() == 0){
- throw new ServiceRuntimeException("The reference " + reference.getName() + " in component " +
- component.getName() + " has no endpoint references");
- }
-
- if (this.reference.getEndpointReferences().size() > 1){
- throw new ServiceRuntimeException("The reference " + reference.getName() + " in component " +
- component.getName() + " has more than one endpoint reference");
- }
-
- this.endpointReference = this.reference.getEndpointReferences().get(0);
- }
-
- // FIXME: Should we normalize the componentName/serviceName URI into an absolute SCA URI in the SCA binding?
- // sca:component1/component11/component112/service1?
- this.compositeActivator = compositeActivator;
- initCallbackID();
- }
-
- private void getExtensions() {
- this.registry = compositeActivator.getCompositeContext().getExtensionPointRegistry();
- this.modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
- this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class);
- this.xmlInputFactory = modelFactories.getFactory(XMLInputFactory.class);
- this.xmlOutputFactory = modelFactories.getFactory(XMLOutputFactory.class);
- this.staxProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- this.staxProcessor = staxProcessors.getProcessor(EndpointReference.class);
- this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class);
- }
-
- public CallableReferenceImpl(Class<B> businessInterface, RuntimeWire wire, ProxyFactory proxyFactory) {
- this.proxyFactory = proxyFactory;
- this.businessInterface = businessInterface;
- //ExtensionPointRegistry registry = ((RuntimeWireImpl)wire).getExtensionPoints();
- //this.modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
- //this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class);
- bind(wire);
- }
-
- public RuntimeWire getRuntimeWire() {
- try {
- resolve();
- if (endpointReference != null){
- return reference.getRuntimeWire(endpointReference);
- } else {
- return null;
- }
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- public EndpointReference getEndpointReference() {
- return endpointReference;
- }
-
- protected void bind(RuntimeWire wire) {
- if (wire != null) {
- this.component = (RuntimeComponent)wire.getEndpointReference().getComponent();
- this.reference = (RuntimeComponentReference)wire.getEndpointReference().getReference();
- this.endpointReference = wire.getEndpointReference();
- this.compositeActivator = component.getComponentContext().getCompositeActivator();
- initCallbackID();
- }
- }
-
- protected void initCallbackID() {
- if (reference.getInterfaceContract() != null) {
- if (reference.getInterfaceContract().getCallbackInterface() != null) {
- this.callbackID = createCallbackID();
- }
- }
- }
-
- public B getProxy() throws ObjectCreationException {
- try {
- if (proxy == null) {
- proxy = createProxy();
- }
- return businessInterface.cast(proxy);
- } catch (Exception e) {
- throw new ObjectCreationException(e);
- }
- }
-
- public void setProxy(Object proxy) {
- this.proxy = proxy;
- }
-
- protected Object createProxy() throws Exception {
- return proxyFactory.createProxy(this);
- }
-
- public B getService() {
- try {
- resolve();
- return getProxy();
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- public Class<B> getBusinessInterface() {
- try {
- resolve();
- return businessInterface;
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- public boolean isConversational() {
- try {
- resolve();
- return reference == null ? false : reference.getInterfaceContract().getInterface().isConversational();
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- public Object getCallbackID() {
- try {
- resolve();
- return callbackID;
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- /**
- * Follow a service promotion chain down to the inner most (non composite)
- * component service.
- *
- * @param topCompositeService
- * @return
- */
- private ComponentService getPromotedComponentService(CompositeService compositeService) {
- ComponentService componentService = compositeService.getPromotedService();
- if (componentService != null) {
- Service service = componentService.getService();
- if (componentService.getName() != null && service instanceof CompositeService) {
-
- // Continue to follow the service promotion chain
- return getPromotedComponentService((CompositeService)service);
-
- } else {
-
- // Found a non-composite service
- return componentService;
- }
- } else {
-
- // No promoted service
- return null;
- }
- }
-
- // ============ WRITE AND READ THE REFERENCE TO EXTERNAL XML ========================
-
- /**
- * write the reference to a stream
- *
- * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
- */
- public void writeExternal(ObjectOutput out) throws IOException {
- try {
- String xml = null;
- if (scdl == null){
- xml = toXMLString();
- } else {
- xml = scdl;
- }
-
- if (xml == null) {
- out.writeBoolean(false);
- } else {
- out.writeBoolean(true);
- out.writeUTF(xml);
- }
- } catch (Exception e) {
- // e.printStackTrace();
- throw new IOException(e.toString());
- }
- }
-
- /**
- * write the endpoint reference into an xml string
- */
- public String toXMLString() throws IOException, XMLStreamException, ContributionWriteException{
- StringWriter writer = new StringWriter();
- XMLStreamWriter streamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
- staxProcessor.write(endpointReference, streamWriter);
- return writer.toString();
- }
-
- /**
- * Read the reference from a stream
- *
- * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
- */
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- final boolean hasSCDL = in.readBoolean();
- if (hasSCDL) {
- this.scdl = in.readUTF();
- } else {
- this.scdl = null;
- }
- }
-
- /**
- * Read xml string into the endpoint reference
- */
- public void fromXMLString() throws IOException, XMLStreamException, ContributionReadException {
-
- XMLStreamReader streamReader = xmlReader;
-
- if (scdl != null ){
- Reader reader = new StringReader(scdl);
-
- if (xmlInputFactory == null){
- // this is a reference being read from a external stream
- // so set up enough of the reference in order to resolved the
- // xml being read
- CompositeContext componentContextHelper = CompositeContext.getCurrentCompositeContext();
- this.compositeActivator = CompositeContext.getCurrentCompositeActivator();
- getExtensions();
- }
-
- streamReader = xmlInputFactory.createXMLStreamReader(reader);
- }
-
- endpointReference = staxProcessor.read(streamReader);
-
- // ok to GC
- xmlReader = null;
- scdl = null;
- }
-
- /**
- * @throws IOException
- */
- private synchronized void resolve() throws Exception {
- if ((scdl != null || xmlReader != null) && component == null && reference == null) {
- fromXMLString();
-
- this.component = (RuntimeComponent)endpointReference.getComponent();
- compositeActivator.configureComponentContext(this.component);
-
- this.reference = (RuntimeComponentReference)endpointReference.getReference();
- this.reference.setComponent(this.component);
- clonedRef = reference;
-
- ReferenceParameters parameters = null;
- for (Object ext : reference.getExtensions()) {
- if (ext instanceof ReferenceParameters) {
- parameters = (ReferenceParameters)ext;
- break;
- }
- }
-
- if (parameters != null) {
- refParams = parameters;
- this.callbackID = parameters.getCallbackID();
- }
-
- Interface i = reference.getInterfaceContract().getInterface();
- if (i instanceof JavaInterface) {
- JavaInterface javaInterface = (JavaInterface)i;
- if (javaInterface.isUnresolved()) {
- // Allow privileged access to get ClassLoader. Requires RuntimePermission in
- // security policy.
- ClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return Thread.currentThread().getContextClassLoader();
- }
- });
-
- javaInterface.setJavaClass(classLoader.loadClass(javaInterface.getName()));
- JavaInterfaceFactory javaInterfaceFactory = getJavaInterfaceFactory(compositeActivator);
-
- javaInterfaceFactory.createJavaInterface(javaInterface, javaInterface.getJavaClass());
- //FIXME: If the interface needs XSDs to be loaded (e.g., for static SDO),
- // this needs to be done here. We usually search for XSDs in the current
- // contribution at resolve time. Is it possible to locate the current
- // contribution at runtime?
- }
- this.businessInterface = (Class<B>)javaInterface.getJavaClass();
- }
-
- Binding binding = endpointReference.getBinding();
- if (binding != null) {
- BindingBuilder bindingBuilder = builders.getBindingBuilder(binding.getClass());
- if (bindingBuilder != null) {
- bindingBuilder.build(component, reference, endpointReference.getBinding(), null);
- }
- }
-
- this.proxyFactory = getProxyFactory(this.compositeActivator);
- } else if (compositeActivator == null) {
- this.compositeActivator = CompositeContext.getCurrentCompositeActivator();
- if (this.compositeActivator != null) {
- this.proxyFactory = getProxyFactory(this.compositeActivator);
- }
- }
- }
-
- private JavaInterfaceFactory getJavaInterfaceFactory(CompositeActivator activator) {
- ExtensionPointRegistry extensionPointRegistry = activator.getCompositeContext().getExtensionPointRegistry();
- FactoryExtensionPoint factories = extensionPointRegistry.getExtensionPoint(FactoryExtensionPoint.class);
- JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
- return javaInterfaceFactory;
- }
-
- private ProxyFactory getProxyFactory(CompositeActivator activator) {
- ExtensionPointRegistry extensionPointRegistry = activator.getCompositeContext().getExtensionPointRegistry();
- ProxyFactoryExtensionPoint proxyFactories = extensionPointRegistry.getExtensionPoint(ProxyFactoryExtensionPoint.class);
- return new ExtensibleProxyFactory(proxyFactories);
- }
-
- // ==================================================================================
-
- /**
- * Create a callback id
- *
- * @return the callback id
- */
- private String createCallbackID() {
- return UUID.randomUUID().toString();
- }
-
- public void attachCallbackID(Object callbackID) {
- this.callbackID = callbackID;
- }
-
- protected ReferenceParameters getReferenceParameters() {
- ReferenceParameters parameters = new ReferenceParametersImpl();
- parameters.setCallbackID(callbackID);
- return parameters;
- }
-
- public XMLStreamReader getXMLReader() {
- return xmlReader;
- }
-
-}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java
index fa8c1a4dfa..13b0299554 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java
@@ -18,9 +18,6 @@
*/
package org.apache.tuscany.sca.core.context.impl;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
@@ -73,6 +70,7 @@ import org.oasisopen.sca.ServiceRuntimeException;
public class ComponentContextImpl implements RuntimeComponentContext {
private final RuntimeComponent component;
+ private final CompositeContext compositeContext;
private final CompositeActivator compositeActivator;
private final RequestContextFactory requestContextFactory;
private final ProxyFactory proxyFactory;
@@ -82,14 +80,15 @@ public class ComponentContextImpl implements RuntimeComponentContext {
private final EndpointReferenceBuilder endpointReferenceBuilder;
private final Monitor monitor;
- public ComponentContextImpl(ExtensionPointRegistry registry, RuntimeComponent component) {
+ public ComponentContextImpl(ExtensionPointRegistry registry, CompositeContext compositeContext, RuntimeComponent component) {
this.component = component;
FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
- // FIXME: We need to have node-specific compositeActivator
UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ this.compositeContext = compositeContext;
+
this.compositeActivator = utilities.getUtility(CompositeActivator.class);
this.requestContextFactory =
@@ -238,7 +237,7 @@ public class ComponentContextImpl implements RuntimeComponentContext {
}
ref.setComponent(component);
return new ServiceReferenceImpl<B>(businessInterface, component, ref, endpointReference, proxyFactory,
- compositeActivator);
+ component.getComponentContext().getCompositeContext());
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
@@ -283,7 +282,7 @@ public class ComponentContextImpl implements RuntimeComponentContext {
ref.getBindings().add(binding);
}
}
- return new ServiceReferenceImpl<B>(businessInterface, component, ref, proxyFactory, compositeActivator);
+ return new ServiceReferenceImpl<B>(businessInterface, component, ref, null, proxyFactory, compositeContext);
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
@@ -301,7 +300,7 @@ public class ComponentContextImpl implements RuntimeComponentContext {
(RuntimeComponentReference)createSelfReference(component, service, businessInterface);
ref.setComponent(component);
return new ServiceReferenceImpl<B>(businessInterface, component, ref, null, proxyFactory,
- compositeActivator);
+ compositeContext);
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
@@ -410,34 +409,12 @@ public class ComponentContextImpl implements RuntimeComponentContext {
}
/**
- * @return the compositeActivator
- */
- public CompositeActivator getCompositeActivator() {
- return compositeActivator;
- }
-
- /**
* @see org.apache.tuscany.sca.runtime.RuntimeComponentContext#start(org.apache.tuscany.sca.runtime.RuntimeComponentReference)
*/
public void start(RuntimeComponentReference reference) {
compositeActivator.start(component, reference);
}
- /**
- * @see org.apache.tuscany.sca.runtime.RuntimeComponentContext#read(java.io.Reader)
- */
- public RuntimeComponent read(Reader reader) throws IOException {
- RuntimeComponent component = compositeActivator.getCompositeContext().read(reader);
- compositeActivator.configureComponentContext(component);
- return component;
- }
-
- /**
- * @see org.apache.tuscany.sca.runtime.RuntimeComponentContext#write(org.apache.tuscany.sca.runtime.RuntimeComponentReference, java.io.Writer)
- */
- public void write(RuntimeComponentReference reference, Writer writer) throws IOException {
- compositeActivator.getCompositeContext().write(component, reference, writer);
- }
/* ******************** Contribution for issue TUSCANY-2281 ******************** */
@@ -478,7 +455,7 @@ public class ComponentContextImpl implements RuntimeComponentContext {
/* ******************** Contribution for issue TUSCANY-2281 ******************** */
public CompositeContext getCompositeContext() {
- return compositeActivator.getCompositeContext();
+ return compositeContext;
}
public ExtensionPointRegistry getExtensionPointRegistry() {
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CompositeContextImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CompositeContextImpl.java
deleted file mode 100644
index b26861aa79..0000000000
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CompositeContextImpl.java
+++ /dev/null
@@ -1,340 +0,0 @@
-/*
- * 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.context.impl;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-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.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.Multiplicity;
-import org.apache.tuscany.sca.assembly.OptimizableBinding;
-import org.apache.tuscany.sca.assembly.Reference;
-import org.apache.tuscany.sca.assembly.Service;
-import org.apache.tuscany.sca.context.CompositeContext;
-import org.apache.tuscany.sca.context.ThreadMessageContext;
-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.invocation.ExtensibleProxyFactory;
-import org.apache.tuscany.sca.core.invocation.ProxyFactory;
-import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
-import org.apache.tuscany.sca.interfacedef.Interface;
-import org.apache.tuscany.sca.interfacedef.InterfaceContract;
-import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
-import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
-import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
-import org.apache.tuscany.sca.invocation.Message;
-import org.apache.tuscany.sca.runtime.CompositeActivator;
-import org.apache.tuscany.sca.runtime.EndpointRegistry;
-import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
-import org.apache.tuscany.sca.runtime.RuntimeComponentService;
-import org.oasisopen.sca.ServiceRuntimeException;
-
-/**
- * @version $Rev$ $Date$
- */
-public class CompositeContextImpl extends CompositeContext {
- private final ExtensionPointRegistry extensionPointRegistry;
- private final EndpointRegistry endpointRegistry;
- private final AssemblyFactory assemblyFactory;
- private final JavaInterfaceFactory javaInterfaceFactory;
- private final StAXArtifactProcessorExtensionPoint staxProcessors;
- private final XMLInputFactory xmlInputFactory;
- private final XMLOutputFactory xmlOutputFactory;
-
- public CompositeContextImpl(ExtensionPointRegistry registry, EndpointRegistry endpointRegistry) {
- this.extensionPointRegistry = registry;
- this.endpointRegistry = endpointRegistry;
- FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
- this.xmlInputFactory = factories.getFactory(XMLInputFactory.class);
- this.xmlOutputFactory = factories.getFactory(XMLOutputFactory.class);
- this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
- this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
- this.staxProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- }
-
- private ProxyFactory getProxyFactory() {
- ProxyFactoryExtensionPoint proxyFactories = extensionPointRegistry.getExtensionPoint(ProxyFactoryExtensionPoint.class);
- return new ExtensibleProxyFactory(proxyFactories);
- }
-
- /**
- * Create a self-reference for a component service
- * @param component
- * @param service
- * @throws CloneNotSupportedException
- * @throws InvalidInterfaceException
- */
- public ComponentReference createSelfReference(Component component,
- ComponentService service,
- Class<?> businessInterface) throws CloneNotSupportedException,
- InvalidInterfaceException {
- ComponentReference componentReference = assemblyFactory.createComponentReference();
- componentReference.setName("$self$." + service.getName());
- for (Binding binding : service.getBindings()) {
- if (binding instanceof OptimizableBinding) {
- OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone();
- optimizableBinding.setTargetBinding(binding);
- optimizableBinding.setTargetComponent(component);
- optimizableBinding.setTargetComponentService(service);
- componentReference.getBindings().add(optimizableBinding);
- } else {
- componentReference.getBindings().add(binding);
- }
- }
-
- componentReference.setCallback(service.getCallback());
- componentReference.getTargets().add(service);
- componentReference.getPolicySets().addAll(service.getPolicySets());
- componentReference.getRequiredIntents().addAll(service.getRequiredIntents());
-
- InterfaceContract interfaceContract = service.getInterfaceContract();
- Service componentTypeService = service.getService();
- if (componentTypeService != null && componentTypeService.getInterfaceContract() != null) {
- interfaceContract = componentTypeService.getInterfaceContract();
- }
- interfaceContract = getInterfaceContract(interfaceContract, businessInterface);
- componentReference.setInterfaceContract(interfaceContract);
- componentReference.setMultiplicity(Multiplicity.ONE_ONE);
- // component.getReferences().add(componentReference);
- return componentReference;
- }
-
- /**
- * @param interfaceContract
- * @param businessInterface
- * @return
- * @throws CloneNotSupportedException
- * @throws InvalidInterfaceException
- */
- private InterfaceContract getInterfaceContract(InterfaceContract interfaceContract, Class<?> businessInterface)
- throws CloneNotSupportedException, InvalidInterfaceException {
- Interface interfaze = interfaceContract.getInterface();
- boolean compatible = false;
- if (interfaze instanceof JavaInterface) {
- Class<?> cls = ((JavaInterface)interfaze).getJavaClass();
- if (businessInterface.isAssignableFrom(cls)) {
- compatible = true;
- }
- }
- if (!compatible) {
- // The interface is not assignable from the interface contract
- interfaceContract = (InterfaceContract)interfaceContract.clone();
- interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface));
- }
-
- return interfaceContract;
- }
-
- /**
- * Bind a component reference to a component service
- * @param <B>
- * @param businessInterface
- * @param reference
- * @param service
- * @return
- * @throws CloneNotSupportedException
- * @throws InvalidInterfaceException
- */
- public RuntimeComponentReference bindComponentReference(Class<?> businessInterface,
- RuntimeComponentReference reference,
- RuntimeComponent component,
- RuntimeComponentService service)
- throws CloneNotSupportedException, InvalidInterfaceException {
- RuntimeComponentReference ref = (RuntimeComponentReference)reference.clone();
- InterfaceContract interfaceContract = reference.getInterfaceContract();
- Reference componentTypeReference = reference.getReference();
- if (componentTypeReference != null && componentTypeReference.getInterfaceContract() != null) {
- interfaceContract = componentTypeReference.getInterfaceContract();
- }
- InterfaceContract refInterfaceContract = getInterfaceContract(interfaceContract, businessInterface);
- if (refInterfaceContract != interfaceContract) {
- ref = (RuntimeComponentReference)reference.clone();
- ref.setInterfaceContract(interfaceContract);
- }
- ref.setComponent(component);
- ref.getTargets().add(service);
- ref.getBindings().clear();
- for (Binding binding : service.getBindings()) {
- if (binding instanceof OptimizableBinding) {
- OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone();
- optimizableBinding.setTargetBinding(binding);
- optimizableBinding.setTargetComponent(component);
- optimizableBinding.setTargetComponentService(service);
- ref.getBindings().add(optimizableBinding);
- } else {
- ref.getBindings().add(binding);
- }
- }
- return ref;
- }
-
- public void write(Component component, ComponentReference reference, Writer writer) throws IOException {
- write(component, reference, null, writer);
- }
-
- public void write(Component component, ComponentReference reference, ComponentService service, Writer writer) throws IOException {
- try {
- StAXArtifactProcessor<Composite> processor = staxProcessors.getProcessor(Composite.class);
- Composite composite = assemblyFactory.createComposite();
- composite.setName(new QName("http://tuscany.apache.org/xmlns/sca/1.1", "default"));
- Component comp = assemblyFactory.createComponent();
- comp.setName("default");
- comp.setURI(component.getURI());
- composite.getComponents().add(comp);
- if (reference != null) {
- comp.getReferences().add(reference);
- }
- if (service != null) {
- comp.getServices().add(service);
- }
-
- XMLStreamWriter streamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
- processor.write(composite, streamWriter);
- } catch (Exception e) {
- throw new IOException(e.getMessage());
- }
- }
-
- public String toXML(Component component, ComponentReference reference) throws IOException {
- StringWriter writer = new StringWriter();
- write(component, reference, writer);
- return writer.toString();
- }
-
- public String toXML(Component component, ComponentService service) throws IOException {
- StringWriter writer = new StringWriter();
- write(component, null, service, writer);
- return writer.toString();
- }
-
- public RuntimeComponent read(Reader reader) throws IOException {
- try {
- XMLStreamReader streamReader = xmlInputFactory.createXMLStreamReader(reader);
- return read(streamReader);
- } catch (Exception e) {
- throw new IOException(e.getMessage());
- }
- }
-
- public RuntimeComponent read(XMLStreamReader streamReader) throws IOException {
- try {
- StAXArtifactProcessor<Composite> processor = staxProcessors.getProcessor(Composite.class);
- Composite composite = processor.read(streamReader);
- RuntimeComponent component = (RuntimeComponent)composite.getComponents().get(0);
- return component;
- } catch (Exception e) {
- throw new IOException(e.getMessage());
- }
- }
-
- public Component fromXML(String xml) throws IOException {
- return read(new StringReader(xml));
- }
-
- public Component fromXML(XMLStreamReader streamReader) throws IOException {
- return read(streamReader);
- }
-
- public static RuntimeComponent getCurrentComponent() {
- Message message = ThreadMessageContext.getMessageContext();
- if (message != null) {
- Endpoint to = message.getTo();
- if (to == null) {
- return null;
- }
- RuntimeComponent component = (RuntimeComponent) message.getTo().getComponent();
- return component;
- }
- return null;
- }
-
- public static CompositeActivator getCurrentCompositeActivator() {
- RuntimeComponent component = getCurrentComponent();
- if (component != null) {
- ComponentContextImpl context = (ComponentContextImpl)component.getComponentContext();
- return context.getCompositeActivator();
- }
- return null;
- }
-
- public static CompositeContext getCurrentCompositeContext() {
- CompositeActivator activator = getCurrentCompositeActivator();
- if (activator != null) {
- return activator.getCompositeContext();
- }
- return null;
- }
-
- /**
- * @param component
- */
- public static ComponentService getSingleService(Component component) {
- ComponentService targetService;
- List<ComponentService> services = component.getServices();
- List<ComponentService> regularServices = new ArrayList<ComponentService>();
- for (ComponentService service : services) {
- if (service.isForCallback()) {
- continue;
- }
- String name = service.getName();
- if (!name.startsWith("$") || name.startsWith("$dynamic$")) {
- regularServices.add(service);
- }
- }
- if (regularServices.size() == 0) {
- throw new ServiceRuntimeException("No service is declared on component " + component.getURI());
- }
- if (regularServices.size() != 1) {
- throw new ServiceRuntimeException("More than one service is declared on component " + component.getURI()
- + ". Service name is required to get the service.");
- }
- targetService = regularServices.get(0);
- return targetService;
- }
-
- public ExtensionPointRegistry getExtensionPointRegistry() {
- return extensionPointRegistry;
- }
-
- public EndpointRegistry getEndpointRegistry() {
- return endpointRegistry;
- }
-
-}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java
index 20b607ce74..a1fc91e824 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java
@@ -18,14 +18,52 @@
*/
package org.apache.tuscany.sca.core.context.impl;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.UUID;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.CompositeService;
import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.builder.BindingBuilder;
+import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint;
+import org.apache.tuscany.sca.context.CompositeContext;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+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.RuntimeAssemblyFactory;
+import org.apache.tuscany.sca.core.assembly.impl.ReferenceParametersImpl;
+import org.apache.tuscany.sca.core.context.ServiceReferenceExt;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory;
import org.apache.tuscany.sca.core.invocation.ProxyFactory;
-import org.apache.tuscany.sca.runtime.CompositeActivator;
+import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.oasisopen.sca.ServiceRuntimeException;
/**
* Default implementation of a ServiceReference.
@@ -33,10 +71,32 @@ import org.apache.tuscany.sca.runtime.RuntimeWire;
* @version $Rev$ $Date$
* @param <B> the type of the business interface
*/
-public class ServiceReferenceImpl<B> extends CallableReferenceImpl<B> {
+public class ServiceReferenceImpl<B> implements ServiceReferenceExt<B> {
private static final long serialVersionUID = 6763709434194361540L;
- protected transient Object callback;
+ protected transient ProxyFactory proxyFactory;
+ protected transient Class<B> businessInterface;
+ protected transient Object proxy;
+
+ protected Object callbackID; // The callbackID should be serializable
+
+ protected transient RuntimeComponent component;
+ protected transient RuntimeComponentReference reference;
+ protected transient EndpointReference endpointReference;
+
+ protected String scdl;
+
+ private transient XMLStreamReader xmlReader;
+
+ protected transient CompositeContext compositeContext;
+ private ExtensionPointRegistry registry;
+ private FactoryExtensionPoint modelFactories;
+ protected RuntimeAssemblyFactory assemblyFactory;
+ private StAXArtifactProcessorExtensionPoint staxProcessors;
+ private StAXArtifactProcessor<EndpointReference> staxProcessor;
+ private XMLInputFactory xmlInputFactory;
+ private XMLOutputFactory xmlOutputFactory;
+ private BuilderExtensionPoint builders;
/*
* Public constructor for Externalizable serialization/deserialization
@@ -48,34 +108,371 @@ public class ServiceReferenceImpl<B> extends CallableReferenceImpl<B> {
/*
* Public constructor for use by XMLStreamReader2CallableReference
*/
- // TODO - EPR - is this required
+ // TODO - EPR - Is this required
public ServiceReferenceImpl(XMLStreamReader xmlReader) throws Exception {
- super(xmlReader);
+ this.xmlReader = xmlReader;
+ resolve();
+ }
+
+ protected ServiceReferenceImpl(Class<B> businessInterface,
+ RuntimeComponent component,
+ RuntimeComponentReference reference,
+ EndpointReference endpointReference,
+ ProxyFactory proxyFactory,
+ CompositeContext compositeContext) {
+ this.proxyFactory = proxyFactory;
+ this.businessInterface = businessInterface;
+ this.component = component;
+ this.reference = reference;
+ this.endpointReference = endpointReference;
+ this.compositeContext = compositeContext;
+
+ getExtensions();
+
+ // FIXME: The SCA Specification is not clear how we should handle multiplicity
+ // for CallableReference
+ if (this.endpointReference == null) {
+
+ // TODO - EPR - If no endpoint reference specified assume the first one
+ // This will happen when a self reference is created in which case the
+ // the reference should only have one endpointReference so use that
+ if (this.reference.getEndpointReferences().size() == 0){
+ throw new ServiceRuntimeException("The reference " + reference.getName() + " in component " +
+ component.getName() + " has no endpoint references");
+ }
+
+ if (this.reference.getEndpointReferences().size() > 1){
+ throw new ServiceRuntimeException("The reference " + reference.getName() + " in component " +
+ component.getName() + " has more than one endpoint reference");
+ }
+
+ this.endpointReference = this.reference.getEndpointReferences().get(0);
+ }
+
+ // FIXME: Should we normalize the componentName/serviceName URI into an absolute SCA URI in the SCA binding?
+ // sca:component1/component11/component112/service1?
+ initCallbackID();
+ }
+
+ private void getExtensions() {
+ this.registry = compositeContext.getExtensionPointRegistry();
+ this.modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class);
+ this.xmlInputFactory = modelFactories.getFactory(XMLInputFactory.class);
+ this.xmlOutputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+ this.staxProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ this.staxProcessor = staxProcessors.getProcessor(EndpointReference.class);
+ this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class);
+ }
+
+ public ServiceReferenceImpl(Class<B> businessInterface, RuntimeWire wire, ProxyFactory proxyFactory) {
+ this.proxyFactory = proxyFactory;
+ this.businessInterface = businessInterface;
+ //ExtensionPointRegistry registry = ((RuntimeWireImpl)wire).getExtensionPoints();
+ //this.modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ //this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class);
+ bind(wire);
+ }
+
+ public RuntimeWire getRuntimeWire() {
+ try {
+ resolve();
+ if (endpointReference != null){
+ return reference.getRuntimeWire(endpointReference);
+ } else {
+ return null;
+ }
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public EndpointReference getEndpointReference() {
+ return endpointReference;
+ }
+
+ protected void bind(RuntimeWire wire) {
+ if (wire != null) {
+ this.component = (RuntimeComponent)wire.getEndpointReference().getComponent();
+ this.reference = (RuntimeComponentReference)wire.getEndpointReference().getReference();
+ this.endpointReference = wire.getEndpointReference();
+ this.compositeContext = component.getComponentContext().getCompositeContext();
+ initCallbackID();
+ }
+ }
+
+ protected void initCallbackID() {
+ if (reference.getInterfaceContract() != null) {
+ if (reference.getInterfaceContract().getCallbackInterface() != null) {
+ this.callbackID = createCallbackID();
+ }
+ }
+ }
+
+ public B getProxy() throws ObjectCreationException {
+ try {
+ if (proxy == null) {
+ proxy = createProxy();
+ }
+ return businessInterface.cast(proxy);
+ } catch (Exception e) {
+ throw new ObjectCreationException(e);
+ }
+ }
+
+ public void setProxy(Object proxy) {
+ this.proxy = proxy;
+ }
+
+ protected Object createProxy() throws Exception {
+ return proxyFactory.createProxy(this);
+ }
+
+ public B getService() {
+ try {
+ resolve();
+ return getProxy();
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public Class<B> getBusinessInterface() {
+ try {
+ resolve();
+ return businessInterface;
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public boolean isConversational() {
+ try {
+ resolve();
+ return reference == null ? false : reference.getInterfaceContract().getInterface().isConversational();
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public Object getCallbackID() {
+ try {
+ resolve();
+ return callbackID;
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
}
/**
- * @param businessInterface
- * @param wire
- * @param proxyFactory
+ * Follow a service promotion chain down to the inner most (non composite)
+ * component service.
+ *
+ * @param topCompositeService
+ * @return
*/
- public ServiceReferenceImpl(Class<B> businessInterface, RuntimeWire wire, ProxyFactory proxyFactory) {
- super(businessInterface, wire, proxyFactory);
+ private ComponentService getPromotedComponentService(CompositeService compositeService) {
+ ComponentService componentService = compositeService.getPromotedService();
+ if (componentService != null) {
+ Service service = componentService.getService();
+ if (componentService.getName() != null && service instanceof CompositeService) {
+
+ // Continue to follow the service promotion chain
+ return getPromotedComponentService((CompositeService)service);
+
+ } else {
+
+ // Found a non-composite service
+ return componentService;
+ }
+ } else {
+
+ // No promoted service
+ return null;
+ }
+ }
+
+ // ============ WRITE AND READ THE REFERENCE TO EXTERNAL XML ========================
+
+ /**
+ * write the reference to a stream
+ *
+ * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
+ */
+ public void writeExternal(ObjectOutput out) throws IOException {
+ try {
+ String xml = null;
+ if (scdl == null){
+ xml = toXMLString();
+ } else {
+ xml = scdl;
+ }
+
+ if (xml == null) {
+ out.writeBoolean(false);
+ } else {
+ out.writeBoolean(true);
+ out.writeUTF(xml);
+ }
+ } catch (Exception e) {
+ // e.printStackTrace();
+ throw new IOException(e.toString());
+ }
+ }
+
+ /**
+ * write the endpoint reference into an xml string
+ */
+ public String toXMLString() throws IOException, XMLStreamException, ContributionWriteException{
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter streamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
+ staxProcessor.write(endpointReference, streamWriter);
+ return writer.toString();
+ }
+
+ /**
+ * Read the reference from a stream
+ *
+ * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
+ */
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ final boolean hasSCDL = in.readBoolean();
+ if (hasSCDL) {
+ this.scdl = in.readUTF();
+ } else {
+ this.scdl = null;
+ }
+ }
+
+ /**
+ * Read xml string into the endpoint reference
+ */
+ public void fromXMLString() throws IOException, XMLStreamException, ContributionReadException {
+
+ XMLStreamReader streamReader = xmlReader;
+
+ if (scdl != null ){
+ Reader reader = new StringReader(scdl);
+
+ if (xmlInputFactory == null){
+ // this is a reference being read from a external stream
+ // so set up enough of the reference in order to resolved the
+ // xml being read
+ this.compositeContext = CompositeContext.getCurrentCompositeContext();
+ getExtensions();
+ }
+
+ streamReader = xmlInputFactory.createXMLStreamReader(reader);
+ }
+
+ endpointReference = staxProcessor.read(streamReader);
+
+ // ok to GC
+ xmlReader = null;
+ scdl = null;
+ }
+
+ /**
+ * @throws IOException
+ */
+ private synchronized void resolve() throws Exception {
+ if ((scdl != null || xmlReader != null) && component == null && reference == null) {
+ fromXMLString();
+
+ this.component = (RuntimeComponent)endpointReference.getComponent();
+ compositeContext.configureComponentContext(this.component);
+
+ this.reference = (RuntimeComponentReference)endpointReference.getReference();
+ this.reference.setComponent(this.component);
+
+ ReferenceParameters parameters = null;
+ for (Object ext : reference.getExtensions()) {
+ if (ext instanceof ReferenceParameters) {
+ parameters = (ReferenceParameters)ext;
+ break;
+ }
+ }
+
+ if (parameters != null) {
+ this.callbackID = parameters.getCallbackID();
+ }
+
+ Interface i = reference.getInterfaceContract().getInterface();
+ if (i instanceof JavaInterface) {
+ JavaInterface javaInterface = (JavaInterface)i;
+ if (javaInterface.isUnresolved()) {
+ // Allow privileged access to get ClassLoader. Requires RuntimePermission in
+ // security policy.
+ ClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+
+ javaInterface.setJavaClass(classLoader.loadClass(javaInterface.getName()));
+ JavaInterfaceFactory javaInterfaceFactory = getJavaInterfaceFactory(compositeContext);
+
+ javaInterfaceFactory.createJavaInterface(javaInterface, javaInterface.getJavaClass());
+ //FIXME: If the interface needs XSDs to be loaded (e.g., for static SDO),
+ // this needs to be done here. We usually search for XSDs in the current
+ // contribution at resolve time. Is it possible to locate the current
+ // contribution at runtime?
+ }
+ this.businessInterface = (Class<B>)javaInterface.getJavaClass();
+ }
+
+ Binding binding = endpointReference.getBinding();
+ if (binding != null) {
+ BindingBuilder bindingBuilder = builders.getBindingBuilder(binding.getClass());
+ if (bindingBuilder != null) {
+ bindingBuilder.build(component, reference, endpointReference.getBinding(), null);
+ }
+ }
+
+ this.proxyFactory = getProxyFactory(this.compositeContext);
+ } else if (compositeContext == null) {
+ this.compositeContext = CompositeContext.getCurrentCompositeContext();
+ if (this.compositeContext != null) {
+ this.proxyFactory = getProxyFactory(this.compositeContext);
+ }
+ }
+ }
+
+ private JavaInterfaceFactory getJavaInterfaceFactory(CompositeContext compositeContext) {
+ ExtensionPointRegistry extensionPointRegistry = compositeContext.getExtensionPointRegistry();
+ FactoryExtensionPoint factories = extensionPointRegistry.getExtensionPoint(FactoryExtensionPoint.class);
+ JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
+ return javaInterfaceFactory;
+ }
+
+ private ProxyFactory getProxyFactory(CompositeContext compositeContext) {
+ ExtensionPointRegistry extensionPointRegistry = compositeContext.getExtensionPointRegistry();
+ ProxyFactoryExtensionPoint proxyFactories = extensionPointRegistry.getExtensionPoint(ProxyFactoryExtensionPoint.class);
+ return new ExtensibleProxyFactory(proxyFactories);
+ }
+
+ // ==================================================================================
+
+ /**
+ * Create a callback id
+ *
+ * @return the callback id
+ */
+ private String createCallbackID() {
+ return UUID.randomUUID().toString();
+ }
+
+ public void attachCallbackID(Object callbackID) {
+ this.callbackID = callbackID;
}
- public ServiceReferenceImpl(Class<B> businessInterface,
- RuntimeComponent component,
- RuntimeComponentReference reference,
- ProxyFactory proxyFactory,
- CompositeActivator compositeActivator) {
- super(businessInterface, component, reference, null, proxyFactory, compositeActivator);
+ protected ReferenceParameters getReferenceParameters() {
+ ReferenceParameters parameters = new ReferenceParametersImpl();
+ parameters.setCallbackID(callbackID);
+ return parameters;
}
- public ServiceReferenceImpl(Class<B> businessInterface,
- RuntimeComponent component,
- RuntimeComponentReference reference,
- EndpointReference endpointReference,
- ProxyFactory proxyFactory,
- CompositeActivator compositeActivator) {
- super(businessInterface, component, reference, endpointReference, proxyFactory, compositeActivator);
+ public XMLStreamReader getXMLReader() {
+ return xmlReader;
}
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
index 0bf7b3554e..11edc283a4 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
@@ -28,7 +28,6 @@ import net.sf.cglib.proxy.Factory;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
-import org.apache.tuscany.sca.core.context.impl.CallableReferenceImpl;
import org.apache.tuscany.sca.core.context.impl.ServiceReferenceImpl;
import org.apache.tuscany.sca.core.invocation.impl.JDKCallbackInvocationHandler;
import org.apache.tuscany.sca.core.invocation.impl.JDKInvocationHandler;
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java
index ad46b33af0..05ed360d75 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java
@@ -33,6 +33,8 @@ import javax.xml.namespace.QName;
public interface NodeConfiguration {
String DEFAULT_DOMAIN_URI = "http://tuscany.apache.org/sca/1.1/domains/default";
String DEFAULT_NODE_URI = "http://tuscany.apache.org/sca/1.1/nodes/default";
+ String DEFAULT_DOMAIN_REGISTRY_URI = "vm://localhost";
+
/**
* Get the URI of the SCA domain that manages the composite application
* @return The URI of the SCA domain
@@ -50,6 +52,24 @@ public interface NodeConfiguration {
* @param domainURI The URI of the SCA domain
*/
NodeConfiguration setDomainURI(String domainURI);
+
+ /**
+ * Return the URI of the domain registry
+ * @return
+ */
+ String getDomainRegistryURI();
+
+ /**
+ * Set the URI of the domain registry
+ * @param domainRegistryURI The URI of the domain registry. The scheme will be used
+ * by Tusany to choose the implementation of DomainRegistry interface. Examples are:
+ * <ul>
+ * <li>vm://localhost (a JVM local registry)
+ * <li>multicast://228.0.0.100:50000?timeout=50 (Tomcat Tribes multicast based registry)
+ * </ul>
+ * @return The NodeConfiguration
+ */
+ NodeConfiguration setDomainRegistryURI(String domainRegistryURI);
/**
* Get the URI of the node. It uniquely identifies a node within the SCA domain
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java
index 9a9a0d6cb5..3d5cb1a94c 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java
@@ -38,6 +38,7 @@ import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
public class NodeConfigurationImpl implements NodeConfiguration {
private String uri = DEFAULT_NODE_URI;
private String domainURI = DEFAULT_DOMAIN_URI;
+ private String domainRegistryURI = DEFAULT_DOMAIN_REGISTRY_URI;
private List<ContributionConfiguration> contributions = new ArrayList<ContributionConfiguration>();
private List<BindingConfiguration> bindings = new ArrayList<BindingConfiguration>();
private List<Object> extensions = new ArrayList<Object>();
@@ -173,4 +174,13 @@ public class NodeConfigurationImpl implements NodeConfiguration {
return extensions;
}
+ public String getDomainRegistryURI() {
+ return domainRegistryURI;
+ }
+
+ public NodeConfiguration setDomainRegistryURI(String domainRegistryURI) {
+ this.domainRegistryURI = domainRegistryURI;
+ return this;
+ }
+
}
diff --git a/java/sca/modules/node-impl/META-INF/MANIFEST.MF b/java/sca/modules/node-impl/META-INF/MANIFEST.MF
index 4ec6d5c84d..a1907800ff 100644
--- a/java/sca/modules/node-impl/META-INF/MANIFEST.MF
+++ b/java/sca/modules/node-impl/META-INF/MANIFEST.MF
@@ -17,7 +17,7 @@ Bnd-LastModified: 1225397240796
Bundle-ManifestVersion: 2
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-Description: Apache Tuscany SCA Node Implementation
-Import-Package: javax.management,
+Import-Package: javax.management;resolution:=optional,
javax.xml.namespace,
javax.xml.stream,
org.apache.tuscany.sca.assembly;version="2.0.0",
@@ -36,6 +36,8 @@ Import-Package: javax.management,
org.apache.tuscany.sca.definitions.util;version="2.0.0",
org.apache.tuscany.sca.definitions.xml;version="2.0.0",
org.apache.tuscany.sca.extensibility;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
org.apache.tuscany.sca.management;version="2.0.0",
org.apache.tuscany.sca.monitor;version="2.0.0",
org.apache.tuscany.sca.node;version="2.0.0",
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/CompositeContextImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/CompositeContextImpl.java
new file mode 100644
index 0000000000..4a3366e6fb
--- /dev/null
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/CompositeContextImpl.java
@@ -0,0 +1,59 @@
+/*
+ * 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.node.impl;
+
+import org.apache.tuscany.sca.context.ComponentContextFactory;
+import org.apache.tuscany.sca.context.CompositeContext;
+import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeContextImpl extends CompositeContext {
+ private final ExtensionPointRegistry extensionPointRegistry;
+ private final EndpointRegistry endpointRegistry;
+ private final ComponentContextFactory componentContextFactory;
+
+ public CompositeContextImpl(ExtensionPointRegistry registry, EndpointRegistry endpointRegistry) {
+ this.extensionPointRegistry = registry;
+ this.endpointRegistry = endpointRegistry;
+ ContextFactoryExtensionPoint contextFactories = registry.getExtensionPoint(ContextFactoryExtensionPoint.class);
+ this.componentContextFactory = contextFactories.getFactory(ComponentContextFactory.class);
+ }
+
+ public ExtensionPointRegistry getExtensionPointRegistry() {
+ return extensionPointRegistry;
+ }
+
+ public EndpointRegistry getEndpointRegistry() {
+ return endpointRegistry;
+ }
+
+ public void configureComponentContext(RuntimeComponent runtimeComponent) {
+ RuntimeComponentContext componentContext =
+ (RuntimeComponentContext)componentContextFactory.createComponentContext(this, runtimeComponent);
+ runtimeComponent.setComponentContext(componentContext);
+ }
+
+}
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
index 82a5b01726..aeb962faf8 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
@@ -36,6 +36,7 @@ import org.apache.tuscany.sca.assembly.CompositeService;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.common.java.io.IOHelper;
+import org.apache.tuscany.sca.context.CompositeContext;
import org.apache.tuscany.sca.context.ThreadMessageContext;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
@@ -50,6 +51,7 @@ import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
import org.apache.tuscany.sca.node.management.NodeManager;
import org.apache.tuscany.sca.runtime.ActivationException;
import org.apache.tuscany.sca.runtime.CompositeActivator;
+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.RuntimeComponentService;
@@ -64,6 +66,8 @@ public class NodeImpl implements Node, Client {
private static final Logger logger = Logger.getLogger(NodeImpl.class.getName());
private ProxyFactory proxyFactory;
private CompositeActivator compositeActivator;
+ private CompositeContext compositeContext;
+ private Composite domainComposite;
private NodeConfiguration configuration;
private NodeFactoryImpl manager;
private List<Contribution> contributions;
@@ -106,20 +110,20 @@ public class NodeImpl implements Node, Client {
manager.init();
manager.addNode(configuration, this);
this.proxyFactory = manager.proxyFactory;
- this.compositeActivator =
- manager.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(CompositeActivator.class,
- manager.getNodeKey(configuration));
+ UtilityExtensionPoint utilities = manager.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+
+ // FIXME: Get the endpoint registry by the Node configuration
+ EndpointRegistry endpointRegistry = utilities.getUtility(EndpointRegistry.class);
+ this.compositeContext = new CompositeContextImpl(manager.extensionPoints, endpointRegistry);
+ this.compositeActivator = utilities.getUtility(CompositeActivator.class);
try {
- Composite composite = manager.configureNode(configuration, contributions);
+ domainComposite = manager.configureNode(configuration, contributions);
- // get the top level composite for this node
- compositeActivator.setDomainComposite(composite);
-
// Activate the composite
- compositeActivator.activate(compositeActivator.getDomainComposite());
+ compositeActivator.activate(domainComposite);
// Start the composite
- compositeActivator.start(compositeActivator.getDomainComposite());
+ compositeActivator.start(compositeContext, domainComposite);
NodeFinder.addNode(IOHelper.createURI(configuration.getDomainURI()), this);
@@ -170,13 +174,13 @@ public class NodeImpl implements Node, Client {
}
NodeFinder.removeNode(this);
- if( compositeActivator.getDomainComposite() != null ) {
+ if( domainComposite != null ) {
// Stop the composite
- compositeActivator.stop(compositeActivator.getDomainComposite());
+ compositeActivator.stop(compositeContext, domainComposite);
// Deactivate the composite
- compositeActivator.deactivate(compositeActivator.getDomainComposite());
+ compositeActivator.deactivate(domainComposite);
} // end if
@@ -225,7 +229,7 @@ public class NodeImpl implements Node, Client {
// Lookup the component
Component component = null;
- for (Component compositeComponent : compositeActivator.getDomainComposite().getComponents()) {
+ for (Component compositeComponent : domainComposite.getComponents()) {
if (compositeComponent.getName().equals(componentName)) {
component = compositeComponent;
}
@@ -279,7 +283,6 @@ public class NodeImpl implements Node, Client {
public List<Endpoint> getServiceEndpoints() {
List<Endpoint> endpoints = new ArrayList<Endpoint>();
if (compositeActivator != null) {
- Composite domainComposite = compositeActivator.getDomainComposite();
if (domainComposite != null) {
for (Component component : domainComposite.getComponents()) {
for (Service service : component.getServices()) {
@@ -296,7 +299,7 @@ public class NodeImpl implements Node, Client {
}
public Composite getDomainComposite() {
- return compositeActivator.getDomainComposite();
+ return domainComposite;
}
public String dumpDomainComposite() {
@@ -322,10 +325,12 @@ public class NodeImpl implements Node, Client {
String result = bos.toString();
// write out and nested composites
- for(Component component : composite.getComponents()){
+ for (Component component : composite.getComponents()) {
if (component.getImplementation() instanceof Composite) {
- result += "\n<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->\n" +
- writeComposite((Composite)component.getImplementation(), compositeProcessor);
+ result +=
+ "\n<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->\n" + writeComposite((Composite)component
+ .getImplementation(),
+ compositeProcessor);
}
}