summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/deployment
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules/deployment')
-rw-r--r--sca-java-2.x/trunk/modules/deployment/META-INF/MANIFEST.MF1
-rw-r--r--sca-java-2.x/trunk/modules/deployment/pom.xml20
-rw-r--r--sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java115
3 files changed, 128 insertions, 8 deletions
diff --git a/sca-java-2.x/trunk/modules/deployment/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/deployment/META-INF/MANIFEST.MF
index 58d085ce87..65f35c59b0 100644
--- a/sca-java-2.x/trunk/modules/deployment/META-INF/MANIFEST.MF
+++ b/sca-java-2.x/trunk/modules/deployment/META-INF/MANIFEST.MF
@@ -45,6 +45,7 @@ Import-Package: javax.xml.namespace,
org.apache.tuscany.sca.deployment;version="2.0.0",
org.apache.tuscany.sca.monitor;version="2.0.0",
org.apache.tuscany.sca.xsd;version="2.0.0",
+ org.apache.tuscany.sca.runtime;version="2.0.0",
org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional
Bundle-SymbolicName: org.apache.tuscany.sca.deployment
Bundle-DocURL: http://www.apache.org/
diff --git a/sca-java-2.x/trunk/modules/deployment/pom.xml b/sca-java-2.x/trunk/modules/deployment/pom.xml
index 68205135a2..31e380eaea 100644
--- a/sca-java-2.x/trunk/modules/deployment/pom.xml
+++ b/sca-java-2.x/trunk/modules/deployment/pom.xml
@@ -37,24 +37,30 @@
<artifactId>tuscany-assembly</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
- <dependency>
+ <dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-contribution</artifactId>
+ <artifactId>tuscany-assembly-xsd</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-assembly-xml</artifactId>
+ <artifactId>tuscany-contribution</artifactId>
<version>2.0-SNAPSHOT</version>
- </dependency>
+ </dependency>
- <dependency>
+ <dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-assembly-xsd</artifactId>
+ <artifactId>tuscany-core</artifactId>
<version>2.0-SNAPSHOT</version>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
diff --git a/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java b/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
index cf94c5a8b7..c3e680bd4d 100644
--- a/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
+++ b/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
@@ -24,6 +24,7 @@ import java.io.Writer;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -38,7 +39,13 @@ import javax.xml.stream.XMLStreamWriter;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Base;
+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.builder.BuilderContext;
import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
@@ -72,6 +79,7 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.impl.EndpointRegistryImpl;
import org.apache.tuscany.sca.definitions.Definitions;
import org.apache.tuscany.sca.definitions.DefinitionsFactory;
import org.apache.tuscany.sca.definitions.util.DefinitionsUtil;
@@ -79,6 +87,9 @@ import org.apache.tuscany.sca.definitions.xml.DefinitionsExtensionPoint;
import org.apache.tuscany.sca.deployment.Deployer;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.runtime.BaseEndpointRegistry;
+import org.apache.tuscany.sca.runtime.EndpointReferenceBinder;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
import org.apache.tuscany.sca.xsd.XSDFactory;
import org.apache.tuscany.sca.xsd.XSDefinition;
@@ -103,6 +114,7 @@ public class DeployerImpl implements Deployer {
protected ExtensibleURLArtifactProcessor artifactProcessor;
protected ExtensibleStAXArtifactProcessor staxProcessor;
protected ValidationSchemaExtensionPoint validationSchema;
+ protected EndpointReferenceBinder endpointReferenceBinder;
protected MonitorFactory monitorFactory;
@@ -310,11 +322,13 @@ public class DeployerImpl implements Deployer {
// get the validation schema
validationSchema = registry.getExtensionPoint(ValidationSchemaExtensionPoint.class);
+
+ // Get the reference binder
+ endpointReferenceBinder = registry.getExtensionPoint(EndpointReferenceBinder.class);
loadSystemContribution(new ProcessorContext(monitorFactory.createMonitor()));
inited = true;
-
}
protected void loadSystemContribution(ProcessorContext context) {
@@ -546,6 +560,9 @@ public class DeployerImpl implements Deployer {
BuilderContext builderContext = new BuilderContext(systemDefinitions, bindingMap, monitor);
compositeBuilder.build(domainComposite, builderContext);
// analyzeProblems(monitor);
+
+ // do build time reference binding
+ buildTimeReferenceBind(domainComposite, builderContext);
return domainComposite;
}
@@ -717,5 +734,101 @@ public class DeployerImpl implements Deployer {
init();
return systemDefinitions;
}
+
+ // The following operations gives references a chance to bind to
+ // services at deployment time.
+
+ private void buildTimeReferenceBind(Composite domainComposite, BuilderContext context){
+ // create temporary local registry for all available local endpoints
+ EndpointRegistry endpointRegistry = new LocalEndpointRegistry(registry);
+
+ // populate the registry with all the endpoints that are present in the model
+ populateLocalRegistry(domainComposite, endpointRegistry, context);
+
+ // match all local services against the endpoint references
+ // we've just created
+ matchEndpointReferences(domainComposite, endpointRegistry, context);
+ }
+
+ private void populateLocalRegistry(Composite composite, EndpointRegistry registry, BuilderContext context){
+ for (Component component : composite.getComponents()) {
+ // recurse for composite implementations
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ populateLocalRegistry((Composite)implementation, registry, context);
+ }
+
+ // add all endpoints to the local registry
+ for (ComponentService service : component.getServices()) {
+ for (Endpoint endpoint : service.getEndpoints()){
+ registry.addEndpoint(endpoint);
+ }
+ }
+
+ // add endpoint references that we want to match to the registry
+ for (ComponentReference reference : component.getReferences()) {
+ for (EndpointReference epr : reference.getEndpointReferences()){
+ if (epr.getStatus().equals(EndpointReference.Status.WIRED_TARGET_NOT_FOUND)||
+ epr.getStatus().equals(EndpointReference.Status.WIRED_TARGET_IN_BINDING_URI)){
+ registry.addEndpointReference(epr);
+ }
+ }
+ }
+ }
+ }
+
+ private void matchEndpointReferences(Composite composite, EndpointRegistry registry, BuilderContext builderContext){
+
+ // look at all the endpoint references and try to match them to
+ // endpoints
+ for (EndpointReference endpointReference : registry.getEndpointReferences()){
+ endpointReferenceBinder.bindBuildTime(registry, endpointReference, builderContext);
+ }
+ }
+
+ // A minimal endpoint registry implementation used to store the Endpoints/EndpointReferences
+ // for build time local reference resolution. We don't rely on the endpoint registry
+ // factory here as we specifically just want to do simple local resolution
+ class LocalEndpointRegistry extends BaseEndpointRegistry {
+
+ private List<Endpoint> endpoints = new ArrayList<Endpoint>();
+
+ public LocalEndpointRegistry(ExtensionPointRegistry registry){
+ super(registry, null, "", "");
+ }
+
+ public void addEndpoint(Endpoint endpoint) {
+ endpoints.add(endpoint);
+ endpointAdded(endpoint);
+ }
+
+ public void removeEndpoint(Endpoint endpoint) {
+ }
+
+ public Collection<Endpoint> getEndpoints() {
+ return endpoints;
+ }
+
+ public Endpoint getEndpoint(String uri) {
+ return null;
+ }
+
+ public List<Endpoint> findEndpoint(String uri) {
+ List<Endpoint> foundEndpoints = new ArrayList<Endpoint>();
+ for (Endpoint endpoint : endpoints) {
+ if (endpoint.matches(uri)) {
+ foundEndpoints.add(endpoint);
+ logger.fine("Found endpoint with matching service - " + endpoint);
+ }
+ // else the service name doesn't match
+ }
+ return foundEndpoints;
+ }
+
+ public void start() {
+ }
+ public void stop() {
+ }
+ }
}