From 0b29e46291e31be846fabe25ce3cf9ee9e40ce5c Mon Sep 17 00:00:00 2001 From: bdaniel Date: Fri, 23 Jul 2010 06:13:25 +0000 Subject: Remove constrained intents from endpoint references at runtime binding time git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@966983 13f79535-47bb-0310-9956-ffa450edef68 --- .../runtime/impl/EndpointReferenceBinderImpl.java | 40 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'sca-java-2.x') diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java index b58635d6d1..2b59e892be 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java @@ -49,6 +49,7 @@ import org.apache.tuscany.sca.interfacedef.util.Audit; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.policy.BindingType; +import org.apache.tuscany.sca.policy.ExtensionType; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.IntentMap; import org.apache.tuscany.sca.policy.PolicySet; @@ -559,8 +560,8 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { // this they must be satisfied by reference policy sets // Failing this the intent is unresolved and the reference and // service don't match - List eprIntents = new ArrayList(); - eprIntents.addAll(endpointReference.getRequiredIntents()); + + // TODO - seems that we should do this loop on a binding by binding basis // rather than each time we do matching @@ -573,6 +574,13 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { } } + // Before we start examining intents, remove any whose constrained + // types don't include the binding type + removeConstrainedIntents(endpointReference, bindingType); + + List eprIntents = new ArrayList(); + eprIntents.addAll(endpointReference.getRequiredIntents()); + // first check the binding type for (Intent intent : endpointReference.getRequiredIntents()){ if (bindingType != null && @@ -703,7 +711,33 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { return match; } - protected boolean isQualifiedBy(Intent qualifiableIntent, Intent qualifiedIntent){ + // Copied from ComponentPolicyBuilder, should probably be refactored + protected void removeConstrainedIntents(EndpointReference subject, BindingType bindingType) { + List intents = subject.getRequiredIntents(); + + // Remove the intents whose @contrains do not include the current element + if(bindingType != null){ + List copy = new ArrayList(intents); + for (Intent i : copy) { + if (i.getConstrainedTypes().size() > 0){ + boolean constraintFound = false; + for (ExtensionType constrainedType : i.getConstrainedTypes()){ + if (constrainedType.getType().equals(bindingType.getType()) || + constrainedType.getType().equals(bindingType.getBaseType())){ + constraintFound = true; + break; + } + } + if(!constraintFound){ + intents.remove(i); + } + } + } + } + } + + + protected boolean isQualifiedBy(Intent qualifiableIntent, Intent qualifiedIntent){ if (qualifiedIntent.getQualifiableIntent() == qualifiableIntent){ return true; } else { -- cgit v1.2.3