From e4d4979293ce33727d6867b7304ab5c693af39ba Mon Sep 17 00:00:00 2001 From: slaws Date: Tue, 21 Feb 2012 11:29:58 +0000 Subject: 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 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1291714 13f79535-47bb-0310-9956-ffa450edef68 --- .../runtime/impl/EndpointReferenceBinderImpl.java | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'sca-java-2.x/trunk/modules') diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java index c1eaf98e66..cd8115d201 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java @@ -416,16 +416,24 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { matchedEndpoint = endpoints.get(0); } } else { - // find the first endpoint that matches this endpoint reference + // find the endpoints that match this endpoint reference + List matchedEndpoints = new ArrayList(); + + 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 implements EndpointReferenceBinder { } } } - - 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 implements EndpointReferenceBinder { // 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); } } } -- cgit v1.2.3