PolicyIntersectorpublic final class PolicyIntersector extends Object The instance of this class is intended to provide policy intersection mechanism. |
Fields Summary |
---|
private static final PolicyIntersector | INSTANCE | private static final com.sun.xml.ws.policy.privateutil.PolicyLogger | LOGGER |
Constructors Summary |
---|
private PolicyIntersector()Prevents direct instantiation of this class from outside
// nothing to initialize
|
Methods Summary |
---|
public static com.sun.xml.ws.policy.PolicyIntersector | createPolicyIntersector()Returns a policy intersector that can be used to intersect group of policies.
return PolicyIntersector.INSTANCE;
| public Policy | intersect(java.util.Collection policies)Performs intersection on the input collection of policies and returns the resulting (intersected) policy. If input policy
collection contains only a single policy instance, no intersection is performed and the instance is directly returned
as a method call result.
if (policies == null || policies.isEmpty()) {
throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0056_NEITHER_NULL_NOR_EMPTY_POLICY_COLLECTION_EXPECTED()));
} else if (policies.size() == 1) {
return policies.iterator().next();
}
// check for "null" and "empty" policy: if such policy is found return "null" policy, or if all policies are "empty", return "empty" policy
boolean found = false;
boolean allPoliciesEmpty = true;
for (Policy tested : policies) {
if (tested.isEmpty()) {
found = true;
} else {
if (tested.isNull()) {
found = true;
}
allPoliciesEmpty = false;
}
if (found && !allPoliciesEmpty) {
return Policy.createNullPolicy();
}
}
if (allPoliciesEmpty) {
return Policy.createEmptyPolicy();
}
// simple tests didn't lead to final answer => let's performe some intersecting ;)
final Iterator<Policy> policyIterator = policies.iterator();
final List<AssertionSet> finalAlternatives = new LinkedList<AssertionSet>(policyIterator.next().getContent());
final Queue<AssertionSet> testedAlternatives = new LinkedList<AssertionSet>();
final List<AssertionSet> alternativesToMerge = new ArrayList<AssertionSet>(2);
while (policyIterator.hasNext()) {
final Collection<AssertionSet> currentAlternatives = policyIterator.next().getContent();
testedAlternatives.clear();
testedAlternatives.addAll(finalAlternatives);
finalAlternatives.clear();
AssertionSet testedAlternative;
while ((testedAlternative = testedAlternatives.poll()) != null) {
for (AssertionSet currentAlternative : currentAlternatives) {
if (testedAlternative.isCompatibleWith(currentAlternative)) {
alternativesToMerge.add(testedAlternative);
alternativesToMerge.add(currentAlternative);
finalAlternatives.add(AssertionSet.createMergedAssertionSet(alternativesToMerge));
alternativesToMerge.clear();
}
}
}
}
return Policy.createPolicy(finalAlternatives);
| public Policy | intersect(Policy policyA, Policy policyB)
return intersect(Arrays.asList(new Policy[] {policyA, policyB}));
|
|