You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2008/07/04 15:20:49 UTC

svn commit: r674044 - /tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java

Author: slaws
Date: Fri Jul  4 06:20:49 2008
New Revision: 674044

URL: http://svn.apache.org/viewvc?rev=674044&view=rev
Log:
Fix up the change made at ? which didn't anticipate that binding uris in serialized callable references may have absolute uris in them. I.e. they don't match target component names and hence the target component may be null. 

Modified:
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java

Modified: tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java?rev=674044&r1=674043&r2=674044&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java (original)
+++ tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java Fri Jul  4 06:20:49 2008
@@ -31,9 +31,11 @@
 import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.assembly.Component;
 import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.CompositeService;
 import org.apache.tuscany.sca.assembly.OptimizableBinding;
 import org.apache.tuscany.sca.assembly.Reference;
 import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.Service;
 import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension;
 import org.apache.tuscany.sca.core.assembly.CompositeActivator;
 import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl;
@@ -297,8 +299,19 @@
                         final Component targetComponent = resolveComponentURI(bindingURI);
                         
                         // Find the Service
-                        final ComponentService targetService = resolveServiceURI(bindingURI, targetComponent);
-
+                        ComponentService targetService = resolveServiceURI(bindingURI, targetComponent);
+                        
+                        // if the target service is a promoted service then find the
+                        // service it promotes
+                        if ((targetService != null) && (targetService.getService() instanceof CompositeService)) {
+                            CompositeService compositeService = (CompositeService) targetService.getService();
+                            // Find the promoted component service
+                            ComponentService promotedComponentService = getPromotedComponentService(compositeService);
+                            if (promotedComponentService != null && !promotedComponentService.isUnresolved()) {
+                                targetService = promotedComponentService;
+                            }
+                        }
+                        
                         OptimizableBinding optimizableBinding = (OptimizableBinding)binding;
                         optimizableBinding.setTargetComponent(targetComponent);
                         optimizableBinding.setTargetComponentService(targetService);
@@ -353,6 +366,34 @@
             }
         }
     }
+    
+    /**
+     * Follow a service promotion chain down to the inner most (non composite)
+     * component service.
+     * 
+     * @param topCompositeService
+     * @return
+     */
+     private ComponentService getPromotedComponentService(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 getPromotedComponentService((CompositeService)service);
+    
+            } else {
+    
+                // Found a non-composite service
+                return componentService;
+            }
+        } else {
+    
+            // No promoted service
+            return null;
+        }
+    }    
 
     /**
      * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
@@ -518,22 +559,24 @@
      * @return The Service with the specified serviceName or null if no such Service found.
      */
     protected ComponentService resolveServiceURI(String bindingURI, Component targetComponent) {
-        if (bindingURI.startsWith("/")) {
-            bindingURI = bindingURI.substring(1);
-        }
-
-        final String componentURI = targetComponent.getURI();
-        final String serviceName;
-        if (componentURI.equals(bindingURI)) {
-            // No service specified
-            serviceName = "";
-        } else {
-            // Get the Service name from the Binding URI
-            serviceName = bindingURI.substring(componentURI.length() + 1);
-        }
-
+        
         ComponentService targetService = null;
+        
         if (targetComponent != null) {
+            if (bindingURI.startsWith("/")) {
+                bindingURI = bindingURI.substring(1);
+            }
+    
+            final String componentURI = targetComponent.getURI();
+            final String serviceName;
+            if (componentURI.equals(bindingURI)) {
+                // No service specified
+                serviceName = "";
+            } else {
+                // Get the Service name from the Binding URI
+                serviceName = bindingURI.substring(componentURI.length() + 1);
+            }
+
             if ("".equals(serviceName)) {
                 targetService = ComponentContextHelper.getSingleService(targetComponent);
             } else {