Author: slaws
Date: Fri Jul  4 17:42:39 2008
New Revision: 674142

URL: http://svn.apache.org/viewvc?rev=674142&view=rev
Log:
TUSCANY-2352 - upgrade the fix for promoted binding overriding as the 
automatically created sca bindings were causing the top level to always 
override.

Added:
    
tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/AutomaticBinding.java
      - copied unchanged from r674139, 
tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/AutomaticBinding.java
Modified:
    
tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java
    
tuscany/branches/sca-java-1.3/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java

Modified: 
tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java?rev=674142&r1=674141&r2=674142&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java
 (original)
+++ 
tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java
 Fri Jul  4 17:42:39 2008
@@ -46,6 +46,7 @@
 import org.apache.tuscany.sca.assembly.SCABinding;
 import org.apache.tuscany.sca.assembly.SCABindingFactory;
 import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.builder.AutomaticBinding;
 import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
 import org.apache.tuscany.sca.definitions.SCADefinitions;
@@ -832,25 +833,35 @@
                 newComponentService.setService(promotedService.getService());
                 // set the bindings using the top level bindings to override 
the 
                 // lower level bindings
-                if (compositeService.getBindings().size() > 0){
+                if (bindingsSpecifiedManually(compositeService.getBindings())){
                     newComponentService.getBindings()
                         .addAll(compositeService.getBindings());
                 } else {
-                    newComponentService.getBindings()
-                    .addAll(promotedService.getBindings());
+                    for (Binding binding : promotedService.getBindings()){
+                        try {
+                            
newComponentService.getBindings().add((Binding)binding.clone());
+                        } catch(CloneNotSupportedException ex){
+                            // this binding can't be used in the promoted 
service
+                        }
+                    }                    
                 }
                 
newComponentService.setInterfaceContract(compositeService.getInterfaceContract());
                 if (compositeService.getInterfaceContract() != null && 
compositeService
                     .getInterfaceContract().getCallbackInterface() != null) {
                     
newComponentService.setCallback(assemblyFactory.createCallback());
                     if ((compositeService.getCallback() != null) &&
-                            
(compositeService.getCallback().getBindings().size() > 0)){
+                        
(bindingsSpecifiedManually(compositeService.getCallback().getBindings()))){
                         newComponentService.getCallback().getBindings()
                             
.addAll(compositeService.getCallback().getBindings());
                     } else if ((promotedService.getCallback() != null) &&
-                            
(promotedService.getCallback().getBindings().size() > 0)){
-                        newComponentService.getBindings()
-                            .addAll(promotedService.getBindings());
+                               
(bindingsSpecifiedManually(promotedService.getCallback().getBindings()))){
+                        for (Binding binding : 
promotedService.getCallback().getBindings()){
+                            try {
+                                
newComponentService.getCallback().getBindings().add((Binding)binding.clone());
+                            } catch(CloneNotSupportedException ex){
+                                // this binding can't be used in the promoted 
service
+                            }
+                        }                          
                     }
                 }
 
@@ -909,20 +920,28 @@
                             newComponentService.setName("$promoted$." + 
componentService.getName());
                             
promotedComponent.getServices().add(newComponentService);
                             
newComponentService.setService(promotedService.getService());
+                            
                             // set the bindings using the top level bindings 
to override the 
                             // lower level bindings
-                            if (componentService.getBindings().size() > 0){
+                            if 
(bindingsSpecifiedManually(componentService.getBindings())){
                                 newComponentService.getBindings()
                                     .addAll(componentService.getBindings());
-                            } else if (compositeService.getBindings().size() > 
0){
+                            } else if 
(bindingsSpecifiedManually(compositeService.getBindings())){
                                 newComponentService.getBindings()
                                     .addAll(compositeService.getBindings());
                             } else {
-                                newComponentService.getBindings()
-                                .addAll(promotedService.getBindings());
+                                for (Binding binding : 
promotedService.getBindings()){
+                                    try {
+                                        
newComponentService.getBindings().add((Binding)binding.clone());
+                                    } catch(CloneNotSupportedException ex){
+                                        // this binding can't be used in the 
promoted service
+                                    }
+                                }
                             }
+                            
                             
newComponentService.setInterfaceContract(componentService
                                 .getInterfaceContract());
+                            
                             if (componentService.getInterfaceContract() != 
null && 
                                 
componentService.getInterfaceContract().getCallbackInterface() != null) {
                                 
@@ -931,17 +950,22 @@
                                 // set the bindings using the top level 
bindings to override the 
                                 // lower level bindings
                                 if ((componentService.getCallback() != null) &&
-                                    
(componentService.getCallback().getBindings().size() > 0)){
+                                    
(bindingsSpecifiedManually(componentService.getCallback().getBindings()))){
                                     
newComponentService.getCallback().getBindings()
                                         
.addAll(componentService.getCallback().getBindings());
                                 } else if ((compositeService.getCallback() != 
null) &&
-                                           
(compositeService.getCallback().getBindings().size() > 0)){
+                                           
(bindingsSpecifiedManually(compositeService.getCallback().getBindings()))){
                                     
newComponentService.getCallback().getBindings()
                                         
.addAll(compositeService.getCallback().getBindings());
                                 } else if ((promotedService.getCallback() != 
null) &&
-                                           
(promotedService.getCallback().getBindings().size() > 0)){
-                                    newComponentService.getBindings()
-                                        .addAll(promotedService.getBindings());
+                                           
(bindingsSpecifiedManually(promotedService.getCallback().getBindings()))){
+                                    for (Binding binding : 
promotedService.getCallback().getBindings()){
+                                        try {
+                                            
newComponentService.getCallback().getBindings().add((Binding)binding.clone());
+                                        } catch(CloneNotSupportedException ex){
+                                            // this binding can't be used in 
the promoted service
+                                        }
+                                    }                                    
                                 }
                             }
 
@@ -957,6 +981,28 @@
     }
     
     /**
+     * If the bindings are specified in the composite file return true as they 
should 
+     * otherwise return false
+     *  
+     * @param bindings
+     * @return true if the bindings were specified manually
+     */
+    private boolean bindingsSpecifiedManually(List<Binding> bindings){
+
+        if (bindings.size() > 1){
+            return true;
+        } else if ((bindings.size() == 1) &&
+                   (bindings.get(0) instanceof AutomaticBinding) &&
+                   (((AutomaticBinding)bindings.get(0)).getIsAutomatic() == 
true )){
+            return false;
+        } else if (bindings.size() == 1) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+    
+    /**
      * @param composite
      */
     private void configureSourcedProperties(Composite composite, 
List<ComponentProperty> propertySettings) {
@@ -1028,6 +1074,12 @@
     private SCABinding createSCABinding() {
         SCABinding scaBinding = scaBindingFactory.createSCABinding();
         
+        // mark the bindings that are added automatically so that theu can 
+        // can be disregarded for overriding purposes
+        if (scaBinding instanceof AutomaticBinding){
+            ((AutomaticBinding)scaBinding).setIsAutomatic(true);
+        }
+        
         if ( policyDefinitions != null ) {
             for ( IntentAttachPointType attachPointType : 
policyDefinitions.getBindingTypes() ) {
                 if ( attachPointType.getName().equals(BINDING_SCA_QNAME)) {

Modified: 
tuscany/branches/sca-java-1.3/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java?rev=674142&r1=674141&r2=674142&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.3/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java
 (original)
+++ 
tuscany/branches/sca-java-1.3/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java
 Fri Jul  4 17:42:39 2008
@@ -27,6 +27,7 @@
 import org.apache.tuscany.sca.assembly.Extensible;
 import org.apache.tuscany.sca.assembly.OptimizableBinding;
 import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.builder.AutomaticBinding;
 import org.apache.tuscany.sca.policy.Intent;
 import org.apache.tuscany.sca.policy.IntentAttachPointType;
 import org.apache.tuscany.sca.policy.PolicySet;
@@ -37,7 +38,7 @@
  * 
  * @version $Rev$ $Date$
  */
-public class SCABindingImpl implements SCABinding, Extensible, 
PolicySetAttachPoint, OptimizableBinding {
+public class SCABindingImpl implements SCABinding, Extensible, 
PolicySetAttachPoint, OptimizableBinding, AutomaticBinding {
     private String name;
     private String uri;
     private List<Object> extensions = new ArrayList<Object>();
@@ -50,6 +51,8 @@
     private Binding targetBinding;
     private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
     
+    private boolean isAutomatic = false;
+    
     public List<PolicySet> getApplicablePolicySets() {
         return applicablePolicySets;
     }
@@ -208,4 +211,13 @@
     public void setRequiredIntents(List<Intent> intents) {
         this.requiredIntents = intents;
     }
+    
+
+    public void setIsAutomatic(boolean isAutomatic){
+        this.isAutomatic = isAutomatic;
+    }
+    
+    public boolean getIsAutomatic(){
+        return this.isAutomatic;
+    }
 }


Reply via email to