Author: slaws
Date: Thu Mar 11 15:42:08 2010
New Revision: 921903

URL: http://svn.apache.org/viewvc?rev=921903&view=rev
Log:
TUSCANY-3483 - ensure that policies defined in the implementation are applied 
correctly to the component service. This pointed out another problem in that if 
binding.sca was defined on the reference with no uri but with intents then the 
intents weren't being applied to the EPR because the binding was being ignored 
(as it's a targeted reference).

Modified:
    
tuscany/sca-java-2.x/trunk/itest/policies/src/main/resources/META-INF/definitions.xml
    
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentPolicyBuilderImpl.java
    
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java
    
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java
    
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/itest/policies/src/main/resources/META-INF/definitions.xml
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/policies/src/main/resources/META-INF/definitions.xml?rev=921903&r1=921902&r2=921903&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/itest/policies/src/main/resources/META-INF/definitions.xml
 (original)
+++ 
tuscany/sca-java-2.x/trunk/itest/policies/src/main/resources/META-INF/definitions.xml
 Thu Mar 11 15:42:08 2010
@@ -64,4 +64,8 @@
     <policySet name="ClientAuthenticationTransportPolicy" 
                provides="sca:clientAuthentication.transport" 
                appliesTo="//binding | //implementation"/>  
+               
+    <policySet name="IntegrityTransportPolicy" 
+               provides="sca:integrity.transport" 
+               appliesTo="//binding | //implementation"/>                
 </definitions>
\ No newline at end of file

Modified: 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentPolicyBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentPolicyBuilderImpl.java?rev=921903&r1=921902&r2=921903&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentPolicyBuilderImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentPolicyBuilderImpl.java
 Thu Mar 11 15:42:08 2010
@@ -89,21 +89,33 @@ public class ComponentPolicyBuilderImpl 
         Monitor.error(monitor, this, Messages.ASSEMBLY_VALIDATION, message, 
messageParameters);
     }
 
+
     /**
      * Inherit the intents and policySets from the list of models
-     * @param ignoreExclusiveIntents TODO
-     * @param models
-     * @param intents
-     * @param policySets
+     * 
+     * @param policySubject - the subject to which intents will be added
+     * @param intentType - choose to copy interaction or implementation 
intents. Null = both
+     * @param ignoreExclusiveIntents - when set true mutually exclusive 
intents won't be copied
+     * @param models - the subjects from which intents will be copied
      */
