You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2009/08/04 04:58:18 UTC

svn commit: r800663 - /tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java

Author: rfeng
Date: Tue Aug  4 02:58:18 2009
New Revision: 800663

URL: http://svn.apache.org/viewvc?rev=800663&view=rev
Log:
Fix the algorithm to check duplicate names for callback bindings to avoid failure in callback-ws itest

Modified:
    tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java

Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java?rev=800663&r1=800662&r2=800663&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java Tue Aug  4 02:58:18 2009
@@ -169,9 +169,10 @@
             // Create default SCA binding
             attachSCABinding(service, definitions);
 
+            constructBindingNames(service, monitor);
+            
             // Initialize binding names and URIs
             for (Binding binding : service.getBindings()) {
-                constructBindingName(service, binding, monitor);
                 constructBindingURI(parentComponentURI, composite, service, binding, defaultBindings, monitor);
             }
         }
@@ -209,10 +210,10 @@
                 // Create default SCA binding
                 attachSCABinding(service, definitions);
 
+                constructBindingNames(service, monitor);
+                
                 // Initialize binding names and URIs
                 for (Binding binding : service.getBindings()) {
-
-                    constructBindingName(service, binding, monitor);
                     constructBindingURI(component, service, binding, defaultBindings, monitor);
                 }
             }
@@ -239,26 +240,12 @@
 
         // Initialize composite service callback binding names
         for (Service service : composite.getServices()) {
-
-            if (service.getCallback() != null) {
-                for (Binding binding : service.getCallback().getBindings()) {
-                    constructBindingName(service, binding, monitor);
-                }
-            }
+            constructBindingNames(service, monitor);
         }
 
         // Initialize composite reference binding names
         for (Reference reference : composite.getReferences()) {
-
-            for (Binding binding : reference.getBindings()) {
-                constructBindingName(reference, binding, monitor);
-            }
-
-            if (reference.getCallback() != null) {
-                for (Binding binding : reference.getCallback().getBindings()) {
-                    constructBindingName(reference, binding, monitor);
-                }
-            }
+            constructBindingNames(reference, monitor);
         }
 
         // Initialize component service and reference binding names
@@ -266,27 +253,13 @@
 
             // Initialize component service callback binding names
             for (ComponentService service : component.getServices()) {
-
-                if (service.getCallback() != null) {
-                    for (Binding binding : service.getCallback().getBindings()) {
-                        constructBindingName(service, binding, monitor);
-                    }
-                }
+                constructBindingNames(service, monitor);
             }
 
             // Initialize component reference binding names
             for (ComponentReference reference : component.getReferences()) {
-
                 // Initialize binding names
-                for (Binding binding : reference.getBindings()) {
-                    constructBindingName(reference, binding, monitor);
-                }
-
-                if (reference.getCallback() != null) {
-                    for (Binding binding : reference.getCallback().getBindings()) {
-                        constructBindingName(reference, binding, monitor);
-                    }
-                }
+                constructBindingNames(reference, monitor);
             }
         }
     }
@@ -296,28 +269,41 @@
      * or reference name
      *
      * @param contract the service or reference
-     * @param binding
      */
-    private void constructBindingName(Contract contract, Binding binding, Monitor monitor) {
-
-        // set the default binding name if one is required
-        // if there is no name on the binding then set it to the service or reference name
-        if (binding.getName() == null) {
-            binding.setName(contract.getName());
-        }
-
-        // Check that multiple bindings do not have the same name
-        for (Binding otherBinding : contract.getBindings()) {
-            if (otherBinding == binding) {
-                // Skip the current binding
-                continue;
-            }
-
-            if (binding.getName().equals(otherBinding.getName())) {
+    private void constructBindingNames(Contract contract, Monitor monitor) {
+        List<Binding> bindings = contract.getBindings();
+        Map<String, Binding> bindingMap = new HashMap<String, Binding>();
+        for (Binding binding : bindings) {
+            // set the default binding name if one is required
+            // if there is no name on the binding then set it to the service or reference name
+            if (binding.getName() == null) {
+                binding.setName(contract.getName());
+            }
+            Binding existed = bindingMap.put(binding.getName(), binding);
+            // Check that multiple bindings do not have the same name
+            if (existed != null && existed != binding) {
                 error(monitor, contract instanceof Service ? "MultipleBindingsForService"
                     : "MultipleBindingsForReference", binding, contract.getName(), binding.getName());
             }
         }
+        
+        if (contract.getCallback() != null) {
+            bindings = contract.getCallback().getBindings();
+            bindingMap.clear();
+            for (Binding binding : bindings) {
+                // set the default binding name if one is required
+                // if there is no name on the binding then set it to the service or reference name
+                if (binding.getName() == null) {
+                    binding.setName(contract.getName());
+                }
+                Binding existed = bindingMap.put(binding.getName(), binding);
+                // Check that multiple bindings do not have the same name
+                if (existed != null && existed != binding) {
+                    error(monitor, contract instanceof Service ? "MultipleBindingsForServiceCallback"
+                        : "MultipleBindingsForReferenceCallback", binding, contract.getName(), binding.getName());
+                }
+            }
+        }
     }
 
     /**