static void determineApplicableBindingPolicySets(Contract source, Contract target) throws PolicyConfigurationException {
List<Intent> intentsCopy = null;
for (Binding aBinding : source.getBindings()) {
if (aBinding instanceof PolicySubject) {
PolicySubject policiedBinding = (PolicySubject)aBinding;
ExtensionType bindingType = policiedBinding.getType();
intentsCopy = new ArrayList<Intent>(policiedBinding.getRequiredIntents());
// add the target component's intents to the reference binding
if (target != null) {
for (Intent intent : target.getRequiredIntents()) {
if (!policiedBinding.getRequiredIntents().contains(intent)) {
for (ExtensionType constrained : intent.getConstrainedTypes()) {
if (bindingType != null && bindingType.getType().getNamespaceURI()
.equals(constrained.getType().getNamespaceURI())
&& bindingType.getType().getLocalPart().startsWith(constrained
.getType().getLocalPart())) {
policiedBinding.getRequiredIntents().add(intent);
break;
}
}
}
}
}
trimInherentlyProvidedIntents(policiedBinding.getType(),
policiedBinding.getRequiredIntents());
trimProvidedIntents(policiedBinding.getRequiredIntents(), policiedBinding
.getPolicySets());
// determine additional policysets that match remaining intents
// TODO: resolved to domain policy registry and attach suitable
// policy sets to the binding
// for now using the SCA Definitions instead of registry
// if there are intents that are not provided by any policy set
// throw a warning
determineApplicableDomainPolicySets(source, policiedBinding);
//the intents list could have been trimmed when matching for policysets
//since the bindings may need the original set of intents we copy that back
policiedBinding.getRequiredIntents().clear();
policiedBinding.getRequiredIntents().addAll(intentsCopy);
}
}
}