-    protected void inherit(PolicySubject policySubject, boolean 
ignoreExclusiveIntents, Object... models) {
+    protected void inherit(PolicySubject policySubject, Intent.Type 
intentType, boolean ignoreExclusiveIntents, Object... models) {
         for (Object model : models) {
             if (model instanceof PolicySubject) {
                 PolicySubject subject = (PolicySubject)model;
 
                 if (!ignoreExclusiveIntents) {
                     // The intents are merged and the exclusion check will be 
done after
-                    
policySubject.getRequiredIntents().addAll(subject.getRequiredIntents());
+                    for (Intent intent : subject.getRequiredIntents()) {
+                        if 
(!policySubject.getRequiredIntents().contains(intent)){
+                            if (intentType != null) {
+                                if (intent.getType().equals(intentType)){
+                                    
policySubject.getRequiredIntents().add(intent);
+                                }
+                            } else {
+                                policySubject.getRequiredIntents().add(intent);
+                            }
+                        }
+                    }
                 } else {
                     Set<Intent> intents = new HashSet<Intent>();
                     for (Intent i1 : subject.getRequiredIntents()) {
@@ -115,7 +127,15 @@ public class ComponentPolicyBuilderImpl 
                             }
                         }
                         if (!exclusive) {
-                            intents.add(i1);
+                            if (!intents.contains(i1)){
+                                if (intentType != null) {
+                                    if (i1.getType().equals(intentType)){
+                                        intents.add(i1);
+                                    }
+                                } else {
+                                    intents.add(i1);
+                                }
+                            }
                         }
                     }
                     policySubject.getRequiredIntents().addAll(intents);
@@ -130,21 +150,21 @@ public class ComponentPolicyBuilderImpl 
         }
     }
 
-    protected void configure(PolicySubject subject1, PolicySubject subject2, 
BuilderContext context) {
+    protected void configure(PolicySubject subject1, PolicySubject subject2, 
Intent.Type intentType, BuilderContext context) {
         if (subject1 != null) {
             resolveAndCheck(subject1, context);
         }
         if (subject2 != null) {
             resolveAndCheck(subject2, context);
         }
-        inherit(subject1, false, subject2);
+        inherit(subject1, intentType, false, subject2);
         checkMutualExclusion(subject1, context);
     }
 
     protected void configure(ComponentService componentService, BuilderContext 
context) {
         Service service = componentService.getService();
         if (service != null) {
-            configure(componentService, service, context);
+            configure(componentService, service, null, context);
             configureBindings(componentService, service, context);
         }
     }
@@ -160,7 +180,7 @@ public class ComponentPolicyBuilderImpl 
         for (Binding binding : componentContract.getBindings()) {
             Binding componentTypeBinding = 
componentTypeContractBindings.get(binding.getName());
             if (binding instanceof PolicySubject) {
-                inherit((PolicySubject)binding, false, componentTypeBinding, 
context);
+                inherit((PolicySubject)binding, null, false, 
componentTypeBinding, context);
             }
         }
     }
@@ -168,35 +188,64 @@ public class ComponentPolicyBuilderImpl 
     protected void configure(ComponentReference componentReference, 
BuilderContext context) {
         Reference reference = componentReference.getReference();
         if (reference != null) {
-            configure(componentReference, reference, context);
+            configure(componentReference, reference, null, context);
             configureBindings(componentReference, reference, context);
         }
     }
 
     protected void configure(CompositeService compositeService, BuilderContext 
context) {
-        configure(compositeService, compositeService.getPromotedService(), 
context);
+        configure(compositeService, compositeService.getPromotedService(), 
null, context);
     }
 
     protected void configure(CompositeReference compositeReference, 
BuilderContext context) {
         for (ComponentReference reference : 
compositeReference.getPromotedReferences()) {
-            configure(compositeReference, reference, context);
+            configure(compositeReference, reference, null, context);
         }
     }
 
     public void configure(Component component, BuilderContext context) {
-        // Inherit the intents and policySets from the componentType
-        configure(component, component.getImplementation(), context);
+        // fix up the component type by copying all implementation level
+        // interaction intents to *all* the component type services
+        for (ComponentService componentService : component.getServices()) {
+            configure(componentService, component.getImplementation(), 
Intent.Type.interaction, context);
+        }
+        
         // Inherit the intents and policySets from the componentType
         for (ComponentReference componentReference : 
component.getReferences()) {
             configure(componentReference, context);
         }
+        
         for (ComponentService componentService : component.getServices()) {
             configure(componentService, context);
         }
     }
+    
+    protected boolean checkQualifiedMutualExclusion(List<Intent> 
excludedIntentList, Intent intent){
+        for (Intent excludedIntent : excludedIntentList){
+            if (intent.getQualifiableIntent() != null &&
+                excludedIntent != null && 
+                intent.getQualifiableIntent().equals(excludedIntent)){
+                return true;
+            }
+        }
+        return false;
+    }    
+    
+    protected boolean checkMutualExclusion(Intent i1, Intent i2, 
BuilderContext context){
+        if ((i1 != i2) && 
+            (i1.getExcludedIntents().contains(i2) || 
+             i2.getExcludedIntents().contains(i1) ||
+             checkQualifiedMutualExclusion(i1.getExcludedIntents(), i2) ||
+             checkQualifiedMutualExclusion(i2.getExcludedIntents(), i1))) {
+            error(context.getMonitor(), "MutuallyExclusiveIntents", this, i1, 
i2);
+            return true;
+        }
+        
+        return false;
+    }
 
     /**
-     * Check if a single policy subject requires multually exclusive intents
+     * Check if a single policy subject requires mutually exclusive intents
      * @param subject1 - the policy subject to check
      * @param context - context containing useful things like the monitor 
instance
      * @return true if the policy subject contains mutually exclusive intents
@@ -207,17 +256,26 @@ public class ComponentPolicyBuilderImpl 
         }
         for (Intent i1 : subject1.getRequiredIntents()) {
             for (Intent i2 : subject1.getRequiredIntents()) {
-                if ((i1 != i2) && (i1.getExcludedIntents().contains(i2) || 
i2.getExcludedIntents().contains(i1))) {
+                if (checkMutualExclusion(i1, i2, context)){
+                    return true;
+                }
+/*                
+                if ((i1 != i2) && 
+                    (i1.getExcludedIntents().contains(i2) || 
+                     i2.getExcludedIntents().contains(i1) ||
+                     matchQualifiedMutualExclusion(i1.getExcludedIntents(), 
i2) ||
+                     matchQualifiedMutualExclusion(i2.getExcludedIntents(), 
i1))) {
                     error(context.getMonitor(), "MutuallyExclusiveIntents", 
new Object[] {subject1}, i1, i2);
                     return true;
                 }
+*/                
             }
         }
         return false;
     }
 
     /**
-     * Check if two policy subjects requires multually exclusive intents
+     * Check if two policy subjects requires mutually exclusive intents
      * @param subject1
      * @param subject2
      * @param monitor 
@@ -229,10 +287,18 @@ public class ComponentPolicyBuilderImpl 
         }
         for (Intent i1 : subject1.getRequiredIntents()) {
             for (Intent i2 : subject2.getRequiredIntents()) {
-                if (i1.getExcludedIntents().contains(i2) || 
i2.getExcludedIntents().contains(i1)) {
+                if (checkMutualExclusion(i1, i2, context)){
+                    return true;
+                }
+/*                
+                if (i1.getExcludedIntents().contains(i2) || 
+                    i2.getExcludedIntents().contains(i1) ||
+                    matchQualifiedMutualExclusion(i1.getExcludedIntents(), i2) 
||
+                    matchQualifiedMutualExclusion(i2.getExcludedIntents(), 
i1)) {
                     error(context.getMonitor(), "MutuallyExclusiveIntents", 
new Object[] {subject1, subject2}, i1, i2);
                     return true;
                 }
+*/                
             }
         }
         return false;
