TUSCANY-2617 perform autowire processing after all targets have been processes. In this was explicitly specified targets will take precedence over autwires as described in the assembly spec.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@702034 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6560ed2951
commit
9021748796
4 changed files with 105 additions and 46 deletions
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.tuscany.sca.itest.references;
|
||||||
|
|
||||||
|
import org.osoa.sca.annotations.Reference;
|
||||||
|
|
||||||
|
public class BComponentWrongTargetImpl implements BComponent {
|
||||||
|
|
||||||
|
protected CComponent cReference;
|
||||||
|
|
||||||
|
public BComponentWrongTargetImpl(@Reference(name = "cReference") CComponent cReference) {
|
||||||
|
this.cReference = cReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String bFoo() {
|
||||||
|
return "BComponentWrongTarget";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String fooC() {
|
||||||
|
return "B" + cReference.cFoo();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -37,7 +37,16 @@
|
||||||
<reference name="dServiceReferences" target="DComponent DComponent1" />
|
<reference name="dServiceReferences" target="DComponent DComponent1" />
|
||||||
|
|
||||||
</component>
|
</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">
|
<component name="BComponent">
|
||||||
<implementation.java class="org.apache.tuscany.sca.itest.references.BComponentImpl" />
|
<implementation.java class="org.apache.tuscany.sca.itest.references.BComponentImpl" />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -29,11 +29,13 @@ import org.junit.Test;
|
||||||
public class AutoWiredReferenceTestCase {
|
public class AutoWiredReferenceTestCase {
|
||||||
private static SCADomain domain;
|
private static SCADomain domain;
|
||||||
private static AComponent acomponent;
|
private static AComponent acomponent;
|
||||||
|
private static AComponent acomponentAutowire;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void init() throws Exception {
|
public static void init() throws Exception {
|
||||||
domain = SCADomain.newInstance("AutoWiredReferencesTest.composite");
|
domain = SCADomain.newInstance("AutoWiredReferencesTest.composite");
|
||||||
acomponent = domain.getService(AComponent.class, "AComponent");
|
acomponent = domain.getService(AComponent.class, "AComponent");
|
||||||
|
acomponentAutowire = domain.getService(AComponent.class, "AComponentAutowire");
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
@ -87,5 +89,14 @@ public class AutoWiredReferenceTestCase {
|
||||||
Assert.assertTrue(true);
|
Assert.assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTargetPrecendence() {
|
||||||
|
try {
|
||||||
|
assertEquals("BComponent", acomponentAutowire.fooB());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Assert.assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -401,50 +401,7 @@ class BaseWireBuilderImpl {
|
||||||
|
|
||||||
List<Endpoint> endpoints = new ArrayList<Endpoint>();
|
List<Endpoint> endpoints = new ArrayList<Endpoint>();
|
||||||
|
|
||||||
if (componentReference.getAutowire() == Boolean.TRUE) {
|
if (!componentReference.getTargets().isEmpty()) {
|
||||||
|
|
||||||
// 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()) {
|
|
||||||
|
|
||||||
// Check if the component reference does not mix the use of endpoints specified via
|
// Check if the component reference does not mix the use of endpoints specified via
|
||||||
// binding elements with target endpoints specified via the target attribute
|
// binding elements with target endpoints specified via the target attribute
|
||||||
|
@ -511,7 +468,8 @@ class BaseWireBuilderImpl {
|
||||||
composite.getName().toString(), componentService.getName());
|
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
|
// Resolve targets from the corresponding reference in the
|
||||||
// componentType
|
// componentType
|
||||||
|
@ -573,7 +531,49 @@ class BaseWireBuilderImpl {
|
||||||
composite.getName().toString(), componentService.getName());
|
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
|
// if no endpoints have found so far retrieve any target names that are in binding URIs
|
||||||
|
|
Loading…
Add table
Reference in a new issue