TUSCANY-2324 - as a follow on from TUSCANY-2484 allow an interface contract to be retrieved from a reference based on the bindings that needs it. For component references information in the endpoint structure is used to find the correct interface contract. I've wrapped this in a method on the contract now though as we are not ready yet to make the endpoint structure more prominent. A piece of work is now required to make use of this information when bindings that required is are configured.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@679082 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d1d6635301
commit
5b7aa6a2fe
6 changed files with 69 additions and 10 deletions
|
@ -20,6 +20,7 @@ package org.apache.tuscany.sca.assembly;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
|
||||
import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
|
||||
|
||||
/**
|
||||
|
@ -78,4 +79,17 @@ public interface Contract extends AbstractContract, PolicySetAttachPoint, Clonea
|
|||
*/
|
||||
Object clone() throws CloneNotSupportedException;
|
||||
|
||||
/**
|
||||
* Returns the interface contract given a binding. Important in the case where
|
||||
* a reference with multiplicity > 1 has been promoted and has it's list of
|
||||
* resolved bindings extended by a promoting reference. Here the binding
|
||||
* from the promoting reference may need the interface contract from the
|
||||
* promoting reference and not the promoted reference.
|
||||
* TODO - remove this wrinkle with better endpoint support.
|
||||
*
|
||||
* @param binding the binding for which the interface contract is required
|
||||
* @return the interface contract
|
||||
*/
|
||||
InterfaceContract getInterfaceContract(Binding binding);
|
||||
|
||||
}
|
||||
|
|
|
@ -639,16 +639,13 @@ class BaseWireBuilderImpl {
|
|||
}
|
||||
} else {
|
||||
|
||||
/* TODO - don't enable this yet as we have tests that
|
||||
use relative URIs in bindings that don't refer to
|
||||
targets
|
||||
// create endpoints for manually configured bindings
|
||||
Endpoint endpoint = endpointFactory.createEndpoint();
|
||||
endpoint.setTargetName(uri);
|
||||
endpoint.setSourceComponent(null); // TODO - fixed up at start
|
||||
endpoint.setSourceComponentReference(componentReference);
|
||||
endpoint.getCandidateBindings().add(binding);
|
||||
endpoint.setSourceBinding(binding);
|
||||
endpoints.add(endpoint);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -679,8 +676,16 @@ class BaseWireBuilderImpl {
|
|||
|
||||
componentReference.getEndpoints().addAll(endpoints);
|
||||
|
||||
// the result of calculating the endpoints is either that bindings have been
|
||||
// configured manually using a URI or that targets have been provided and the
|
||||
// endpoint remains unresolved. So all endpoints should be either resved or uresolved.
|
||||
boolean endpointsRequireAutomaticResolution = false;
|
||||
for(Endpoint endpoint : endpoints){
|
||||
endpointsRequireAutomaticResolution = endpoint.isUnresolved();
|
||||
}
|
||||
|
||||
// build each endpoint
|
||||
if (!endpoints.isEmpty()) {
|
||||
if (endpointsRequireAutomaticResolution) {
|
||||
|
||||
for(Endpoint endpoint : endpoints){
|
||||
endpointBuilder.build(endpoint);
|
||||
|
|
|
@ -185,9 +185,11 @@ abstract class ReferenceConfigurationUtil {
|
|||
for (Binding binding : reference.getBindings()) {
|
||||
if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) {
|
||||
promotedReference.getBindings().add(binding);
|
||||
|
||||
// TUSCANY-2324: ensure that the promoted reference can identify the
|
||||
// correct interface contract for this binding
|
||||
// TODO - Remove and use Reference.getInterfaceContract(binding)
|
||||
// in any binding that needs to use the interface contract
|
||||
// from the promoting reference
|
||||
promotedReference.setInterfaceContract(reference.getInterfaceContract());
|
||||
}
|
||||
}
|
||||
|
@ -209,11 +211,12 @@ abstract class ReferenceConfigurationUtil {
|
|||
for (Binding binding : reference.getBindings()) {
|
||||
if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) {
|
||||
promotedReference.getBindings().add(binding);
|
||||
|
||||
// TUSCANY-2324: ensure that the promoted reference can identify the
|
||||
// correct interface contract for this binding
|
||||
// TODO: no such interface exists yet!
|
||||
//promotedReference.setInterfaceContract(binding, reference.getInterfaceContract());
|
||||
// TODO: use Reference.getInterfaceContract(binding) when the interface contract is required
|
||||
// in any binding that needs to use the interface contract
|
||||
// from the promoting reference
|
||||
//promotedReference.setInterfaceContract(binding, reference.getInterfaceContract());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,11 +22,13 @@ package org.apache.tuscany.sca.assembly.impl;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.tuscany.sca.assembly.Binding;
|
||||
import org.apache.tuscany.sca.assembly.ComponentReference;
|
||||
import org.apache.tuscany.sca.assembly.ComponentService;
|
||||
import org.apache.tuscany.sca.assembly.CompositeReference;
|
||||
import org.apache.tuscany.sca.assembly.Endpoint;
|
||||
import org.apache.tuscany.sca.assembly.Reference;
|
||||
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
|
||||
|
||||
/**
|
||||
* Represents a component reference
|
||||
|
@ -88,4 +90,23 @@ public class ComponentReferenceImpl extends ReferenceImpl implements ComponentRe
|
|||
public List<Endpoint> getEndpoints(){
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use endpoint information to work out what the interface contract for the
|
||||
* binding is.
|
||||
*/
|
||||
public InterfaceContract getInterfaceContract(Binding binding){
|
||||
InterfaceContract interfaceContract = null;
|
||||
|
||||
for (Endpoint theEndpoint : endpoints){
|
||||
if (theEndpoint.getSourceBinding() == binding){
|
||||
interfaceContract = theEndpoint.getSourceComponentReference().getInterfaceContract();
|
||||
}
|
||||
}
|
||||
|
||||
if (interfaceContract == null){
|
||||
interfaceContract = getInterfaceContract();
|
||||
}
|
||||
return interfaceContract;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.tuscany.sca.assembly.Binding;
|
|||
import org.apache.tuscany.sca.assembly.Callback;
|
||||
import org.apache.tuscany.sca.assembly.ComponentService;
|
||||
import org.apache.tuscany.sca.assembly.Reference;
|
||||
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
|
||||
import org.apache.tuscany.sca.policy.PolicySet;
|
||||
|
||||
/**
|
||||
|
@ -121,5 +122,12 @@ public class ReferenceImpl extends AbstractReferenceImpl implements Reference, C
|
|||
public void setPolicySets(List<PolicySet> policySets) {
|
||||
this.policySets = policySets;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default return the interface contract for the reference
|
||||
*/
|
||||
public InterfaceContract getInterfaceContract(Binding binding){
|
||||
return getInterfaceContract();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
|||
import org.apache.tuscany.sca.assembly.Binding;
|
||||
import org.apache.tuscany.sca.assembly.Callback;
|
||||
import org.apache.tuscany.sca.assembly.Service;
|
||||
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
|
||||
import org.apache.tuscany.sca.policy.PolicySet;
|
||||
|
||||
/**
|
||||
|
@ -95,5 +96,12 @@ public class ServiceImpl extends AbstractServiceImpl implements Service, Cloneab
|
|||
public void setPolicySets(List<PolicySet> policySets) {
|
||||
this.policySets = policySets;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default return the interface contract for the service
|
||||
*/
|
||||
public InterfaceContract getInterfaceContract(Binding binding){
|
||||
return getInterfaceContract();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue