* @param endpointReference
* @param endpoints
*/
private void selectForwardEndpoint(EndpointReference endpointReference, List<Endpoint> endpoints, Audit matchAudit, BuilderContext builderContext) {
Endpoint matchedEndpoint = null;
if (endpointReference.getReference().getName().startsWith("$self$.")){
// just select the first one and don't do any policy matching
if (endpointReference.getTargetEndpoint() != null && !endpointReference.getTargetEndpoint().isUnresolved()) {
matchedEndpoint = endpointReference.getTargetEndpoint();
} else {
matchedEndpoint = endpoints.get(0);
}
} else {
// find the first endpoint that matches this endpoint reference
for (Endpoint endpoint : endpoints){
if (haveMatchingPolicy(endpointReference, endpoint, matchAudit, builderContext) &&
haveMatchingInterfaceContracts(endpointReference, endpoint, matchAudit)){
matchedEndpoint = endpoint;
break;
}
}
}
if (matchedEndpoint == null){
return;
} else {
endpointReference.setTargetEndpoint(matchedEndpoint);
Binding binding = matchedEndpoint.getBinding();
endpointReference.setBinding(binding);
// TUSCANY-3873 - add policy from the service
// we don't care about intents at this stage
endpointReference.getPolicySets().addAll(matchedEndpoint.getPolicySets());
// TODO - we need to re-run the appliesTo processing here but there is some question about what
// appliesTo means. It's also difficult to get to the PolicyAppliesToBuilder from here and
// need a new EntensionInterface to support access. So for now I'm just cheating and looking to
// see if the XPath expression contains the binding type as a string while we discuss appliesTo