From f343f1d8336d5045d7aacb8f949658b2e34f709f Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 17 Oct 2008 13:08:08 +0000 Subject: TUSCANY-2617 if a reference already has a target don't try to autowire it git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@705599 13f79535-47bb-0310-9956-ffa450edef68 --- .../assembly/builder/impl/BaseWireBuilderImpl.java | 92 +++++++++++----------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'branches/sca-java-1.3.3/modules/assembly/src') diff --git a/branches/sca-java-1.3.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java b/branches/sca-java-1.3.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java index 0c2d02ab48..b2f662918c 100644 --- a/branches/sca-java-1.3.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java +++ b/branches/sca-java-1.3.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java @@ -401,50 +401,7 @@ class BaseWireBuilderImpl { List endpoints = new ArrayList(); - if (componentReference.getAutowire() == Boolean.TRUE) { - - // Find suitable targets in the current composite for an - // autowired reference - Multiplicity multiplicity = componentReference.getMultiplicity(); - for (Component targetComponent : composite.getComponents()) { - // prevent autowire connecting to self - boolean skipSelf = false; - for (ComponentReference targetComponentReference : targetComponent.getReferences()) { - if (componentReference == targetComponentReference){ - skipSelf = true; - } - } - - if (!skipSelf){ - for (ComponentService targetComponentService : targetComponent.getServices()) { - if (componentReference.getInterfaceContract() == null || - interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) { - - Endpoint endpoint = endpointFactory.createEndpoint(); - endpoint.setTargetName(targetComponent.getName()); - endpoint.setSourceComponent(null); // TODO - fixed up at start - endpoint.setSourceComponentReference(componentReference); - endpoint.setInterfaceContract(componentReference.getInterfaceContract()); - endpoint.setTargetComponent(targetComponent); - endpoint.setTargetComponentService(targetComponentService); - endpoint.getCandidateBindings().addAll(componentReference.getBindings()); - endpoints.add(endpoint); - - if (multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) { - break; - } - } - } - } - } - - if (multiplicity == Multiplicity.ONE_N || multiplicity == Multiplicity.ONE_ONE) { - if (endpoints.size() == 0) { - warning("NoComponentReferenceTarget", componentReference, componentReference.getName()); - } - } - - } else if (!componentReference.getTargets().isEmpty()) { + if (!componentReference.getTargets().isEmpty()) { // Check if the component reference does not mix the use of endpoints specified via // binding elements with target endpoints specified via the target attribute @@ -511,7 +468,8 @@ class BaseWireBuilderImpl { composite.getName().toString(), componentService.getName()); } } - } else if (componentReference.getReference() != null) { + } else if ((componentReference.getReference() != null) && + (!componentReference.getReference().getTargets().isEmpty())) { // Resolve targets from the corresponding reference in the // componentType @@ -573,7 +531,49 @@ class BaseWireBuilderImpl { composite.getName().toString(), componentService.getName()); } } - } + } else if (componentReference.getAutowire() == Boolean.TRUE) { + + // Find suitable targets in the current composite for an + // autowired reference + Multiplicity multiplicity = componentReference.getMultiplicity(); + for (Component targetComponent : composite.getComponents()) { + // prevent autowire connecting to self + boolean skipSelf = false; + for (ComponentReference targetComponentReference : targetComponent.getReferences()) { + if (componentReference == targetComponentReference){ + skipSelf = true; + } + } + + if (!skipSelf){ + for (ComponentService targetComponentService : targetComponent.getServices()) { + if (componentReference.getInterfaceContract() == null || + interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) { + + Endpoint endpoint = endpointFactory.createEndpoint(); + endpoint.setTargetName(targetComponent.getName()); + endpoint.setSourceComponent(null); // TODO - fixed up at start + endpoint.setSourceComponentReference(componentReference); + endpoint.setInterfaceContract(componentReference.getInterfaceContract()); + endpoint.setTargetComponent(targetComponent); + endpoint.setTargetComponentService(targetComponentService); + endpoint.getCandidateBindings().addAll(componentReference.getBindings()); + endpoints.add(endpoint); + + if (multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) { + break; + } + } + } + } + } + + if (multiplicity == Multiplicity.ONE_N || multiplicity == Multiplicity.ONE_ONE) { + if (endpoints.size() == 0) { + warning("NoComponentReferenceTarget", componentReference, componentReference.getName()); + } + } + } // if no endpoints have found so far retrieve any target names that are in binding URIs -- cgit v1.2.3