Author: slaws
Date: Tue Feb 21 11:29:58 2012
New Revision: 1291714

URL: http://svn.apache.org/viewvc?rev=1291714&view=rev
Log:
TUSCANY-4005 - swap the test around so that the code that raises an error if a 
reference target containing only a component name matches a component with 
multiple services comes after the code that matches interfaces and policy 

Modified:
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
    
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java
    
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java
    
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java?rev=1291714&r1=1291713&r2=1291714&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
 Tue Feb 21 11:29:58 2012
@@ -416,16 +416,24 @@ public class EndpointReferenceBinderImpl
                 matchedEndpoint = endpoints.get(0);
             }
         } else {
-            // find the first endpoint that matches this endpoint reference
+            // find the endpoints that match this endpoint reference
+            List<Endpoint> matchedEndpoints = new ArrayList<Endpoint>();
+            
+            for (Endpoint endpoint : endpoints){
+                if (haveMatchingPolicy(endpointReference, endpoint, 
matchAudit, builderContext) &&
+                    haveMatchingInterfaceContracts(endpointReference, 
endpoint, matchAudit)){
+                    matchedEndpoints.add(endpoint);
+                }
+            }
             
             // TUSCANY-4005 - raise an error if a reference target that only 
specifies the
             //                component name matches more than one component 
service
             if (endpointReference.getTargetEndpoint().getService() == null &&
                 endpointReference.getTargetEndpoint().getBinding() == null &&
-                endpoints.size() > 1   ) {
+                matchedEndpoints.size() > 1   ) {
                 
                 String serviceName = null;
-                for (Endpoint endpoint : endpoints){
+                for (Endpoint endpoint : matchedEndpoints){
                     // ignore service names called "default" as these indicate 
dynamic services
                     // created for the likes of implementation.python
                     if (serviceName == null &&
@@ -458,8 +466,6 @@ public class EndpointReferenceBinderImpl
                     }
                 }
             }
-           
-            boolean findTargetSCABinding = false;
             
             // TUSCANY-3941 check for the case where the user has provided a 
             //              binding.sca at the reference and make sure we pick
@@ -467,16 +473,18 @@ public class EndpointReferenceBinderImpl
             //              other bindings are provided
             if (endpointReference.getBinding() != null &&
                 endpointReference.getBinding() instanceof SCABinding ){
-                findTargetSCABinding = true;
-            }
-            
-            for (Endpoint endpoint : endpoints){
-                if (haveMatchingPolicy(endpointReference, endpoint, 
matchAudit, builderContext) &&
-                    haveMatchingInterfaceContracts(endpointReference, 
endpoint, matchAudit) &&
-                    (findTargetSCABinding == false ||
-                     (findTargetSCABinding == true && endpoint.getBinding() 
instanceof SCABinding))){
-                    matchedEndpoint = endpoint;
-                    break;
+                for (Endpoint endpoint : matchedEndpoints){
+                    if (endpoint.getBinding() instanceof SCABinding){
+                        matchedEndpoint = endpoint;
+                        break;
+                    }
+                }
+            } 
+
+            if (matchedEndpoint == null) {
+                // just take the first matched endpoint from the list
+                if (matchedEndpoints.size() > 0){
+                    matchedEndpoint = matchedEndpoints.get(0);
                 }
             }
         }

Modified: 
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java?rev=1291714&r1=1291713&r2=1291714&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java
 Tue Feb 21 11:29:58 2012
@@ -20,6 +20,6 @@ package itest;
 
 public interface HelloworldServiceAgain {
 
-    String sayHelloAgain(String name);
+    String sayHello(String name);
 
 }

Modified: 
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java?rev=1291714&r1=1291713&r2=1291714&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java
 Tue Feb 21 11:29:58 2012
@@ -32,7 +32,7 @@ public class MultipleServiceClientImpl i
     public HelloworldServiceAgain helloWorld;
 
     public String sayHello(String name) {
-        return "Hello " + helloWorld.sayHelloAgain(name);
+        return "Hello " + helloWorld.sayHello(name);
     }
 
 }

Modified: 
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java?rev=1291714&r1=1291713&r2=1291714&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java
 Tue Feb 21 11:29:58 2012
@@ -31,7 +31,4 @@ public class MultipleServiceImpl impleme
         return "Hello " + name;
     }
 
-    public String sayHelloAgain(String name) {
-        return "Hello again " + name;
-    }
 }


Reply via email to