@@ -250,10 +316,15 @@ public class ComponentPolicyBuilderImpl 
             for (int j = i + 1; j < size; j++) {
                 Intent i1 = intents.get(i);
                 Intent i2 = intents.get(j);
+                if (checkMutualExclusion(i1, i2, context)){
+                    return true;
+                }
+/*                
                 if (i1 != i2 && i1.getExcludedIntents().contains(i2) || 
i2.getExcludedIntents().contains(i1)) {
                     error(context.getMonitor(), "MutuallyExclusiveIntents", 
subject, i1, i2);
                     return true;
                 }
+*/                
             }
         }
         return false;

Modified: 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java?rev=921903&r1=921902&r2=921903&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java
 Thu Mar 11 15:42:08 2010
@@ -77,7 +77,7 @@ public class CompositePolicyBuilderImpl 
                 
                 try {
                     Implementation implementation = 
component.getImplementation();
-
+                    
                     for (ComponentService componentService : 
component.getServices()) {
                         monitor.pushContext("Service: " + 
componentService.getName());
 
@@ -94,12 +94,14 @@ public class CompositePolicyBuilderImpl 
                             for (Endpoint ep : 
componentService.getEndpoints()) {
                                 if (componentService.getInterfaceContract() != 
null) {
                                     // Inherit from the 
component.service.interface
-                                    inherit(ep, true, 
componentService.getInterfaceContract().getInterface());
+                                    inherit(ep, null, true, 
componentService.getInterfaceContract().getInterface());
                                 }
+                                
                                 // Inherit from composite/component/service
-                                inherit(ep, true, composite, 
ep.getComponent(), ep.getService());
+                                inherit(ep, null, true, composite, 
ep.getComponent(), ep.getService());
+                                
                                 // Inherit from binding
-                                inherit(ep, true, ep.getBinding());
+                                inherit(ep, null, true, ep.getBinding());
 
                                 // Replace profile intents with their required 
intents
                                 // Remove the intents whose @contraints do not 
include the current element
@@ -131,12 +133,14 @@ public class CompositePolicyBuilderImpl 
 
                                 // Inherit from the 
component.reference.interface
                                 if (componentReference.getInterfaceContract() 
!= null) {
-                                    inherit(epr, true, 
componentReference.getInterfaceContract().getInterface());
+                                    inherit(epr, null, true, 
componentReference.getInterfaceContract().getInterface());
                                 }
 
-                                // Inherit from 
composite/component/reference/binding
-                                inherit(epr, true, composite, 
epr.getComponent(), epr.getReference());
-                                inherit(epr, true, epr.getBinding());
+                                // Inherit from composite/component/reference
+                                inherit(epr, null, true, composite, 
epr.getComponent(), epr.getReference());
+                                
+                                // Inherit from binding
+                                inherit(epr, null, true, epr.getBinding());
 
                                 // Replace profile intents with their required 
intents
                                 // Remove the intents whose @contraints do not 
include the current element
@@ -153,12 +157,12 @@ public class CompositePolicyBuilderImpl 
                     }
 
                     if (implementation instanceof Composite) {
-                        inherit(implementation, true, component, composite);
+                        inherit(implementation, null, true, component, 
composite);
                         computePolicies((Composite)implementation, context);
                     } else {
                         resolveAndCheck(implementation, context);
                         if (implementation != null) {
-                            inherit(implementation, true, component, 
composite);
+                            inherit(implementation, null, true, component, 
composite);
                         }
                     }
                 } finally {

Modified: 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java?rev=921903&r1=921902&r2=921903&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java
 Thu Mar 11 15:42:08 2010
@@ -271,6 +271,18 @@ public class EndpointReferenceBuilderImp
                     endpointRef.setTargetEndpoint(createEndpoint(component, 
target.getName()));
                     
endpointRef.setStatus(EndpointReference.Status.WIRED_TARGET_NOT_FOUND);
                     reference.getEndpointReferences().add(endpointRef);
+                    
+                    // There is a special case where the user has defined 
policies on a 
+                    // non-targetted, i.e. no URI, binding.sca in order to 
control the 
+                    // intended QoS of the wire when matching takes place. If 
any other 
+                    // bindings are specified then the test later on will 
complain about
+                    // mixing targts with bindings
+                    if (reference.getBindings().size() == 1){
+                        Binding binding = reference.getBindings().get(0);
+                        if ((binding instanceof SCABinding) && 
(binding.getURI() == null)){
+                            endpointRef.setBinding(binding);
+                        }
+                    }
                 }
             } 
     

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=921903&r1=921902&r2=921903&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
 Thu Mar 11 15:42:08 2010
