Author: slaws
Date: Fri Oct 17 06:08:08 2008
New Revision: 705599

URL: http://svn.apache.org/viewvc?rev=705599&view=rev
Log:
TUSCANY-2617 if a reference already has a target don't try to autowire it 

Added:
    
tuscany/branches/sca-java-1.3.3/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/BComponentWrongTargetImpl.java
      - copied unchanged from r702034, 
tuscany/java/sca/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/BComponentWrongTargetImpl.java
Modified:
    
tuscany/branches/sca-java-1.3.3/itest/references/src/main/resources/AutoWiredReferencesTest.composite
    
tuscany/branches/sca-java-1.3.3/itest/references/src/main/resources/ManualWiredReferencesTest.composite
    
tuscany/branches/sca-java-1.3.3/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/AutoWiredReferenceTestCase.java
    
tuscany/branches/sca-java-1.3.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java

Modified: 
tuscany/branches/sca-java-1.3.3/itest/references/src/main/resources/AutoWiredReferencesTest.composite
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.3/itest/references/src/main/resources/AutoWiredReferencesTest.composite?rev=705599&r1=705598&r2=705599&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.3.3/itest/references/src/main/resources/AutoWiredReferencesTest.composite
 (original)
+++ 
tuscany/branches/sca-java-1.3.3/itest/references/src/main/resources/AutoWiredReferencesTest.composite
 Fri Oct 17 06:08:08 2008
@@ -37,7 +37,16 @@
         <reference name="dServiceReferences" target="DComponent DComponent1" />
 
     </component>
+    
+    <component name="AComponentAutowire" autowire="true">
+        <implementation.java 
class="org.apache.tuscany.sca.itest.references.AComponentImpl" />
+        <reference name="bReference" target="BComponent" />
+    </component>    
 
+    <component name="BComponentWrongTarget">
+        <implementation.java 
class="org.apache.tuscany.sca.itest.references.BComponentWrongTargetImpl" />
+    </component>
+    
     <component name="BComponent">
         <implementation.java 
class="org.apache.tuscany.sca.itest.references.BComponentImpl" />
     </component>

Modified: 
tuscany/branches/sca-java-1.3.3/itest/references/src/main/resources/ManualWiredReferencesTest.composite
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.3/itest/references/src/main/resources/ManualWiredReferencesTest.composite?rev=705599&r1=705598&r2=705599&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.3.3/itest/references/src/main/resources/ManualWiredReferencesTest.composite
 (original)
+++ 
tuscany/branches/sca-java-1.3.3/itest/references/src/main/resources/ManualWiredReferencesTest.composite
 Fri Oct 17 06:08:08 2008
@@ -26,7 +26,8 @@
     <component name="AComponent" >
         <implementation.java 
class="org.apache.tuscany.sca.itest.references.AComponentImpl" />
         <reference name="bReference" target="BComponent" />
-        <reference name="cReference" target="CComponent/CComponent">
+        <reference name="cReference" target="CComponent/CComponentImpl">
+        <!-- reference name="cReference" target="CComponent"-->
             <binding.sca uri="DComponent"/>
         </reference>
         <reference name="dReference1" >

Modified: 
tuscany/branches/sca-java-1.3.3/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/AutoWiredReferenceTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.3/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/AutoWiredReferenceTestCase.java?rev=705599&r1=705598&r2=705599&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.3.3/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/AutoWiredReferenceTestCase.java
 (original)
+++ 
tuscany/branches/sca-java-1.3.3/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/AutoWiredReferenceTestCase.java
 Fri Oct 17 06:08:08 2008
@@ -29,11 +29,13 @@
 public class AutoWiredReferenceTestCase {
     private static SCADomain domain;
     private static AComponent acomponent;
+    private static AComponent acomponentAutowire;
 
     @BeforeClass
     public static void init() throws Exception {
         domain = SCADomain.newInstance("AutoWiredReferencesTest.composite");
         acomponent = domain.getService(AComponent.class, "AComponent");
+        acomponentAutowire = domain.getService(AComponent.class, 
"AComponentAutowire");
     }
 
     @AfterClass
@@ -87,5 +89,14 @@
             Assert.assertTrue(true);
         }
     }
+    
+    @Test
+    public void testTargetPrecendence() {
+        try {
+            assertEquals("BComponent", acomponentAutowire.fooB());
+        } catch (Exception e) {
+            Assert.assertTrue(true);
+        }
+    }
 
 }

Modified: 
tuscany/branches/sca-java-1.3.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java?rev=705599&r1=705598&r2=705599&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.3.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java
 (original)
+++ 
tuscany/branches/sca-java-1.3.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java
 Fri Oct 17 06:08:08 2008
@@ -401,50 +401,7 @@
 
         List<Endpoint> endpoints = new ArrayList<Endpoint>();
         
-        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 @@
                                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 @@
                                         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


Reply via email to