Takes collection of policies and merges them into a single policy using algorithm described in
WS-PolicyAttachment specification. None of the original policis in the collection is modified in
any way.
if (policies == null || policies.isEmpty()) {
return null;
} else if (policies.size() == 1) {
return policies.iterator().next();
}
final Collection<Collection<AssertionSet>> alternativeSets = new LinkedList<Collection<AssertionSet>>();
for (Policy policy : policies) {
alternativeSets.add(policy.getContent());
}
final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);
if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
return Policy.createNullPolicy();
} else {
final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
}
return Policy.createPolicy(mergedSetList);
}