FileDocCategorySizeDatePackage
PolicyMerger.javaAPI DocExample4669Tue May 29 16:56:34 BST 2007com.sun.xml.ws.policy

PolicyMerger

public final class PolicyMerger extends Object
Merge policies and return the effective policy. WS-PolicyAttachment defines a merge algorithm for WSDL 1.1 policy attachments.

Fields Summary
private static final PolicyMerger
merger
Constructors Summary
private PolicyMerger()
This private constructor is to avoid direct class instantiation from outsied of the package

    
                       
      
        // nothing to instantiate
    
Methods Summary
public static com.sun.xml.ws.policy.PolicyMergergetMerger()
Factory method for obtaining thread-safe policy merger instance.

return
policy merger instance.

        return merger;
    
public Policymerge(java.util.Collection policies)
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.

param
policies collection of policies to be merged. The collection must not contain '{@code null}' elements!
return
merged policy containing combination of policy alternatives stored in all input policies. If provided collection of policies is {@code null} or empty, returns {@code null}. If provided collection of policies contains only single policy, the policy is returned.

        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);
        }