*/
private boolean haveMatchingPolicy(EndpointReference endpointReference, Endpoint endpoint, Audit matchAudit, BuilderContext builderContext){
matchAudit.append("Match policy of " + endpointReference.toString() + " to " + endpoint.toString() + " ");
List<PolicySet> referencePolicySets = new ArrayList<PolicySet>();
Binding binding = null;
if (endpointReference.getBinding() == null){
binding = endpoint.getBinding();
} else {
binding = endpointReference.getBinding();
}
// if there are any intents that are mutually exclusive between
// service and reference then they don't match
for (Intent eprIntent : endpointReference.getRequiredIntents()){
for (Intent epIntent : endpoint.getRequiredIntents()){
if (eprIntent.getExcludedIntents().contains(epIntent) ||
epIntent.getExcludedIntents().contains(eprIntent) ||
checkQualifiedMutualExclusion(eprIntent.getExcludedIntents(), epIntent) ||
checkQualifiedMutualExclusion(epIntent.getExcludedIntents(), eprIntent)){
matchAudit.append("No match because the following intents are mutually exclusive " +
eprIntent.toString() +
" " +
epIntent.toString() +
" ");
matchAudit.appendSeperator();
return false;
}
}
}
// Find the set of policy sets from this reference. This includes
// the policy sets that are specific to the service binding and
// any policy sets that are not binding specific
for (PolicySet policySet : endpointReference.getPolicySets()){
PolicyBuilder policyBuilder = null;
if (policySet.getPolicies().size() > 0){
QName policyType = policySet.getPolicies().get(0).getName();
policyBuilder = builders.getPolicyBuilder(policyType);
}
if ((policyBuilder == null) ||
(policyBuilder != null && policyBuilder.getSupportedBindings() == null) ||
(policyBuilder != null && policyBuilder.getSupportedBindings().contains(binding.getType()))){
referencePolicySets.add(policySet);
}
}
// if there are no policy sets on the reference take the policy sets from the
// service binding we are matching against
if (referencePolicySets.isEmpty()) {
for (PolicySet policySet : endpoint.getPolicySets()){
PolicyBuilder policyBuilder = null;
if (policySet.getPolicies().size() > 0){
QName policyType = policySet.getPolicies().get(0).getName();
policyBuilder = builders.getPolicyBuilder(policyType);
}
if ((policyBuilder == null) ||
(policyBuilder != null && policyBuilder.getSupportedBindings() == null) ||
(policyBuilder != null && policyBuilder.getSupportedBindings().contains(binding.getType()))){
referencePolicySets.add(policySet);
}
}
}
// the "appliesTo" algorithm to remove any policy sets that
// don't apply to the service binding will already have been
// run during the build phase
// Determine if there are any reference policies
boolean noEndpointReferencePolicies = true;
for (PolicySet policySet : referencePolicySets){
if (policySet.getPolicies().size() > 0){
noEndpointReferencePolicies = false;
break;
}
}
// Determine of there are any service policies
boolean noEndpointPolicies = true;
for (PolicySet policySet : endpoint.getPolicySets()){
if (policySet.getPolicies().size() > 0){
noEndpointPolicies = false;
break;
}
}
// if no policy sets or intents are present then they match
if ((endpointReference.getRequiredIntents().size() == 0) &&
(endpoint.getRequiredIntents().size() == 0) &&
(noEndpointReferencePolicies) &&
(noEndpointPolicies)) {
matchAudit.append("Match because there are no intents or policies ");
matchAudit.appendSeperator();
return true;
}
// check that the intents on the reference side are resolved
// can't do this until this point as the service binding
// may come into play. Intents may be satisfied by the default
// or optional intents that the binding type provides. Failing
// this they must be satisfied by reference policy sets
// Failing this the intent is unresolved and the reference and
// service don't match
// TODO - seems that we should do this loop on a binding by binding basis
// rather than each time we do matching
BindingType bindingType = null;
Definitions systemDefinitions = null;
if (builderContext != null){
systemDefinitions = builderContext.getDefinitions();
} else {
systemDefinitions = ((RuntimeEndpoint)endpoint).getCompositeContext().getSystemDefinitions();
}
for (BindingType loopBindingType : systemDefinitions.getBindingTypes()){
if (loopBindingType.getType().equals(binding.getType())){
bindingType = loopBindingType;
break;
}
}