You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by na...@apache.org on 2008/07/21 19:38:02 UTC

svn commit: r678491 [3/4] - in /tuscany/branches/sca-java-1.3: itest/ itest/builder/ itest/builder/src/ itest/builder/src/main/ itest/builder/src/main/java/ itest/builder/src/main/java/org/ itest/builder/src/main/java/org/apache/ itest/builder/src/main...

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=678491&r1=678490&r2=678491&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 Mon Jul 21 10:37:59 2008
@@ -38,6 +38,7 @@
 import org.apache.tuscany.sca.assembly.ComponentService;
 import org.apache.tuscany.sca.assembly.Composite;
 import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Contract;
 import org.apache.tuscany.sca.assembly.Implementation;
 import org.apache.tuscany.sca.assembly.Multiplicity;
 import org.apache.tuscany.sca.assembly.OptimizableBinding;
@@ -95,7 +96,7 @@
     protected void configureComponents(Composite composite) throws CompositeBuilderException {
         configureComponents(composite, null);
         configureSourcedProperties(composite, null);
-        configureBindingURIs(composite, null, null);
+        //configureBindingURIs(composite, null, null);
     }
 
     /**
@@ -138,7 +139,7 @@
                 SCABinding scaBinding = createSCABinding();
                 service.getBindings().add(scaBinding);
             }
-
+/*
             // Initialize binding names and URIs
             for (Binding binding : service.getBindings()) {
                 
@@ -155,6 +156,7 @@
                     }
                 }
             }
+*/
         }
 
         // Initialize reference bindings
@@ -164,7 +166,7 @@
                 SCABinding scaBinding = createSCABinding();
                 reference.getBindings().add(scaBinding);
             }
-
+/*
             // Set binding names
             for (Binding binding : reference.getBindings()) {
                 if (binding.getName() == null) {
@@ -179,6 +181,7 @@
                     }
                 }
             }
+*/
         }
 
         // Initialize all component services and references
@@ -252,7 +255,7 @@
                     SCABinding scaBinding = createSCABinding();
                     componentService.getBindings().add(scaBinding);
                 }
-
+/*
                 // Set binding names
                 for (Binding binding : componentService.getBindings()) {
                     
@@ -268,6 +271,7 @@
                         }
                     }
                 }
+*/
             }
 
             // Initialize reference bindings
@@ -278,7 +282,7 @@
                     SCABinding scaBinding = createSCABinding();
                     componentReference.getBindings().add(scaBinding);
                 }
-
+/*
                 // Set binding names
                 for (Binding binding : componentReference.getBindings()) {
                     if (binding.getName() == null) {
@@ -292,6 +296,7 @@
                         }
                     }
                 }
+*/
             }
         }
     }