@@ -408,7 +408,9 @@ public class EndpointReferenceBinderImpl
         for (Intent eprIntent : endpointReference.getRequiredIntents()){
             for (Intent epIntent : endpoint.getRequiredIntents()){ 
                 if (eprIntent.getExcludedIntents().contains(epIntent) ||
-                    epIntent.getExcludedIntents().contains(eprIntent)){
+                    epIntent.getExcludedIntents().contains(eprIntent) ||
+                    
checkQualifiedMutualExclusion(eprIntent.getExcludedIntents(), epIntent) ||
+                    
checkQualifiedMutualExclusion(epIntent.getExcludedIntents(), eprIntent)){
                     matchAudit.append("No match because the following intents 
are mutually exclusive " + 
                                       eprIntent.toString() +
                                       " " +
@@ -622,7 +624,18 @@ public class EndpointReferenceBinderImpl
         } else {
             return false;
         }
-    }    
+    }
+    
+    protected boolean checkQualifiedMutualExclusion(List<Intent> 
excludedIntentList, Intent intent){
+        for (Intent excludedIntent : excludedIntentList){
+            if (intent.getQualifiableIntent() != null &&
+                excludedIntent != null &&
+                intent.getQualifiableIntent().equals(excludedIntent)){
+                return true;
+            }
+        }
+        return false;
+    }      
     
     /**
      * Determine if endpoint reference and endpoint interface contracts match 


Reply via email to