You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2009/03/11 20:13:15 UTC
svn commit: r752585 [1/2] - in /tuscany/java/sca:
itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/
modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/
modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ ...
Author: slaws
Date: Wed Mar 11 19:13:15 2009
New Revision: 752585
URL: http://svn.apache.org/viewvc?rev=752585&view=rev
Log:
Bring up the service wire based on the endpoint model. To turn this on change core/META-INF/services/org.apache.tuscany.sca.core.assembly.CompositeActivator to reference CompositeActivatorImpl2. There are a few classes with "2" appearing now so I can build this in parallel without (I hope) messing everyone else up. Endpoint reference building code still not in the right place yet.
Added:
tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointReference2Builder.java (with props)
tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java (with props)
tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java (with props)
tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java (with props)
Modified:
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/TestUtils.java
tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint2.java
tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java
tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java
tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java
tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/Endpoint2Impl.java
tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java
Modified: tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/TestUtils.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/TestUtils.java?rev=752585&r1=752584&r2=752585&view=diff
==============================================================================
--- tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/TestUtils.java (original)
+++ tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/TestUtils.java Wed Mar 11 19:13:15 2009
@@ -259,7 +259,8 @@
if (endpointReference.getTargetName() != null){
buffer += indent + " Wired: " +"\n";
buffer += indent + " Target: " + endpointReference.getTargetName()+"\n";
- if (endpointReference.getTargetEndpoint() != null){
+ if (endpointReference.getTargetEndpoint() != null &&
+ endpointReference.getTargetEndpoint().isUnresolved() == false){
buffer += indent + " Binding: " + endpointReference.getBinding().getName() +"\n";
buffer += indent + " TargetEndpoint: " + endpointReference.getTargetEndpoint().getBinding().getName()+"\n";
} else {
Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint2.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint2.java?rev=752585&r1=752584&r2=752585&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint2.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint2.java Wed Mar 11 19:13:15 2009
@@ -32,6 +32,14 @@
public interface Endpoint2 extends Base, PolicySubject, Cloneable {
/**
+ * Supports endpoint cloning
+ *
+ * @return endpoint
+ * @throws CloneNotSupportedException
+ */
+ Object clone() throws CloneNotSupportedException;
+
+ /**
* Get the component model object
*
* @return component
@@ -72,25 +80,24 @@
* @param binding
*/
void setBinding(Binding binding);
-
-
-
-
- // not sure these are required
+
/**
* Returns the interface contract defining the interface
*
* @return the interface contract
*/
- // InterfaceContract getInterfaceContract();
+ InterfaceContract getInterfaceContract();
/**
* Sets the interface contract defining the interface
*
* @param interfaceContract the interface contract
*/
- // void setInterfaceContract(InterfaceContract interfaceContract);
-
+ void setInterfaceContract(InterfaceContract interfaceContract);
+
+
+ // not sure these are required
+
/**
* Returns the binding specific URI for this endpoint.
*
Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java?rev=752585&r1=752584&r2=752585&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java Wed Mar 11 19:13:15 2009
@@ -31,6 +31,14 @@
public interface EndpointReference2 extends Base, PolicySubject, Cloneable {
/**
+ * Supports endpoint reference cloning
+ *
+ * @return endpointReference
+ * @throws CloneNotSupportedException
+ */
+ Object clone() throws CloneNotSupportedException;
+
+ /**
* Get the component model object
*
* @return component
@@ -114,24 +122,24 @@
*/
void setTargetEndpoint(Endpoint2 targetEndpoint);
-
-
-
- // not sure the methods below are required
-
/**
* Returns the interface contract defining the interface
*
* @return the interface contract
*/
- //InterfaceContract getInterfaceContract();
+ InterfaceContract getInterfaceContract();
/**
* Sets the interface contract defining the interface
*
* @param interfaceContract the interface contract
*/
- //void setInterfaceContract(InterfaceContract interfaceContract);
+ void setInterfaceContract(InterfaceContract interfaceContract);
+
+
+ // not sure the methods below are required
+
+
/**
* Returns the binding specific target URI for this endpoint reference.
Added: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointReference2Builder.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointReference2Builder.java?rev=752585&view=auto
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointReference2Builder.java (added)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointReference2Builder.java Wed Mar 11 19:13:15 2009
@@ -0,0 +1,43 @@
+/*
+ * 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.assembly.builder;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference2;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A builder that handles the configuration of endpoint references
+ * It collects together the logic so that it can be used at build time
+ * or later on during late binding scenarios
+ *
+ * @version $Rev$ $Date$
+ */
+public interface EndpointReference2Builder {
+
+ /**
+ * Build an endpoint.
+ *
+ * @param endpoint
+ * @param monitor
+ */
+ void build(EndpointReference2 endpointReference, Monitor monitor);
+
+}
Propchange: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointReference2Builder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointReference2Builder.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java?rev=752585&r1=752584&r2=752585&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java Wed Mar 11 19:13:15 2009
@@ -62,6 +62,7 @@
private CompositeBuilder compositeReferenceEndpointReferenceBuilder;
private CompositeBuilder compositeServiceEndpointBuilder;
+ private CompositeBuilder endpointReferenceBuilder;
public CompositeBuilderImpl(FactoryExtensionPoint factories, InterfaceContractMapper mapper) {
this(factories.getFactory(AssemblyFactory.class),
@@ -176,6 +177,7 @@
compositeReferenceEndpointReferenceBuilder = new CompositeReferenceEndpointReferenceBuilderImpl(assemblyFactory, interfaceContractMapper);
compositeServiceEndpointBuilder = new CompositeServiceEndpointBuilderImpl(assemblyFactory);
+ endpointReferenceBuilder = new EndpointReference2BuilderImpl(assemblyFactory, interfaceContractMapper);
}
public String getID() {
@@ -222,7 +224,12 @@
// create service endpoint models
compositeServiceEndpointBuilder.build(composite, definitions, monitor);
// create reference enpointreference models
- compositeReferenceEndpointReferenceBuilder.build(composite, definitions, monitor);
+ compositeReferenceEndpointReferenceBuilder.build(composite, definitions, monitor);
+
+ // TODO this needs to be offloaded to a plugpoint
+ // could be called upon when rebuilding wires
+ // wire endpoint references to endpoints
+ endpointReferenceBuilder.build(composite, definitions, monitor);
// ===============================================
// Wire the components
Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java?rev=752585&r1=752584&r2=752585&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java Wed Mar 11 19:13:15 2009
@@ -139,14 +139,20 @@
if (reference.getInterfaceContract() == null ||
interfaceContractMapper.isCompatible(reference.getInterfaceContract(),
targetComponentService.getInterfaceContract())) {
-
+ // create endpoint reference
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
endpointRef.setTargetName(targetComponentService.getName());
endpointRef.setUnresolved(false);
- matchForwardBinding(endpointRef, targetComponentService, monitor);
- matchCallbackBinding(endpointRef, targetComponentService, monitor);
+
+ // create dummy endpoint. This will be replaced when policies
+ // are matched and bindings are configured later
+ Endpoint2 endpoint = assemblyFactory.createEndpoint();
+ endpoint.setComponent(targetComponent);
+ endpoint.setService(targetComponentService);
+ endpoint.setUnresolved(true);
+ endpointRef.setTargetEndpoint(endpoint);
reference.getEndpointReferences().add(endpointRef);
@@ -201,13 +207,20 @@
interfaceContractMapper.isCompatible(reference.getInterfaceContract(),
targetComponentService.getInterfaceContract())) {
+ // create endpoint reference
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
endpointRef.setTargetName(targetComponentService.getName());
endpointRef.setUnresolved(false);
- matchForwardBinding(endpointRef, targetComponentService, monitor);
- matchCallbackBinding(endpointRef, targetComponentService, monitor);
+
+ // create dummy endpoint. This will be replaced when policies
+ // are matched and bindings are configured later
+ Endpoint2 endpoint = assemblyFactory.createEndpoint();
+ endpoint.setComponent(targetComponent);
+ endpoint.setService(targetComponentService);
+ endpoint.setUnresolved(true);
+ endpointRef.setTargetEndpoint(endpoint);
reference.getEndpointReferences().add(endpointRef);
} else {
@@ -219,7 +232,7 @@
targetName);
}
} else {
- // add an unresolved endpoint
+ // add an unresolved endpoint reference
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
@@ -259,13 +272,20 @@
interfaceContractMapper.isCompatible(reference.getInterfaceContract(),
targetComponentService.getInterfaceContract())) {
+ // create endpoint reference
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
endpointRef.setTargetName(targetComponentService.getName());
endpointRef.setUnresolved(false);
- matchForwardBinding(endpointRef, targetComponentService, monitor);
- matchCallbackBinding(endpointRef, targetComponentService, monitor);
+
+ // create dummy endpoint. This will be replaced when policies
+ // are matched and bindings are configured later
+ Endpoint2 endpoint = assemblyFactory.createEndpoint();
+ endpoint.setComponent(targetComponent);
+ endpoint.setService(targetComponentService);
+ endpoint.setUnresolved(true);
+ endpointRef.setTargetEndpoint(endpoint);
reference.getEndpointReferences().add(endpointRef);
} else {
@@ -277,7 +297,7 @@
targetName);
}
} else {
- // add an unresolved endpoint
+ // add an unresolved endpoint reference
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
@@ -349,14 +369,21 @@
if (reference.getInterfaceContract() == null ||
interfaceContractMapper.isCompatible(reference.getInterfaceContract(),
targetComponentService.getInterfaceContract())) {
+ // create enpoint reference
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
endpointRef.setBinding(binding);
endpointRef.setTargetName(targetComponentService.getName());
endpointRef.setUnresolved(false);
- matchForwardBinding(endpointRef, targetComponentService, monitor);
- matchCallbackBinding(endpointRef, targetComponentService, monitor);
+
+ // create dummy endpoint. This will be replaced when policies
+ // are matched and bindings are configured later
+ Endpoint2 endpoint = assemblyFactory.createEndpoint();
+ endpoint.setComponent(targetComponent);
+ endpoint.setService(targetComponentService);
+ endpoint.setUnresolved(true);
+ endpointRef.setTargetEndpoint(endpoint);
reference.getEndpointReferences().add(endpointRef);
} else {
@@ -380,162 +407,5 @@
}
}
}
- }
-
- private void matchForwardBinding(EndpointReference2 endpointReference,
- ComponentService service,
- Monitor monitor) {
-
- List<Binding> matchedReferenceBinding = new ArrayList<Binding>();
- List<Endpoint2> matchedServiceEndpoint = new ArrayList<Endpoint2>();
-
- // Find the corresponding bindings from the service side
- for (Binding referenceBinding : endpointReference.getReference().getBindings()) {
- for (Endpoint2 serviceEndpoint : service.getEndpoints()) {
-
- if (referenceBinding.getClass() == serviceEndpoint.getBinding().getClass() &&
- hasCompatiblePolicySets(referenceBinding, serviceEndpoint.getBinding())) {
-
- matchedReferenceBinding.add(referenceBinding);
- matchedServiceEndpoint.add(serviceEndpoint);
- }
- }
- }
-
- if (matchedReferenceBinding.isEmpty()) {
- // No matching binding
- endpointReference.setBinding(null);
- endpointReference.setTargetEndpoint(null);
- warning(monitor,
- "NoMatchingBinding",
- endpointReference.getReference(),
- endpointReference.getReference().getName(),
- service.getName());
- return;
- } else {
- // default to using the first matched binding
- int selectedBinding = 0;
-
- for (int i = 0; i < matchedReferenceBinding.size(); i++) {
- // If binding.sca is present, use it
- if (SCABinding.class.isInstance(matchedReferenceBinding.get(i))) {
- selectedBinding = i;
- }
- }
-
- Binding referenceBinding = matchedReferenceBinding.get(selectedBinding);
- Endpoint2 serviceEndpoint = matchedServiceEndpoint.get(selectedBinding);
-
- // populate the endpoint reference
- try {
-
- Binding cloned = (Binding) referenceBinding.clone();
-
- // Set the binding URI to the URI of the target service
- // that has been matched
- if (referenceBinding.getURI() == null) {
- cloned.setURI(serviceEndpoint.getBinding().getURI());
- }
-
- endpointReference.setBinding(referenceBinding);
- endpointReference.setTargetEndpoint(serviceEndpoint);
-
- } catch (Exception ex) {
- // do nothing
- }
- }
- }
-
- // TODO
- // Pretty much a duplicate of matchForwardBinding to handle callback bindings
- // will rationalize when I understand what we need to do with callbacks
- private void matchCallbackBinding(EndpointReference2 endpointReference,
- ComponentService service,
- Monitor monitor) {
-
- // if no callback on the interface do nothing
- if (endpointReference.getReference().getInterfaceContract() == null ||
- endpointReference.getReference().getInterfaceContract().getCallbackInterface() == null){
- return;
- }
-
- List<Binding> matchedReferenceBinding = new ArrayList<Binding>();
- List<Binding> matchedServiceBinding = new ArrayList<Binding>();
-
- // Find the corresponding bindings from the service side
- for (Binding referenceBinding : endpointReference.getReference().getCallback().getBindings()) {
- for (Binding serviceBinding : service.getCallback().getBindings()) {
-
- if (referenceBinding.getClass() == serviceBinding.getClass() &&
- hasCompatiblePolicySets(referenceBinding, serviceBinding)) {
-
- matchedReferenceBinding.add(referenceBinding);
- matchedServiceBinding.add(serviceBinding);
- }
- }
- }
-
- if (matchedReferenceBinding.isEmpty()) {
- // No matching binding
- endpointReference.setBinding(null);
- endpointReference.setTargetEndpoint(null);
- warning(monitor,
- "NoMatchingCallbackBinding",
- endpointReference.getReference(),
- endpointReference.getReference().getName(),
- service.getName());
- return;
- } else {
- // default to using the first matched binding
- int selectedBinding = 0;
-
- for (int i = 0; i < matchedReferenceBinding.size(); i++){
- // If binding.sca is present, use it
- if (SCABinding.class.isInstance(matchedReferenceBinding.get(i))) {
- selectedBinding = i;
- }
- }
-
- Binding referenceBinding = matchedReferenceBinding.get(selectedBinding);
- Binding serviceBinding = matchedServiceBinding.get(selectedBinding);
-
- // populate the endpoint reference
- try {
-
- Binding cloned = (Binding)referenceBinding.clone();
-
- // Set the binding URI to the URI of the target service
- // that has been matched
- if (referenceBinding.getURI() == null) {
- cloned.setURI(serviceBinding.getURI());
- }
-
- endpointReference.setCallbackBinding(referenceBinding);
-
- } catch (Exception ex) {
- // do nothing
- }
- }
- }
-
- private boolean hasCompatiblePolicySets(Binding refBinding, Binding svcBinding) {
- boolean isCompatible = true;
- if ( refBinding instanceof PolicySubject && svcBinding instanceof PolicySubject ) {
- //TODO : need to add more compatibility checks at the policy attachment levels
- for ( PolicySet svcPolicySet : ((PolicySubject)svcBinding).getPolicySets() ) {
- isCompatible = false;
- for ( PolicySet refPolicySet : ((PolicySubject)refBinding).getPolicySets() ) {
- if ( svcPolicySet.equals(refPolicySet) ) {
- isCompatible = true;
- break;
- }
- }
- //if there exists no matching policy set in the reference binding
- if ( !isCompatible ) {
- return isCompatible;
- }
- }
- }
- return isCompatible;
}
}
Added: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java?rev=752585&view=auto
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java (added)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java Wed Mar 11 19:13:15 2009
@@ -0,0 +1,320 @@
+/*
+ * 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.assembly.builder.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.CompositeService;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.Endpoint2;
+import org.apache.tuscany.sca.assembly.EndpointReference2;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.assembly.builder.EndpointBuilder;
+import org.apache.tuscany.sca.assembly.builder.EndpointReference2Builder;
+import org.apache.tuscany.sca.definitions.Definitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySubject;
+
+/**
+ * An builder that takes endpoint references and resolves them. It either finds local
+ * service endpoints if they are available or asks the domain. The main function here
+ * is to perform binding and policy matching.
+ * This is a separate builder in case it is required by undresolved endpoints
+ * once the runtime has started.
+ *
+ * @version $Rev$ $Date$
+ */
+public class EndpointReference2BuilderImpl extends BaseBuilderImpl implements CompositeBuilder, EndpointReference2Builder {
+
+
+ public EndpointReference2BuilderImpl(AssemblyFactory assemblyFactory, InterfaceContractMapper interfaceContractMapper) {
+ super(assemblyFactory, null, null, null, interfaceContractMapper);
+ }
+
+ public String getID() {
+ return "org.apache.tuscany.sca.assembly.builder.EndpointReference2Builder";
+ }
+
+ /**
+ * Build all the endpoint references
+ *
+ * @param composite
+ */
+ public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException
+ {
+ // process top level composite references
+ // TODO - I don't think OASIS allows for these
+ //
+ //processCompositeReferences(composite);
+
+ // process component services
+ processComponentReferences(composite, monitor);
+ }
+
+ private void processCompositeReferences(Composite composite) {
+ // TODO do we need this for OASIS?
+ }
+
+ private void processComponentReferences(Composite composite, Monitor monitor) {
+
+ // index all of the components in the composite
+ Map<String, Component> components = new HashMap<String, Component>();
+ indexComponents(composite, components);
+
+ // index all of the services in the composite
+ Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>();
+ indexServices(composite, componentServices);
+
+ // create endpoint references for each component's references
+ for (Component component : composite.getComponents()) {
+ // recurse for composite implementations
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ processComponentReferences((Composite)implementation, monitor);
+ }
+
+ // create endpoint references to represent the component reference
+ for (ComponentReference reference : component.getReferences()) {
+ for (EndpointReference2 endpointReference : reference.getEndpointReferences()){
+ build(endpointReference, monitor);
+ }
+ }
+ }
+ }
+
+ /**
+ * Build a single endpoint reference
+ *
+ * @param endpoint
+ * @param monitor
+ */
+ public void build(EndpointReference2 endpointReference, Monitor monitor) {
+ Endpoint2 endpoint = endpointReference.getTargetEndpoint();
+
+
+ // check if the endpoint was available locally
+ if (endpoint == null){
+ if (endpointReference.isUnresolved() == false){
+ // this is a non-wired endpoint reference
+ return;
+ } else {
+ // target service is available remotely
+
+ // go look it up in the domain
+ }
+ } else {
+ // target service is available locally
+
+ // check for wired reference that's already resolved
+ if (endpoint.isUnresolved() == false){
+ return;
+ }
+
+ // find the real endpoint for this reference by matching bindings
+ // and policy sets
+ matchForwardBinding(endpointReference,
+ endpointReference.getTargetEndpoint().getService(),
+ monitor);
+
+ matchCallbackBinding(endpointReference,
+ endpointReference.getTargetEndpoint().getService(),
+ monitor);
+ }
+
+ }
+
+ // TODO - In OASIS case there are no bindings to match with on the
+ // reference side. This code will be factored out into a pluggable
+ // piece
+ private void matchForwardBinding(EndpointReference2 endpointReference,
+ ComponentService service,
+ Monitor monitor) {
+
+ List<Binding> matchedReferenceBinding = new ArrayList<Binding>();
+ List<Endpoint2> matchedServiceEndpoint = new ArrayList<Endpoint2>();
+
+ // Find the corresponding bindings from the service side
+ for (Binding referenceBinding : endpointReference.getReference().getBindings()) {
+ for (Endpoint2 serviceEndpoint : service.getEndpoints()) {
+
+ if (referenceBinding.getClass() == serviceEndpoint.getBinding().getClass() &&
+ hasCompatiblePolicySets(referenceBinding, serviceEndpoint.getBinding())) {
+
+ matchedReferenceBinding.add(referenceBinding);
+ matchedServiceEndpoint.add(serviceEndpoint);
+ }
+ }
+ }
+
+ if (matchedReferenceBinding.isEmpty()) {
+ // No matching binding
+ endpointReference.setBinding(null);
+ endpointReference.setTargetEndpoint(null);
+ warning(monitor,
+ "NoMatchingBinding",
+ endpointReference.getReference(),
+ endpointReference.getReference().getName(),
+ service.getName());
+ return;
+ } else {
+ // default to using the first matched binding
+ int selectedBinding = 0;
+
+ for (int i = 0; i < matchedReferenceBinding.size(); i++) {
+ // If binding.sca is present, use it
+ if (SCABinding.class.isInstance(matchedReferenceBinding.get(i))) {
+ selectedBinding = i;
+ }
+ }
+
+ Binding referenceBinding = matchedReferenceBinding.get(selectedBinding);
+ Endpoint2 serviceEndpoint = matchedServiceEndpoint.get(selectedBinding);
+
+ // populate the endpoint reference
+ try {
+
+ Binding cloned = (Binding) referenceBinding.clone();
+
+ // Set the binding URI to the URI of the target service
+ // that has been matched
+ if (referenceBinding.getURI() == null) {
+ cloned.setURI(serviceEndpoint.getBinding().getURI());
+ }
+
+ endpointReference.setBinding(referenceBinding);
+ endpointReference.setTargetEndpoint(serviceEndpoint);
+
+ } catch (Exception ex) {
+ // do nothing
+ }
+ }
+ }
+
+ // TODO
+ // Pretty much a duplicate of matchForwardBinding to handle callback bindings
+ // will rationalize when I understand what we need to do with callbacks
+ private void matchCallbackBinding(EndpointReference2 endpointReference,
+ ComponentService service,
+ Monitor monitor) {
+
+ // if no callback on the interface do nothing
+ if (endpointReference.getReference().getInterfaceContract() == null ||
+ endpointReference.getReference().getInterfaceContract().getCallbackInterface() == null){
+ return;
+ }
+
+ List<Binding> matchedReferenceBinding = new ArrayList<Binding>();
+ List<Binding> matchedServiceBinding = new ArrayList<Binding>();
+
+ // Find the corresponding bindings from the service side
+ for (Binding referenceBinding : endpointReference.getReference().getCallback().getBindings()) {
+ for (Binding serviceBinding : service.getCallback().getBindings()) {
+
+ if (referenceBinding.getClass() == serviceBinding.getClass() &&
+ hasCompatiblePolicySets(referenceBinding, serviceBinding)) {
+
+ matchedReferenceBinding.add(referenceBinding);
+ matchedServiceBinding.add(serviceBinding);
+ }
+ }
+ }
+
+ if (matchedReferenceBinding.isEmpty()) {
+ // No matching binding
+ endpointReference.setBinding(null);
+ endpointReference.setTargetEndpoint(null);
+ warning(monitor,
+ "NoMatchingCallbackBinding",
+ endpointReference.getReference(),
+ endpointReference.getReference().getName(),
+ service.getName());
+ return;
+ } else {
+ // default to using the first matched binding
+ int selectedBinding = 0;
+
+ for (int i = 0; i < matchedReferenceBinding.size(); i++){
+ // If binding.sca is present, use it
+ if (SCABinding.class.isInstance(matchedReferenceBinding.get(i))) {
+ selectedBinding = i;
+ }
+ }
+
+ Binding referenceBinding = matchedReferenceBinding.get(selectedBinding);
+ Binding serviceBinding = matchedServiceBinding.get(selectedBinding);
+
+ // populate the endpoint reference
+ try {
+
+ Binding cloned = (Binding)referenceBinding.clone();
+
+ // Set the binding URI to the URI of the target service
+ // that has been matched
+ if (referenceBinding.getURI() == null) {
+ cloned.setURI(serviceBinding.getURI());
+ }
+
+ endpointReference.setCallbackBinding(referenceBinding);
+
+ } catch (Exception ex) {
+ // do nothing
+ }
+ }
+ }
+
+ private boolean hasCompatiblePolicySets(Binding refBinding, Binding svcBinding) {
+ boolean isCompatible = true;
+ if ( refBinding instanceof PolicySubject && svcBinding instanceof PolicySubject ) {
+ //TODO : need to add more compatibility checks at the policy attachment levels
+ for ( PolicySet svcPolicySet : ((PolicySubject)svcBinding).getPolicySets() ) {
+ isCompatible = false;
+ for ( PolicySet refPolicySet : ((PolicySubject)refBinding).getPolicySets() ) {
+ if ( svcPolicySet.equals(refPolicySet) ) {
+ isCompatible = true;
+ break;
+ }
+ }
+ //if there exists no matching policy set in the reference binding
+ if ( !isCompatible ) {
+ return isCompatible;
+ }
+ }
+ }
+ return isCompatible;
+ }
+
+}
Propchange: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/Endpoint2Impl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/Endpoint2Impl.java?rev=752585&r1=752584&r2=752585&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/Endpoint2Impl.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/Endpoint2Impl.java Wed Mar 11 19:13:15 2009
@@ -38,11 +38,12 @@
*/
public class Endpoint2Impl implements Endpoint2 {
+ private Boolean unresolved;
private Component component;
private ComponentService service;
private Binding binding;
private Binding callbackBinding;
- //private InterfaceContract interfaceContract;
+ private InterfaceContract interfaceContract;
//private String uri;
private List<PolicySet> policySets = new ArrayList<PolicySet>();
private List<Intent> requiredIntents = new ArrayList<Intent>();
@@ -56,12 +57,11 @@
}
public boolean isUnresolved() {
- // TODO Auto-generated method stub
- return false;
+ return unresolved;
}
public void setUnresolved(boolean unresolved) {
- // TODO Auto-generated method stub
+ this.unresolved = unresolved;
}
public Component getComponent() {
@@ -87,7 +87,7 @@
public void setBinding(Binding binding) {
this.binding = binding;
}
-/*
+
public InterfaceContract getInterfaceContract() {
return interfaceContract;
}
@@ -95,7 +95,7 @@
public void setInterfaceContract(InterfaceContract interfaceContract) {
this.interfaceContract = interfaceContract;
}
-
+/*
public String getURI() {
return uri;
}
Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java?rev=752585&r1=752584&r2=752585&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java Wed Mar 11 19:13:15 2009
@@ -39,6 +39,7 @@
*/
public class EndpointReference2Impl implements EndpointReference2 {
+ private Boolean unresolved = true;
private Component component;
private ComponentReference reference;
private Binding binding;
@@ -46,7 +47,7 @@
private String targetName;
private Endpoint2 targetEndpoint;
private InterfaceContract interfaceContract;
- private String uri;
+// private String uri;
private List<PolicySet> policySets = new ArrayList<PolicySet>();
private List<Intent> requiredIntents = new ArrayList<Intent>();
@@ -59,12 +60,11 @@
}
public boolean isUnresolved() {
- // TODO Auto-generated method stub
- return false;
+ return unresolved;
}
public void setUnresolved(boolean unresolved) {
- // TODO Auto-generated method stub
+ this.unresolved = unresolved;
}
public Component getComponent() {
@@ -116,7 +116,7 @@
}
- /*
+
public InterfaceContract getInterfaceContract() {
return interfaceContract;
}
@@ -124,7 +124,8 @@
public void setInterfaceContract(InterfaceContract interfaceContract) {
this.interfaceContract = interfaceContract;
}
-
+
+ /*
public String getURI() {
return uri;
}