diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-10 12:53:49 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-10 12:53:49 +0000 |
commit | 62b81c136a65722d6cb39e6f5bd6741cc128891b (patch) | |
tree | 1e03a96ec7a23998c103b140eae2a9b685d97535 /java/sca/modules/assembly/src | |
parent | 8120d943322aa1094e88a0820e91e050a5e5a856 (diff) |
Add initial reference resolution to builders. Will be replaced with separate resolution logic when I get further into wire building for endpoints.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@752097 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/assembly/src')
6 files changed, 262 insertions, 75 deletions
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint2.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint2.java index d99d4f6450..076ea74284 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint2.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint2.java @@ -73,31 +73,35 @@ public interface Endpoint2 extends Base, PolicySubject, Cloneable { */ 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); /** * Returns the binding specific URI for this endpoint. * * @return uri the binding specific URI */ - String getURI(); + // String getURI(); /** * Sets the binding specific URI for this endpoint. * * @param uri the binding specific URI */ - void setURI(String uri); + // void setURI(String uri); } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java index 7e4898507a..a0cc427804 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java @@ -22,27 +22,13 @@ import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.policy.PolicySubject; /** - * Represents an endpoint reference. An SCA reference can reference service enpoints in a + * Represents an endpoint reference. An SCA reference can reference service endpoints in a * number of ways. Target names, autowire, configured bindings. The endpoint reference * captures the result of specifying one of these things. * * @version $Rev$ $Date$ */ -public interface EndpointReference2 extends Base, PolicySubject, Cloneable { - - /** - * Get the name of the target service that this endpoint reference refers to - * - * @return target service name - */ - String getTargetName(); - - /** - * Set the name of the target service that this endpoint reference refers to - * - * @param targetName - */ - void setTargetName(String targetName); +public interface EndpointReference2 extends Base, PolicySubject, Cloneable { /** * Get the component model object @@ -85,46 +71,79 @@ public interface EndpointReference2 extends Base, PolicySubject, Cloneable { * @param binding the resolved reference binding */ void setBinding(Binding binding); + + /** + * Get the reference callback binding + * + * @return callbackBinding the reference callback binding + */ + Binding getCallbackBinding(); + + /** + * Set the reference callback binding + * + * @param callbackBinding the reference callback binding + */ + void setCallbackBinding(Binding callbackBinding); /** + * Get the name of the target service that this endpoint reference refers to + * + * @return target service name + */ + String getTargetName(); + + /** + * Set the name of the target service that this endpoint reference refers to + * + * @param targetName + */ + void setTargetName(String targetName); + + /** * Get the target endpoint * * @return endpoint the target endpoint */ - Endpoint2 getEndpoint(); + Endpoint2 getTargetEndpoint(); /** * Set the target endpoint model object * * @param endpoint the target endpoint */ - void setEndpoint(Endpoint2 endpoint); + 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); /** * Returns the binding specific target URI for this endpoint reference. * * @return uri the binding specific target URI */ - String getURI(); + //String getURI(); /** * Sets the binding specific target URI for this endpoint reference. * * @param uri the binding specific target URI */ - void setURI(String uri); + //void setURI(String uri); } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java index e15183e65d..3f184767c0 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java @@ -204,10 +204,6 @@ public class CompositeBuilderImpl implements CompositeBuilder { // Configure composite references compositeReferenceConfigurationBuilder.build(composite, definitions, monitor); - - // TODO - temporarily add endpoint builders - compositeServiceEndpointBuilder.build(composite, definitions, monitor); - compositeReferenceEndpointReferenceBuilder.build(composite, definitions, monitor); // Configure binding URIs compositeBindingURIBuilder.build(composite, definitions, monitor); @@ -221,6 +217,14 @@ public class CompositeBuilderImpl implements CompositeBuilder { // Build component service binding-related information componentServiceBindingBuilder.build(composite, definitions, monitor); + // =============================================== + // TODO - temporarily add OASIS endpoint builders + // create service endpoint models + compositeServiceEndpointBuilder.build(composite, definitions, monitor); + // create reference enpointreference models + compositeReferenceEndpointReferenceBuilder.build(composite, definitions, monitor); + // =============================================== + // Wire the components componentReferenceWireBuilder.build(composite, definitions, monitor); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java index da21f6e635..33867e0127 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java @@ -33,10 +33,12 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.CompositeReference; import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.Endpoint2; import org.apache.tuscany.sca.assembly.EndpointFactory; import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.assembly.Implementation; 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.SCABinding; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; @@ -45,6 +47,8 @@ import org.apache.tuscany.sca.assembly.builder.DefaultEndpointBuilder; 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.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; /** * A composite builder that creates endpoint reference models. @@ -84,7 +88,7 @@ public class CompositeReferenceEndpointReferenceBuilderImpl extends BaseBuilderI private void processComponentReferences(Composite composite, Monitor monitor) { - // index all of the services in the composite + // index all of the components in the composite Map<String, Component> components = new HashMap<String, Component>(); indexComponents(composite, components); @@ -139,14 +143,10 @@ public class CompositeReferenceEndpointReferenceBuilderImpl extends BaseBuilderI EndpointReference2 endpointRef = assemblyFactory.createEndpointReference(); endpointRef.setComponent(component); endpointRef.setReference(reference); - endpointRef.setInterfaceContract(reference.getInterfaceContract()); endpointRef.setTargetName(targetComponentService.getName()); endpointRef.setUnresolved(false); - - // TODO binding is chosen at endpoint resolution when - // endpoint reference is matched with endpoint - //endpointRef.setBinding(binding); - //endpointRef.setEndpoint(endpoint); + matchForwardBinding(endpointRef, targetComponentService, monitor); + matchCallbackBinding(endpointRef, targetComponentService, monitor); reference.getEndpointReferences().add(endpointRef); @@ -204,14 +204,10 @@ public class CompositeReferenceEndpointReferenceBuilderImpl extends BaseBuilderI EndpointReference2 endpointRef = assemblyFactory.createEndpointReference(); endpointRef.setComponent(component); endpointRef.setReference(reference); - endpointRef.setInterfaceContract(reference.getInterfaceContract()); endpointRef.setTargetName(targetComponentService.getName()); endpointRef.setUnresolved(false); - - // TODO binding is chosen at endpoint resolution when - // endpoint reference is matched with endpoint - //endpointRef.setBinding(binding); - //endpointRef.setEndpoint(endpoint); + matchForwardBinding(endpointRef, targetComponentService, monitor); + matchCallbackBinding(endpointRef, targetComponentService, monitor); reference.getEndpointReferences().add(endpointRef); } else { @@ -227,7 +223,6 @@ public class CompositeReferenceEndpointReferenceBuilderImpl extends BaseBuilderI EndpointReference2 endpointRef = assemblyFactory.createEndpointReference(); endpointRef.setComponent(component); endpointRef.setReference(reference); - endpointRef.setInterfaceContract(reference.getInterfaceContract()); endpointRef.setTargetName(targetName); endpointRef.setUnresolved(true); @@ -267,14 +262,10 @@ public class CompositeReferenceEndpointReferenceBuilderImpl extends BaseBuilderI EndpointReference2 endpointRef = assemblyFactory.createEndpointReference(); endpointRef.setComponent(component); endpointRef.setReference(reference); - endpointRef.setInterfaceContract(reference.getInterfaceContract()); endpointRef.setTargetName(targetComponentService.getName()); endpointRef.setUnresolved(false); - - // TODO binding is chosen at endpoint resolution when - // endpoint reference is matched with endpoint - //endpointRef.setBinding(binding); - //endpointRef.setEndpoint(endpoint); + matchForwardBinding(endpointRef, targetComponentService, monitor); + matchCallbackBinding(endpointRef, targetComponentService, monitor); reference.getEndpointReferences().add(endpointRef); } else { @@ -290,7 +281,6 @@ public class CompositeReferenceEndpointReferenceBuilderImpl extends BaseBuilderI EndpointReference2 endpointRef = assemblyFactory.createEndpointReference(); endpointRef.setComponent(component); endpointRef.setReference(reference); - endpointRef.setInterfaceContract(reference.getInterfaceContract()); endpointRef.setTargetName(targetName); endpointRef.setUnresolved(true); @@ -363,9 +353,11 @@ public class CompositeReferenceEndpointReferenceBuilderImpl extends BaseBuilderI endpointRef.setComponent(component); endpointRef.setReference(reference); endpointRef.setBinding(binding); - endpointRef.setInterfaceContract(reference.getInterfaceContract()); endpointRef.setTargetName(targetComponentService.getName()); - endpointRef.setUnresolved(false); + endpointRef.setUnresolved(false); + matchForwardBinding(endpointRef, targetComponentService, monitor); + matchCallbackBinding(endpointRef, targetComponentService, monitor); + reference.getEndpointReferences().add(endpointRef); } else { warning(monitor, @@ -381,12 +373,169 @@ public class CompositeReferenceEndpointReferenceBuilderImpl extends BaseBuilderI endpointRef.setComponent(component); endpointRef.setReference(reference); endpointRef.setBinding(binding); - endpointRef.setInterfaceContract(reference.getInterfaceContract()); - endpointRef.setTargetName(uri); + endpointRef.setTargetName(null); + endpointRef.setTargetEndpoint(null); endpointRef.setUnresolved(false); reference.getEndpointReferences().add(endpointRef); } } } } + + 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; + } } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/Endpoint2Impl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/Endpoint2Impl.java index b5dac5a284..94309b6641 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/Endpoint2Impl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/Endpoint2Impl.java @@ -42,8 +42,8 @@ public class Endpoint2Impl implements Endpoint2 { private ComponentService service; private Binding binding; private Binding callbackBinding; - private InterfaceContract interfaceContract; - private String uri; + //private InterfaceContract interfaceContract; + //private String uri; private List<PolicySet> policySets = new ArrayList<PolicySet>(); private List<Intent> requiredIntents = new ArrayList<Intent>(); @@ -87,7 +87,7 @@ public class Endpoint2Impl implements Endpoint2 { public void setBinding(Binding binding) { this.binding = binding; } - +/* public InterfaceContract getInterfaceContract() { return interfaceContract; } @@ -103,7 +103,7 @@ public class Endpoint2Impl implements Endpoint2 { public void setURI(String uri) { this.uri = uri; } - +*/ public List<PolicySet> getPolicySets() { return policySets; } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java index ceeba3ceb0..eacdeb4cad 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java @@ -38,13 +38,13 @@ import org.apache.tuscany.sca.policy.PolicySubject; * @version $Rev$ $Date$ */ public class EndpointReference2Impl implements EndpointReference2 { - - private String targetName; + private Component component; private ComponentReference reference; private Binding binding; private Binding callbackBinding; - private Endpoint2 endpoint; + private String targetName; + private Endpoint2 targetEndpoint; private InterfaceContract interfaceContract; private String uri; private List<PolicySet> policySets = new ArrayList<PolicySet>(); @@ -67,14 +67,6 @@ public class EndpointReference2Impl implements EndpointReference2 { // TODO Auto-generated method stub } - public String getTargetName() { - return targetName; - } - - public void setTargetName(String targetName) { - this.targetName = targetName; - } - public Component getComponent() { return component; } @@ -98,15 +90,33 @@ public class EndpointReference2Impl implements EndpointReference2 { public void setBinding(Binding binding) { this.binding = binding; } - - public Endpoint2 getEndpoint() { - return endpoint; + + public Binding getCallbackBinding() { + return callbackBinding; + } + + public void setCallbackBinding(Binding callbackBinding) { + this.callbackBinding = callbackBinding; + } + + public String getTargetName() { + return targetName; } - public void setEndpoint(Endpoint2 endpoint) { - this.endpoint = endpoint; + public void setTargetName(String targetName) { + this.targetName = targetName; + } + + public Endpoint2 getTargetEndpoint() { + return targetEndpoint; } + + public void setTargetEndpoint(Endpoint2 targetEndpoint) { + this.targetEndpoint = targetEndpoint; + } + + /* public InterfaceContract getInterfaceContract() { return interfaceContract; } @@ -122,6 +132,7 @@ public class EndpointReference2Impl implements EndpointReference2 { public void setURI(String uri) { this.uri = uri; } + */ public List<PolicySet> getPolicySets() { return policySets; |