You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by bd...@apache.org on 2010/07/23 08:13:26 UTC

svn commit: r966983 - /tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java

Author: bdaniel
Date: Fri Jul 23 06:13:25 2010
New Revision: 966983

URL: http://svn.apache.org/viewvc?rev=966983&view=rev
Log:
Remove constrained intents from endpoint references at runtime binding time

Modified:
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java

Modified: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java?rev=966983&r1=966982&r2=966983&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java Fri Jul 23 06:13:25 2010
@@ -49,6 +49,7 @@ import org.apache.tuscany.sca.interfaced
 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
         // this they must be satisfied by reference policy sets
         // Failing this the intent is unresolved and the reference and 
         // service don't match
-        List<Intent> eprIntents = new ArrayList<Intent>();
-        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
             }
         }
         
+        // Before we start examining intents, remove any whose constrained
+        // types don't include the binding type
+        removeConstrainedIntents(endpointReference, bindingType);
+        
+        List<Intent> eprIntents = new ArrayList<Intent>();
+        eprIntents.addAll(endpointReference.getRequiredIntents());
+        
         // first check the binding type
         for (Intent intent : endpointReference.getRequiredIntents()){ 
             if (bindingType != null && 
@@ -703,7 +711,33 @@ public class EndpointReferenceBinderImpl
         return match;
     }
     
-    protected boolean isQualifiedBy(Intent qualifiableIntent, Intent qualifiedIntent){
+    // Copied from ComponentPolicyBuilder, should probably be refactored
+    protected void removeConstrainedIntents(EndpointReference subject, BindingType bindingType) {
+        List<Intent> intents = subject.getRequiredIntents();
+        
+        // Remove the intents whose @contrains do not include the current element       
+        if(bindingType != null){
+            List<Intent> copy = new ArrayList<Intent>(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 {