@@ -801,208 +806,6 @@
     }
 
     /**
-     * Activate composite services in nested composites.
-     * 
-     * @param composite
-     * @param problems
-     */
-    protected void configureCompositeServices(Composite composite) {
-
-        // Process nested composites recursively
-        configureNestedCompositeServices(composite);
-
-        // Process top level composite services
-        for (Service service : composite.getServices()) {
-            CompositeService compositeService = (CompositeService)service;
-
-            // Get the inner most promoted service
-            ComponentService promotedService = ServiceConfigurationUtil.getPromotedComponentService(compositeService);
-            if (promotedService != null) {
-                Component promotedComponent = getPromotedComponent(compositeService);
-
-                // Default to use the interface from the promoted service
-                if (compositeService.getInterfaceContract() == null && promotedService.getInterfaceContract() != null) {
-                    compositeService.setInterfaceContract(promotedService.getInterfaceContract());
-                }
-
-                // Create a new component service to represent this composite
-                // service on the promoted component
-                ComponentService newComponentService = assemblyFactory.createComponentService();
-                newComponentService.setName("$promoted$." + compositeService.getName());
-                promotedComponent.getServices().add(newComponentService);
-                newComponentService.setService(promotedService.getService());
-                // set the bindings using the top level bindings to override the 
-                // lower level bindings
-                if (bindingsSpecifiedManually(compositeService.getBindings())){
-                    newComponentService.getBindings()
-                        .addAll(compositeService.getBindings());
-                } else {
-                    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) &&
-                        (bindingsSpecifiedManually(compositeService.getCallback().getBindings()))){
-                        newComponentService.getCallback().getBindings()
-                            .addAll(compositeService.getCallback().getBindings());
-                    } else if ((promotedService.getCallback() != null) &&
-                               (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
-                            }
-                        }                          
-                    }
-                }
-
-                // Change the composite service to now promote the newly
-                // created component service directly
-                compositeService.setPromotedComponent(promotedComponent);
-                compositeService.setPromotedService(newComponentService);
-            }
-        }
-    }
-
-    /**
-     * Activate composite services in nested composites.
-     * 
-     * @param composite
-     * @param problems
-     */
-    private void configureNestedCompositeServices(Composite composite) {
-
-        // Process nested composites recursively
-        for (Component component : composite.getComponents()) {
-            Implementation implementation = component.getImplementation();
-            if (implementation instanceof Composite) {
-
-                // First process nested composites
-                configureNestedCompositeServices((Composite)implementation);
-
-                // Process the component services declared on components
-                // in this composite
-                for (ComponentService componentService : component.getServices()) {
-                    Service implService = componentService.getService();
-                    if (implService != null && implService instanceof CompositeService) {
-                        CompositeService compositeService = (CompositeService)implService;
-
-                        // Get the inner most promoted service
-                        ComponentService promotedService =
-                            ServiceConfigurationUtil.getPromotedComponentService(compositeService);
-                        if (promotedService != null) {
-                            Component promotedComponent = getPromotedComponent(compositeService);
-
-                            // Default to use the interface from the promoted
-                            // service
-                            if (compositeService.getInterfaceContract() == null) {
-                                compositeService.setInterfaceContract(promotedService
-                                    .getInterfaceContract());
-                            }
-                            if (componentService.getInterfaceContract() == null) {
-                                componentService.setInterfaceContract(promotedService
-                                    .getInterfaceContract());
-                            }
-
-                            // Create a new component service to represent this
-                            // composite service on the promoted component
-                            ComponentService newComponentService =
-                                assemblyFactory.createComponentService();
-                            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 (bindingsSpecifiedManually(componentService.getBindings())){
-                                newComponentService.getBindings()
-                                    .addAll(componentService.getBindings());
-                            } else if (bindingsSpecifiedManually(compositeService.getBindings())){
-                                newComponentService.getBindings()
-                                    .addAll(compositeService.getBindings());
-                            } else {
-                                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) {
-                                
-                                newComponentService.setCallback(assemblyFactory.createCallback());
-                                
-                                // set the bindings using the top level bindings to override the 
-                                // lower level bindings
-                                if ((componentService.getCallback() != null) &&
-                                    (bindingsSpecifiedManually(componentService.getCallback().getBindings()))){
-                                    newComponentService.getCallback().getBindings()
-                                        .addAll(componentService.getCallback().getBindings());
-                                } else if ((compositeService.getCallback() != null) &&
-                                           (bindingsSpecifiedManually(compositeService.getCallback().getBindings()))){
-                                    newComponentService.getCallback().getBindings()
-                                        .addAll(compositeService.getCallback().getBindings());
-                                } else if ((promotedService.getCallback() != null) &&
-                                           (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
-                                        }
-                                    }                                    
-                                }
-                            }
-
-                            // Change the composite service to now promote the
-                            // newly created component service directly
-                            compositeService.setPromotedComponent(promotedComponent);
-                            compositeService.setPromotedService(newComponentService);
-                        }
-                    }
-                }
-            }
-        }
-    }
-    
-    /**
-     * 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) {
@@ -1032,34 +835,6 @@
         }
     }
 
-    /**
-     * Follow a service promotion chain down to the inner most (non composite)
-     * component.
-     * 
-     * @param compositeService
-     * @return
-     */
-    protected static Component getPromotedComponent(CompositeService compositeService) {
-        ComponentService componentService = compositeService.getPromotedService();
-        if (componentService != null) {
-            Service service = componentService.getService();
-            if (componentService.getName() != null && service instanceof CompositeService) {
-
-                // Continue to follow the service promotion chain
-                return getPromotedComponent((CompositeService)service);
-
-            } else {
-
-                // Found a non-composite service
-                return compositeService.getPromotedComponent();
-            }
-        } else {
-
-            // No promoted service
-            return null;
-        }
-    }
-
     private ComponentProperty getComponentPropertyByName(String propertyName, List<ComponentProperty> properties) {
         if (properties != null) {
             for (ComponentProperty aProperty : properties) {
@@ -1074,8 +849,8 @@
     private SCABinding createSCABinding() {
         SCABinding scaBinding = scaBindingFactory.createSCABinding();
         
-        // mark the bindings that are added automatically so that theu can 
-        // can be disregarded for overriding purposes
+        // mark the bindings that are added automatically so that they can 
+        // be disregarded for overriding purposes
         if (scaBinding instanceof AutomaticBinding){
             ((AutomaticBinding)scaBinding).setIsAutomatic(true);
         }
@@ -1092,6 +867,16 @@
     }
 
     /**
+     * Called by CompositeBindingURIBuilderImpl
+     *  
+     * @param composite the composite to be configured
+     */
+    protected void configureBindingURIsAndNames(Composite composite) throws CompositeBuilderException {
+        configureBindingURIs(composite, null, null);
+        configureBindingNames(composite);
+    }
+
+    /**
      * Fully resolve the binding URIs based on available information. This includes information
      * from the ".composite" files, from resources associated with the binding, e.g. WSDL files, 
      * from any associated policies and from the default information for each binding type.
@@ -1108,7 +893,13 @@
       * from the ".composite" files, from resources associated with the binding, e.g. WSDL files, 
       * from any associated policies and from the default information for each binding type.
       * 
-      * TODO: Share the  URL calculation algorithm with the configureComponents() method above
+      * NOTE: This method repeats some of the processing performed by the configureComponents()
+      *       method above.  The duplication is needed because NodeConfigurationServiceImpl
+      *       calls this method without previously calling configureComponents().  In the
+      *       normal builder sequence used by CompositeBuilderImpl, both of these methods
+      *       are called.
+      *
+      * TODO: Share the URL calculation algorithm with the configureComponents() method above
       *       although keeping the configureComponents() methods signature as is because when
       *       a composite is actually build in a node the node default information is currently
       *       available
@@ -1209,23 +1000,96 @@
             } 
         }
     }
+
+    /**
+     * Add default names for callback bindings and reference bindings.  Needs to be
+     * separate from configureBindingURIs() because configureBindingURIs() is called
+     * by NodeConfigurationServiceImpl as well as by CompositeBuilderImpl.
+     */
+    private void configureBindingNames(Composite composite) {
+        
+        // Process nested composites recursively
+        for (Component component : composite.getComponents()) {
+
+            Implementation implementation = component.getImplementation();
+            if (implementation instanceof Composite) {
+
+                // Process nested composite
+                configureBindingNames((Composite)implementation);
+            }
+        }  
+        
+        // Initialize composite service callback binding names
+        for (Service service : composite.getServices()) {
+
+            if (service.getCallback() != null) {
+                for (Binding binding : service.getCallback().getBindings()) {
+                    constructBindingName(service, binding);
+                }
+            }
+        }
+        
+        // Initialize composite reference binding names
+        for (Reference reference : composite.getReferences()) {
+
+            for (Binding binding : reference.getBindings()) {  
+                constructBindingName(reference, binding);
+            }
+
+            if (reference.getCallback() != null) {
+                for (Binding binding : reference.getCallback().getBindings()) {
+                    constructBindingName(reference, binding);
+                }
+            }
+        }
+        
+        // Initialize component service and reference binding names
+        for (Component component : composite.getComponents()) {
+
+            // Initialize component service callback binding names
+            for (ComponentService service : component.getServices()) {
+
+                if (service.getCallback() != null) {
+                    for (Binding binding : service.getCallback().getBindings()) {
+                        constructBindingName(service, binding);
+                    }
+                }
+            } 
+        
+            // Initialize component reference binding names
+            for (ComponentReference reference : component.getReferences()) {
+
+                // Initialize binding names
+                for (Binding binding : reference.getBindings()) {  
+                    constructBindingName(reference, binding);
+                }
+
+                if (reference.getCallback() != null) {
+                    for (Binding binding : reference.getCallback().getBindings()) {
+                        constructBindingName(reference, binding);
+                    }
+                }
+            }
+        }
+    }
     
     /**
-     * If a binding name is not provided by the user construct it based on the service name
+     * If a binding name is not provided by the user, construct it based on the service
+     * or reference name
      * 
-     * @param service
+     * @param contract the service or reference
      * @param binding
      */
-    private void constructBindingName(Service service, Binding binding) throws CompositeBuilderException{
+    private void constructBindingName(Contract contract, Binding binding) {
         
         // set the default binding name if one is required        
-        // if there is no name on the binding then set it to the service name 
+        // if there is no name on the binding then set it to the service or reference name 
         if (binding.getName() == null){
-            binding.setName(service.getName());
+            binding.setName(contract.getName());
         }
             
         // Check that multiple bindings do not have the same name
-        for (Binding otherBinding : service.getBindings()) {
+        for (Binding otherBinding : contract.getBindings()) {
             if (otherBinding == binding) {
                 // Skip the current binding
                 continue;
@@ -1235,7 +1099,8 @@
                 continue;
             }
             if (binding.getName().equals(otherBinding.getName())) {
-                warning("MultipleBindingsForService", binding, service.getName(), binding.getName());
+                warning(contract instanceof Service ? "MultipleBindingsForService" : "MultipleBindingsForReference",
+                        binding, contract.getName(), binding.getName());
             }
         }
     }

Modified: tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.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/BaseWireBuilderImpl.java?rev=678491&r1=678490&r2=678491&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java (original)
+++ tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java Mon Jul 21 10:37:59 2008
@@ -939,218 +939,6 @@
         // Clear the list of wires
         composite.getWires().clear();
     }
-
-    /**
-     * Wire composite references in nested composites.
-     * 
-     * @param composite
-     * @param problems
-     */
-    protected void wireCompositeReferences(Composite composite) {
-    
-        // Process nested composites recursively
-        for (Component component : composite.getComponents()) {
-            Implementation implementation = component.getImplementation();
-            if (implementation instanceof Composite) {
-                wireCompositeReferences((Composite)implementation);
-            }
-        }
-    
-        // Process composite references declared in this composite
-        for (Reference reference : composite.getReferences()) {
-            CompositeReference compositeReference = (CompositeReference)reference;
-            List<ComponentReference> promotedReferences = getPromotedComponentReferences(compositeReference);
-            for (ComponentReference promotedReference : promotedReferences) {
-    
-                reconcileReferenceBindings(compositeReference, promotedReference);
-                if (compositeReference.getInterfaceContract() != null && // can be null in unit tests
-                compositeReference.getInterfaceContract().getCallbackInterface() != null) {
-                    SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class);
-                    if (promotedReference.getCallback() != null) {
-                        promotedReference.getCallback().getBindings().clear();
-                    } else {
-                        promotedReference.setCallback(assemblyFactory.createCallback());
-                    }
-                    if (scaCallbackBinding != null) {
-                        promotedReference.getCallback().getBindings().add(scaCallbackBinding);
-                    }
-                    if (compositeReference.getCallback() != null) {
-                        promotedReference.getCallback().getBindings().addAll(compositeReference.getCallback()
-                            .getBindings());
-                    }
-                }
-            }
-        }
-    
-        // Process the component references declared on components
-        // in this composite
-        for (Component component : composite.getComponents()) {
-            Implementation implementation = component.getImplementation();
-            if (implementation instanceof Composite) {
-                for (ComponentReference componentReference : component.getReferences()) {
-                    Reference implReference = componentReference.getReference();
-                    if (implReference != null && implReference instanceof CompositeReference) {
-                        CompositeReference compositeReference = (CompositeReference)implReference;
-                        List<ComponentReference> promotedReferences =
-                            getPromotedComponentReferences(compositeReference);
-                        for (ComponentReference promotedReference : promotedReferences) {
-    
-                            // Override the configuration of the promoted reference
-                            reconcileReferenceBindings(componentReference, promotedReference);
-                            if (componentReference.getInterfaceContract() != null && // can be null in unit tests
-                            componentReference.getInterfaceContract().getCallbackInterface() != null) {
-                                SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class);
-                                if (promotedReference.getCallback() != null) {
-                                    promotedReference.getCallback().getBindings().clear();
-                                } else {
-                                    promotedReference.setCallback(assemblyFactory.createCallback());
-                                }
-                                if (scaCallbackBinding != null) {
-                                    promotedReference.getCallback().getBindings().add(scaCallbackBinding);
-                                }
-                                if (componentReference.getCallback() != null) {
-                                    promotedReference.getCallback().getBindings().addAll(componentReference
-                                        .getCallback().getBindings());
-                                }
-                            }
-    
-                            // Wire the promoted reference to the actual
-                            // non-composite component services
-                            if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE || promotedReference
-                                .getMultiplicity() == Multiplicity.ONE_ONE) {
-                                // promotedReference.getTargets().clear();
-                            }
-                            for (ComponentService target : componentReference.getTargets()) {
-                                if (target.getService() instanceof CompositeService) {
-    
-                                    // Wire to the actual component service
-                                    // promoted by a composite service
-                                    CompositeService compositeService = (CompositeService)target.getService();
-                                    // Find the promoted component service
-                                    ComponentService componentService = ServiceConfigurationUtil.getPromotedComponentService(compositeService);
-                                    if (componentService != null) {
-                                        promotedReference.getTargets().add(componentService);
-                                    }
-                                } else {
-    
-                                    // Wire to a non-composite target service
-                                    promotedReference.getTargets().add(target);
-                                }
-                            }
-                        }
-                    }
-                }
-            } else {
-                for (ComponentReference componentReference : component.getReferences()) {
-    
-                    // Wire the component reference to the actual
-                    // non-composite component services
-                    List<ComponentService> targets = componentReference.getTargets();
-                    for (int i = 0, n = targets.size(); i < n; i++) {
-                        ComponentService target = targets.get(i);
-                        if (target.getService() instanceof CompositeService) {
-    
-                            // Wire to the actual component service
-                            // promoted by a composite service
-                            CompositeService compositeService = (CompositeService)target.getService();
-                            ComponentService componentService = compositeService.getPromotedService();
-                            if (componentService != null) {
-                                targets.set(i, componentService);
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * Follow a reference promotion chain down to the inner most (non composite)
-     * component references.
-     * 
-     * @param compositeReference
-     * @return
-     */
-    private List<ComponentReference> getPromotedComponentReferences(CompositeReference compositeReference) {
-        List<ComponentReference> componentReferences = new ArrayList<ComponentReference>();
-        collectPromotedComponentReferences(compositeReference, componentReferences);
-        return componentReferences;
-    }
-
-    /**
-     * Follow a reference promotion chain down to the inner most (non composite)
-     * component references.
-     * 
-     * @param compositeReference
-     * @param componentReferences
-     * @return
-     */
-    private void collectPromotedComponentReferences(CompositeReference compositeReference,
-                                                    List<ComponentReference> componentReferences) {
-        for (ComponentReference componentReference : compositeReference.getPromotedReferences()) {
-            Reference reference = componentReference.getReference();
-            if (reference instanceof CompositeReference) {
-    
-                // Continue to follow the reference promotion chain
-                collectPromotedComponentReferences((CompositeReference)reference, componentReferences);
-    
-            } else if (reference != null) {
-    
-                // Found a non-composite reference
-                componentReferences.add(componentReference);
-            }
-        }
-    }
-
-    /**
-     * Override the bindings for a promoted reference from an outer component
-     * reference
-     * 
-     * @param reference
-     * @param promotedReference
-     */
-    private void reconcileReferenceBindings(Reference reference, ComponentReference promotedReference) {
-        List<Binding> bindings = new ArrayList<Binding>();
-        
-        // collect the top level bindings first
-        for (Binding binding : reference.getBindings()) {
-            if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) {
-                bindings.add(binding);
-            }
-        }
-        
-        // if there are not top level bindings to override the promoted bindings
-        // then collect the promoted bindings
-        if (bindings.size() == 0){
-            for (Binding binding : promotedReference.getBindings()) {
-                if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) {
-                    bindings.add(binding);
-                }
-            }
-        }
-        
-        promotedReference.getBindings().clear();
-        promotedReference.getBindings().addAll(bindings);
-        
-        if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE || promotedReference.getMultiplicity() == Multiplicity.ZERO_ONE) {
-            if (promotedReference.getBindings().size() > 1) {
-                warning("ComponentReferenceMoreWire", promotedReference, promotedReference.getName());                
-            }
-        }
-        Set<Binding> callbackBindings = new HashSet<Binding>();
-        if (promotedReference.getCallback() != null) {
-            callbackBindings.addAll(promotedReference.getCallback().getBindings());
-        }
-        if (reference.getCallback() != null) {
-            callbackBindings.addAll(reference.getCallback().getBindings());
-        }
-        promotedReference.setCallback(assemblyFactory.createCallback());
-        for (Binding binding : callbackBindings) {
-            if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) {
-                promotedReference.getCallback().getBindings().add(binding);
-            }
-        }
-    }
     
     private void addPoliciesFromPromotedService(CompositeService compositeService) {
         //inherit intents and policies from promoted service

Modified: tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.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/ComponentReferenceBindingBuilderImpl.java?rev=678491&r1=678490&r2=678491&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java (original)
+++ tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java Mon Jul 21 10:37:59 2008
@@ -48,16 +48,8 @@
     }
     
     private void buildReferenceBindings(Composite composite) {
-        
-        // build bindings recursively
-        for (Component component : composite.getComponents()) {
-            Implementation implementation = component.getImplementation();
-            if (implementation instanceof Composite) {
-                buildReferenceBindings((Composite)implementation);
-            }
-        }
     
-        // find all the component reference bindings     
+        // find all the component reference bindings (starting at top level)     
         for (Component component : composite.getComponents()) {
             for (ComponentReference componentReference : component.getReferences()) {
                 for (Binding binding : componentReference.getBindings()) {
@@ -67,6 +59,14 @@
                 }
             }
         }
+        
+        // build bindings recursively
+        for (Component component : composite.getComponents()) {
+            Implementation implementation = component.getImplementation();
+            if (implementation instanceof Composite) {
+                buildReferenceBindings((Composite)implementation);
+            }
+        }
     }
 
 }

Added: tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.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/ComponentReferencePromotionWireBuilderImpl.java?rev=678491&view=auto
==============================================================================
--- tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java (added)
+++ tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java Mon Jul 21 10:37:59 2008
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+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.CompositeService;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that handles the creation of promoted composite services.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentReferencePromotionWireBuilderImpl implements CompositeBuilder {
+    private AssemblyFactory assemblyFactory;
+    private Monitor monitor;
+
+    public ComponentReferencePromotionWireBuilderImpl(AssemblyFactory assemblyFactory, Monitor monitor) {
+        this.assemblyFactory = assemblyFactory;
+        this.monitor = monitor;
+    }
+
+    public void build(Composite composite) throws CompositeBuilderException {
+        wireCompositeReferences(composite);
+    }
+
+    /**
+     * Wire composite references in nested composites.
+     * 
+     * @param composite
+     * @param problems
+     */
+    private void wireCompositeReferences(Composite composite) {
+    
+        // Process nested composites recursively
+        for (Component component : composite.getComponents()) {
+            Implementation implementation = component.getImplementation();
+            if (implementation instanceof Composite) {
+                wireCompositeReferences((Composite)implementation);
+            }
+        }
+    
+        // Process component references declared on components in this composite
+        for (Component component : composite.getComponents()) {
+            Implementation implementation = component.getImplementation();
+            if (implementation instanceof Composite) {
+                for (ComponentReference componentReference : component.getReferences()) {
+                    Reference implReference = componentReference.getReference();
+                    if (implReference != null && implReference instanceof CompositeReference) {
+
+                        // If the component reference is wired, it is a promotion override
+                        if (!componentReference.getEndpoints().isEmpty()) {
+                            componentReference.setPromotionOverride(true);
+                        }
+     
+                        // If the component reference is a promotion override, override the
+                        // configuration of the promoted reference  
+                        if (componentReference.isPromotionOverride()) {
+                            CompositeReference compositeReference = (CompositeReference)implReference;
+                            List<ComponentReference> promotedReferences =
+                                ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference);
+                            for (ComponentReference promotedReference : promotedReferences) {
+                                ReferenceConfigurationUtil.reconcileReferenceBindings(
+                                        componentReference, promotedReference, assemblyFactory, monitor);
+                                if (componentReference.getInterfaceContract() != null && // can be null in unit tests
+                                    componentReference.getInterfaceContract().getCallbackInterface() != null) {
+                                    SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class);
+                                    if (promotedReference.getCallback() != null) {
+                                        promotedReference.getCallback().getBindings().clear();
+                                    } else {
+                                        promotedReference.setCallback(assemblyFactory.createCallback());
+                                    }
+                                    if (scaCallbackBinding != null) {
+                                        promotedReference.getCallback().getBindings().add(scaCallbackBinding);
+                                    }
+                                    if (componentReference.getCallback() != null) {
+                                        promotedReference.getCallback().getBindings().addAll(componentReference
+                                            .getCallback().getBindings());
+                                    }
+                                }
+    
+                                // Wire the promoted reference to the actual non-composite component services
+                                if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE) {
+                                    // promotedReference.getTargets().clear();
+                                }
+                                for (ComponentService target : componentReference.getTargets()) {
+                                    if (target.getService() instanceof CompositeService) {
+        
+                                        // Wire to the actual component service
+                                        // promoted by a composite service
+                                        CompositeService compositeService = (CompositeService)target.getService();
+                                        // Find the promoted component service
+                                        ComponentService componentService =
+                                            ServiceConfigurationUtil.getPromotedComponentService(compositeService);
+                                        if (componentService != null) {
+                                            promotedReference.getTargets().add(componentService);
+                                        }
+                                    } else {
+        
+                                        // Wire to a non-composite target service
+                                        promotedReference.getTargets().add(target);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            } else {
+                for (ComponentReference componentReference : component.getReferences()) {
+    
+                    // Wire the component reference to the actual
+                    // non-composite component services
+                    List<ComponentService> targets = componentReference.getTargets();
+                    for (int i = 0, n = targets.size(); i < n; i++) {
+                        ComponentService target = targets.get(i);
+                        if (target.getService() instanceof CompositeService) {
+    
+                            // Wire to the actual component service
+                            // promoted by a composite service
+                            CompositeService compositeService = (CompositeService)target.getService();
+                            ComponentService componentService = compositeService.getPromotedService();
+                            if (componentService != null) {
+                                targets.set(i, componentService);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+}

Added: tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.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/ComponentServicePromotionBuilderImpl.java?rev=678491&view=auto
==============================================================================
--- tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java (added)
+++ tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java Mon Jul 21 10:37:59 2008
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+
+/**
+ * A composite builder that handles the creation of promoted services.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentServicePromotionBuilderImpl implements CompositeBuilder {
+    private AssemblyFactory assemblyFactory;
+
+    public ComponentServicePromotionBuilderImpl(AssemblyFactory assemblyFactory) {
+        this.assemblyFactory = assemblyFactory;
+    }
+
+    public void build(Composite composite) throws CompositeBuilderException {
+
+        // Process nested composites recursively
+        configureNestedCompositeServices(composite);
+    }
+
+    private void configureNestedCompositeServices(Composite composite) {
+
+        // Process nested composites recursively
+        for (Component component : composite.getComponents()) {
+            Implementation implementation = component.getImplementation();
+            if (implementation instanceof Composite) {
+
+                // First process nested composites
+                configureNestedCompositeServices((Composite)implementation);
+
+                // Process the component services declared on components in this composite
+                for (ComponentService componentService : component.getServices()) {
+                    Service implService = componentService.getService();
+                    if (implService != null && implService instanceof CompositeService) {
+                        CompositeService compositeService = (CompositeService)implService;
+
+                        // Get the innermost promoted service
+                        ComponentService promotedService =
+                            ServiceConfigurationUtil.getPromotedComponentService(compositeService);
+                        if (promotedService != null) {
+                            Component promotedComponent = ServiceConfigurationUtil.getPromotedComponent(compositeService);
+
+                            // Create a new component service to represent this
+                            // component service on the promoted component
+                            ComponentService newComponentService = assemblyFactory.createComponentService();
+                            newComponentService.setName("$promoted$." + component.getName() + "." + componentService.getName());
+                            promotedComponent.getServices().add(newComponentService);
+                            newComponentService.setService(promotedService.getService());
+                            newComponentService.getBindings().addAll(componentService.getBindings());
+                            newComponentService.setInterfaceContract(componentService.getInterfaceContract());
+                            
+                            if (componentService.getInterfaceContract() != null && 
+                                componentService.getInterfaceContract().getCallbackInterface() != null) {
+                                newComponentService.setCallback(assemblyFactory.createCallback());
+                                newComponentService.getCallback().getBindings()
+                                        .addAll(componentService.getCallback().getBindings());
+                            }
+
+                            // Change the composite service to now promote the
+                            // newly created component service directly
+                            compositeService.setPromotedComponent(promotedComponent);
+                            compositeService.setPromotedService(newComponentService);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+}

Added: tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.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/CompositeBindingURIBuilderImpl.java?rev=678491&view=auto
==============================================================================
--- tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java (added)
+++ tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java Mon Jul 21 10:37:59 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that handles the configuration of binding URIs.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeBindingURIBuilderImpl extends BaseConfigurationBuilderImpl implements CompositeBuilder {
+
+    public CompositeBindingURIBuilderImpl(AssemblyFactory assemblyFactory,
+                                          SCABindingFactory scaBindingFactory,
+                                          InterfaceContractMapper interfaceContractMapper,
+                                          SCADefinitions policyDefinitions,
+                                          Monitor monitor) {
+        super(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor);
+    }
+
+    public void build(Composite composite) throws CompositeBuilderException {
+        configureBindingURIsAndNames(composite);
+    }
+    
+}

Modified: tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.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/CompositeBuilderImpl.java?rev=678491&r1=678490&r2=678491&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java (original)
+++ tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java Mon Jul 21 10:37:59 2008
@@ -42,15 +42,19 @@
 public class CompositeBuilderImpl implements CompositeBuilder {
     private static final Logger logger = Logger.getLogger(CompositeBuilderImpl.class.getName());
     private CompositeBuilder compositeIncludeBuilder;
-    private CompositeBuilder componentWireBuilder;
+    private CompositeBuilder componentReferenceWireBuilder;
+    private CompositeBuilder componentReferencePromotionWireBuilder;
     private CompositeBuilder compositeReferenceWireBuilder;
     private CompositeBuilder compositeCloneBuilder;
     private CompositeBuilder componentConfigurationBuilder;
     private CompositeBuilder compositeServiceConfigurationBuilder;
+    private CompositeBuilder compositeReferenceConfigurationBuilder;
+    private CompositeBuilder compositeBindingURIBuilder;
+    private CompositeBuilder componentServicePromotionBuilder;
+    private CompositeBuilder compositeServicePromotionBuilder;
     private CompositeBuilder compositePromotionBuilder;
     private CompositeBuilder compositePolicyBuilder;
     private CompositeBuilder componentServiceBindingBuilder;
-    private CompositeBuilder compositeServiceBindingBuilder;
     private CompositeBuilder componentReferenceBindingBuilder;
     
     /**
@@ -94,15 +98,19 @@
         }       
         
         compositeIncludeBuilder = new CompositeIncludeBuilderImpl(monitor); 
-        componentWireBuilder = new ComponentReferenceWireBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
-        compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
+        componentReferenceWireBuilder = new ComponentReferenceWireBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
+        componentReferencePromotionWireBuilder = new ComponentReferencePromotionWireBuilderImpl(assemblyFactory, monitor);
+        compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, monitor);
         compositeCloneBuilder = new CompositeCloneBuilderImpl(monitor);
         componentConfigurationBuilder = new ComponentConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor);
-        compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor);
+        compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(assemblyFactory);
+        compositeReferenceConfigurationBuilder = new CompositeReferenceConfigurationBuilderImpl(assemblyFactory);
+        compositeBindingURIBuilder = new CompositeBindingURIBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor);
+        componentServicePromotionBuilder = new ComponentServicePromotionBuilderImpl(assemblyFactory);
+        compositeServicePromotionBuilder = new CompositeServicePromotionBuilderImpl(assemblyFactory);
         compositePromotionBuilder = new CompositePromotionBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
         compositePolicyBuilder = new CompositePolicyBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
         componentServiceBindingBuilder = new ComponentServiceBindingBuilderImpl(monitor);
-        compositeServiceBindingBuilder = new CompositeServiceBindingBuilderImpl(monitor);
         componentReferenceBindingBuilder = new ComponentReferenceBindingBuilderImpl(monitor);
     }
 
@@ -123,17 +131,29 @@
         // Compute the policies across the model hierarchy
         compositePolicyBuilder.build(composite);
 
-        // Build component service binding-related information
-        componentServiceBindingBuilder.build(composite);
-
-        // Build composite service binding-related information
-        compositeServiceBindingBuilder.build(composite);
-
         // Configure composite services
         compositeServiceConfigurationBuilder.build(composite);
         
+        // Configure composite references
+        compositeReferenceConfigurationBuilder.build(composite);
+
+        // Configure binding URIs
+        compositeBindingURIBuilder.build(composite);
+
+        // Create promoted component services
+        componentServicePromotionBuilder.build(composite);
+
+        // Create promoted composite services
+        compositeServicePromotionBuilder.build(composite);
+
+        // Build component service binding-related information
+        componentServiceBindingBuilder.build(composite);
+
         // Wire the components
-        componentWireBuilder.build(composite);
+        componentReferenceWireBuilder.build(composite);
+
+        // Wire the promoted component references
+        componentReferencePromotionWireBuilder.build(composite);
 
         // Wire the composite references
         compositeReferenceWireBuilder.build(composite);

Added: tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.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/CompositeReferenceConfigurationBuilderImpl.java?rev=678491&view=auto
==============================================================================
--- tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java (added)
+++ tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java Mon Jul 21 10:37:59 2008
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.List;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.builder.AutomaticBinding;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+
+/**
+ * A composite builder that handles the configuration of composite references.
+ *
+ * @version $Rev: 651179 $ $Date: 2008-04-24 08:21:13 +0100 (Thu, 24 Apr 2008) $
+ */
+public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuilder {
+    private AssemblyFactory assemblyFactory;
+
+    public CompositeReferenceConfigurationBuilderImpl(AssemblyFactory assemblyFactory) {
+        this.assemblyFactory = assemblyFactory;
+    }
+
+    public void build(Composite composite) throws CompositeBuilderException {
+
+        // Process nested composites recursively
+        configureNestedCompositeReferences(composite);
+
+        // Process top level composite references
+        for (Reference reference : composite.getReferences()) {
+            CompositeReference compositeReference = (CompositeReference)reference;
+
+            // Get the next lower level promoted reference
+            List<ComponentReference> promotedRefs = compositeReference.getPromotedReferences();
+            if (!promotedRefs.isEmpty()) {
+                if (promotedRefs.size() == 1) {
+                    ComponentReference promotedReference = promotedRefs.get(0);
+
+                    // Set the bindings using the top level bindings to override the lower level bindings
+                    if (bindingsSpecifiedManually(compositeReference.getBindings())) {
+                        compositeReference.setPromotionOverride(true);
+                    } else if (bindingsSpecifiedManually(promotedReference.getBindings()) ) {
+                        compositeReference.getBindings().clear();
+                        for (Binding binding : promotedReference.getBindings()) {
+                            try {
+                                compositeReference.getBindings().add((Binding)binding.clone());
+                            } catch (CloneNotSupportedException ex) {
+                                // this binding can't be used in the promoted reference
+                            }
+                        }
+                    }
+                    if (compositeReference.getInterfaceContract() != null &&
+                        compositeReference.getInterfaceContract().getCallbackInterface() != null) {
+                        if (compositeReference.getCallback() != null &&
+                            bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) {
+                            compositeReference.setPromotionOverride(true);
+                        } else if (promotedReference.getCallback() != null &&
+                                   bindingsSpecifiedManually(promotedReference.getCallback().getBindings())) {
+                            if (compositeReference.getCallback() != null) {
+                                compositeReference.getCallback().getBindings().clear();
+                            } else {
+                                compositeReference.setCallback(assemblyFactory.createCallback());
+                            }
+                            for (Binding binding : promotedReference.getCallback().getBindings()) {
+                                try {
+                                    compositeReference.getCallback().getBindings().add((Binding)binding.clone());
+                                } catch (CloneNotSupportedException ex) {
+                                    // this binding can't be used in the promoted reference
+                                }
+                            }
+                        }
+                    }
+                } else {
+                    // This composite reference promotes multiple component references.
+                    // Because the component reference bindings can all be different, we don't
+                    // copy any of them up to this composite reference, which will therefore always
+                    // have its own binding, even if it's only the default SCA binding.
+                    if (bindingsSpecifiedManually(compositeReference.getBindings()) ||
+                        (compositeReference.getCallback() != null &&
+                         bindingsSpecifiedManually(compositeReference.getCallback().getBindings()))) {
+                        compositeReference.setPromotionOverride(true);
+                    }
+                }
+            }
+        }
+    }
+
+    private void configureNestedCompositeReferences(Composite composite) {
+
+        // Process nested composites recursively
+        for (Component component : composite.getComponents()) {
+            Implementation implementation = component.getImplementation();
+            if (implementation instanceof Composite) {
+
+                // First process nested composites
+                configureNestedCompositeReferences((Composite)implementation);
+
+                // Process the component references declared on components in this composite
+                for (ComponentReference componentReference : component.getReferences()) {
+                    Reference implReference = componentReference.getReference();
+                    if (implReference != null && implReference instanceof CompositeReference) {
+                        CompositeReference compositeReference = (CompositeReference)implReference;
+
+                        // Get the next lower level promoted reference
+                        List<ComponentReference> promotedRefs = compositeReference.getPromotedReferences();
+                        if (!promotedRefs.isEmpty()) {
+                            if (promotedRefs.size() == 1) {
+                                ComponentReference promotedReference = promotedRefs.get(0);
+
+                                // Set the bindings using the top level bindings to override the lower level bindings
+                                if (!bindingsSpecifiedManually(compositeReference.getBindings()) &&
+                                    bindingsSpecifiedManually(promotedReference.getBindings()) ) {
+                                    compositeReference.getBindings().clear();
+                                    for (Binding binding : promotedReference.getBindings()) {
+                                        try {
+                                            compositeReference.getBindings().add((Binding)binding.clone());
+                                        } catch (CloneNotSupportedException ex) {
+                                            // this binding can't be used in the promoted reference
+                                        }
+                                    }
+                                }
+                                if (bindingsSpecifiedManually(componentReference.getBindings())) {
+                                    componentReference.setPromotionOverride(true);
+                                } else if (bindingsSpecifiedManually(compositeReference.getBindings()) ) {
+                                    componentReference.getBindings().clear();
+                                    componentReference.getBindings().addAll(compositeReference.getBindings());
+                                }
+                                if (componentReference.getInterfaceContract() != null &&
+                                    componentReference.getInterfaceContract().getCallbackInterface() != null) {
+                                    if (!(compositeReference.getCallback() != null &&
+                                          bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) &&
+                                        promotedReference.getCallback() != null &&
+                                        bindingsSpecifiedManually(promotedReference.getCallback().getBindings())) {
+                                        if (compositeReference.getCallback() != null) {
+                                            compositeReference.getCallback().getBindings().clear();
+                                        } else {
+                                            compositeReference.setCallback(assemblyFactory.createCallback());
+                                        }
+                                        compositeReference.getCallback().getBindings().addAll(
+                                                promotedReference.getCallback().getBindings());
+                                    }
+                                    if (componentReference.getCallback() != null &&
+                                        bindingsSpecifiedManually(componentReference.getCallback().getBindings())) {
+                                        componentReference.setPromotionOverride(true);
+                                    } else if (compositeReference.getCallback() != null &&
+                                               bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) {
+                                        if (componentReference.getCallback() != null) {
+                                            componentReference.getCallback().getBindings().clear();
+                                        } else {
+                                            componentReference.setCallback(assemblyFactory.createCallback());
+                                        }
+                                        for (Binding binding : compositeReference.getCallback().getBindings()) {
+                                            try {
+                                                componentReference.getCallback().getBindings().add((Binding)binding.clone());
+                                            } catch (CloneNotSupportedException ex) {
+                                                // this binding can't be used in the promoted reference
+                                            }
+                                        }
+                                    }
+                                }
+                            } else {
+                                // This component reference promotes multiple lower-level component references.
+                                // Because the lower-level component reference bindings can all be different,
+                                // we don't copy any of them up to this component reference, which will therefore
+                                // always have its own binding, even if it's only the default SCA binding.
+                                if (bindingsSpecifiedManually(componentReference.getBindings()) ||
+                                    (componentReference.getCallback() != null &&
+                                     bindingsSpecifiedManually(componentReference.getCallback().getBindings()))) {
+                                    componentReference.setPromotionOverride(true);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 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()) {
+            return false;
+        } else if (bindings.size() == 1) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+    
+}

Modified: tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.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/CompositeReferenceWireBuilderImpl.java?rev=678491&r1=678490&r2=678491&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java (original)
+++ tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java Mon Jul 21 10:37:59 2008
@@ -19,12 +19,18 @@
 
 package org.apache.tuscany.sca.assembly.builder.impl;
 
+import java.util.List;
+
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
 import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.SCABinding;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
-import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
 import org.apache.tuscany.sca.monitor.Monitor;
 
 /**
@@ -32,13 +38,56 @@
  *
  * @version $Rev$ $Date$
  */
-public class CompositeReferenceWireBuilderImpl extends BaseWireBuilderImpl implements CompositeBuilder {
+public class CompositeReferenceWireBuilderImpl implements CompositeBuilder {
+    private AssemblyFactory assemblyFactory;
+    private Monitor monitor;
 
-    public CompositeReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) {
-        super(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
+    public CompositeReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, Monitor monitor) {
+        this.assemblyFactory = assemblyFactory;
+        this.monitor = monitor;
     }
 
+    /**
+     * Wire composite references in a deployment composite.
+     * 
+     * @param composite
+     */
     public void build(Composite composite) throws CompositeBuilderException {
-        wireCompositeReferences(composite);
+    
+        // Process composite references declared in this composite
+        for (Reference reference : composite.getReferences()) {
+            CompositeReference compositeReference = (CompositeReference)reference;
+
+            // If the composite reference is a promotion override, override the
+            // configuration of the promoted reference.  
+            //FIXME: Policy configuration or wiring of domain-level composite references
+            // doesn't cause a promotion override, unless the composite reference has
+            // additional bindings.  Do we need to detect this and force an override?
+            if (compositeReference.isPromotionOverride()) {
+                List<ComponentReference> promotedReferences =
+                    ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference);
+                for (ComponentReference promotedReference : promotedReferences) {
+                    ReferenceConfigurationUtil.reconcileReferenceBindings(
+                            compositeReference, promotedReference, assemblyFactory, monitor);
+                    if (compositeReference.getInterfaceContract() != null && // can be null in unit tests
+                        compositeReference.getInterfaceContract().getCallbackInterface() != null) {
+                        SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class);
+                        if (promotedReference.getCallback() != null) {
+                            promotedReference.getCallback().getBindings().clear();
+                        } else {
+                            promotedReference.setCallback(assemblyFactory.createCallback());
+                        }
+                        if (scaCallbackBinding != null) {
+                            promotedReference.getCallback().getBindings().add(scaCallbackBinding);
+                        }
+                        if (compositeReference.getCallback() != null) {
+                            promotedReference.getCallback().getBindings().addAll(compositeReference.getCallback()
+                                .getBindings());
+                        }
+                    }
+                }
+            }
+        }
     }
+
 }

Modified: tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.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/CompositeServiceBindingBuilderImpl.java?rev=678491&r1=678490&r2=678491&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java (original)
+++ tuscany/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java Mon Jul 21 10:37:59 2008
@@ -62,7 +62,7 @@
         for (Service service : composite.getServices()) {
             for (Binding binding : service.getBindings()) {
                 if (binding instanceof BindingBuilderExtension) {
-                    Component component = BaseConfigurationBuilderImpl.getPromotedComponent((CompositeService)service);
+                    Component component = ServiceConfigurationUtil.getPromotedComponent((CompositeService)service);
                     ((BindingBuilderExtension)binding).getBuilder().build(component, service, binding, monitor);
                 }
             }