You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by mc...@apache.org on 2008/07/03 16:31:53 UTC

svn commit: r673687 - in /tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core: context/CallableReferenceImpl.java invocation/CallbackReferenceImpl.java

Author: mcombellack
Date: Thu Jul  3 07:31:53 2008
New Revision: 673687

URL: http://svn.apache.org/viewvc?rev=673687&view=rev
Log:
TUSCANY-2454 - Updated Deserialization code of CallableReferenceImpl and CallbackReferenceImpl to correctly handle references to nested Composites

Modified:
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.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=673687&r1=673686&r2=673687&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 Thu Jul  3 07:31:53 2008
@@ -292,16 +292,12 @@
 
                 for (Binding binding : reference.getBindings()) {
                     if (binding instanceof OptimizableBinding) {
-                        // Split up the URI
-                        final String[] splitURI = splitComponentURI(binding.getURI());
-                        final String componentURI = splitURI[0];
-                        final String serviceName = splitURI[1];
-                        
                         // Resolve the Component
-                        final Component targetComponent = resolveComponentURI(componentURI);
+                        final String bindingURI = binding.getURI();
+                        final Component targetComponent = resolveComponentURI(bindingURI);
                         
                         // Find the Service
-                        final ComponentService targetService = resolveService(serviceName, targetComponent);
+                        final ComponentService targetService = resolveServiceURI(bindingURI, targetComponent);
 
                         OptimizableBinding optimizableBinding = (OptimizableBinding)binding;
                         optimizableBinding.setTargetComponent(targetComponent);
@@ -480,50 +476,62 @@
 
     /**
      * Resolves the specified URI to a Component using the compositeActivator.
+     * There are two cases that we need to handle:
+     * <ul>
+     * <li>URI containing just Composite name(s) (i.e. no Service name specified)
+     * <li>URI containing Composite name(s) and a Service Name
+     * </ul>
      * 
      * @param componentURI The URI of the Component to resolve
      * @return The Component for the specified URI or null if not founds
      */
     protected Component resolveComponentURI(String componentURI) {
-        final String[] splitUri = splitComponentURI(componentURI);
-        return compositeActivator.resolve(splitUri[0]);
-    }
-
-    /**
-     * This method will split the specified URI into the Component URI
-     * and Service Name.
-     * 
-     * @param componentURI The URI to split
-     * @return [0] = Component URI [1] = ServiceName
-     */
-    protected String[] splitComponentURI(String componentURI) {
-        final String[] result = new String[2];
-
+        // If the URI has come from a binding, it may well start with a '/'. We will need
+        // to remove this so we can match it to the composite names.
         if (componentURI.startsWith("/")) {
             componentURI = componentURI.substring(1);
         }
+
+        // First assume that we are dealing with a Component URI without a Service Name
+        Component component = compositeActivator.resolve(componentURI);
+        if (component != null) {
+            return component;
+        }
+
+        // Perhaps we have a ComponentURI that has a ServiceName on the end of it
         final int index = componentURI.lastIndexOf('/');
-        String serviceName = "";
         if (index > -1) {
-            serviceName = componentURI.substring(index + 1);
             componentURI = componentURI.substring(0, index);
+            return compositeActivator.resolve(componentURI);
         }
 
-        // Return the results
-        result[0] = componentURI;
-        result[1] = serviceName;
-        return result;
+        // We could not resolve the Component URI
+        return null;
     }
 
     /**
      * Examines the Services on the specified Component and returns the Service that matches the
-     * specified name.
+     * specified Binding URI.
      * 
-     * @param serviceName The name of the Service to resolve on the Component
+     * @param bindingURI The Binding URI to resolve on the Component
      * @param targetComponent The Component containing the Services
      * @return The Service with the specified serviceName or null if no such Service found.
      */
-    protected ComponentService resolveService(String serviceName, Component targetComponent) {
+    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 ("".equals(serviceName)) {

Modified: tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java?rev=673687&r1=673686&r2=673687&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java (original)
+++ tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java Thu Jul  3 07:31:53 2008
@@ -225,11 +225,8 @@
 
         // Get the target Component and Service from the URI
         final String uri = in.readUTF();
-        final String[] splitURI = super.splitComponentURI(uri);
-        final String componentURI = splitURI[0];
-        final String serviceName = splitURI[1];
-        final Component targetComponent = super.resolveComponentURI(componentURI);
-        final ComponentService targetService = super.resolveService(serviceName, targetComponent);
+        final Component targetComponent = super.resolveComponentURI(uri);
+        final ComponentService targetService = super.resolveServiceURI(uri, targetComponent);
         final InterfaceContract targetServiceIfaceContract = targetService.getInterfaceContract();
 
         // Re-create the resolved Endpoint