Java Code Examples for com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion#compareTo()

The following examples show how to use com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion#compareTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PolicyMerger.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @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.
 */
public Policy merge(final Collection<Policy> policies) {
    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>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example 2
Source File: PolicyMerger.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @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.
 */
public Policy merge(final Collection<Policy> policies) {
    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>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example 3
Source File: PolicyMerger.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @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.
 */
public Policy merge(final Collection<Policy> policies) {
    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>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example 4
Source File: PolicyMerger.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @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.
 */
public Policy merge(final Collection<Policy> policies) {
    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>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example 5
Source File: PolicyMerger.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @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.
 */
public Policy merge(final Collection<Policy> policies) {
    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>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example 6
Source File: PolicyMerger.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @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.
 */
public Policy merge(final Collection<Policy> policies) {
    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>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example 7
Source File: PolicyMerger.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @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.
 */
public Policy merge(final Collection<Policy> policies) {
    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>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example 8
Source File: PolicyMerger.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @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.
 */
public Policy merge(final Collection<Policy> policies) {
    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>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example 9
Source File: PolicyIntersector.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param policies collection of policies to be intersected. Must not be {@code null} nor empty, otherwise exception is thrown.
 * @return intersected policy as a result of perfromed policy intersection. A {@code null} value is never returned.
 *
 * @throws IllegalArgumentException in case {@code policies} argument is either {@code null} or empty collection.
 */
public Policy intersect(final Policy... policies) {
    if (policies == null || policies.length == 0) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0056_NEITHER_NULL_NOR_EMPTY_POLICY_COLLECTION_EXPECTED()));
    } else if (policies.length == 1) {
        return policies[0];
    }

    // 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;
    NamespaceVersion latestVersion = null;
    for (Policy tested : policies) {
        if (tested.isEmpty()) {
            found = true;
        } else {
            if (tested.isNull()) {
                found = true;
            }
            allPoliciesEmpty = false;
        }
        if (latestVersion == null) {
            latestVersion = tested.getNamespaceVersion();
        } else if (latestVersion.compareTo(tested.getNamespaceVersion()) < 0) {
            latestVersion = tested.getNamespaceVersion();
        }

        if (found && !allPoliciesEmpty) {
            return Policy.createNullPolicy(latestVersion, null, null);
        }
    }
    latestVersion = (latestVersion != null) ? latestVersion : NamespaceVersion.getLatestVersion();
    if (allPoliciesEmpty) {
        return Policy.createEmptyPolicy(latestVersion, null, null);
    }

    // simple tests didn't lead to final answer => let's performe some intersecting ;)
    final List<AssertionSet> finalAlternatives = new LinkedList<AssertionSet>(policies[0].getContent());
    final Queue<AssertionSet> testedAlternatives = new LinkedList<AssertionSet>();
    final List<AssertionSet> alternativesToMerge = new ArrayList<AssertionSet>(2);
    for (int i = 1; i < policies.length; i++) {
        final Collection<AssertionSet> currentAlternatives = policies[i].getContent();

        testedAlternatives.clear();
        testedAlternatives.addAll(finalAlternatives);
        finalAlternatives.clear();

        AssertionSet testedAlternative;
        while ((testedAlternative = testedAlternatives.poll()) != null) {
            for (AssertionSet currentAlternative : currentAlternatives) {
                if (testedAlternative.isCompatibleWith(currentAlternative, this.mode)) {
                    alternativesToMerge.add(testedAlternative);
                    alternativesToMerge.add(currentAlternative);
                    finalAlternatives.add(AssertionSet.createMergedAssertionSet(alternativesToMerge));
                    alternativesToMerge.clear();
                }
            }
        }
    }

    return Policy.createPolicy(latestVersion, null, null, finalAlternatives);
}
 
Example 10
Source File: PolicyIntersector.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param policies collection of policies to be intersected. Must not be {@code null} nor empty, otherwise exception is thrown.
 * @return intersected policy as a result of perfromed policy intersection. A {@code null} value is never returned.
 *
 * @throws IllegalArgumentException in case {@code policies} argument is either {@code null} or empty collection.
 */
public Policy intersect(final Policy... policies) {
    if (policies == null || policies.length == 0) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0056_NEITHER_NULL_NOR_EMPTY_POLICY_COLLECTION_EXPECTED()));
    } else if (policies.length == 1) {
        return policies[0];
    }

    // 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;
    NamespaceVersion latestVersion = null;
    for (Policy tested : policies) {
        if (tested.isEmpty()) {
            found = true;
        } else {
            if (tested.isNull()) {
                found = true;
            }
            allPoliciesEmpty = false;
        }
        if (latestVersion == null) {
            latestVersion = tested.getNamespaceVersion();
        } else if (latestVersion.compareTo(tested.getNamespaceVersion()) < 0) {
            latestVersion = tested.getNamespaceVersion();
        }

        if (found && !allPoliciesEmpty) {
            return Policy.createNullPolicy(latestVersion, null, null);
        }
    }
    latestVersion = (latestVersion != null) ? latestVersion : NamespaceVersion.getLatestVersion();
    if (allPoliciesEmpty) {
        return Policy.createEmptyPolicy(latestVersion, null, null);
    }

    // simple tests didn't lead to final answer => let's performe some intersecting ;)
    final List<AssertionSet> finalAlternatives = new LinkedList<AssertionSet>(policies[0].getContent());
    final Queue<AssertionSet> testedAlternatives = new LinkedList<AssertionSet>();
    final List<AssertionSet> alternativesToMerge = new ArrayList<AssertionSet>(2);
    for (int i = 1; i < policies.length; i++) {
        final Collection<AssertionSet> currentAlternatives = policies[i].getContent();

        testedAlternatives.clear();
        testedAlternatives.addAll(finalAlternatives);
        finalAlternatives.clear();

        AssertionSet testedAlternative;
        while ((testedAlternative = testedAlternatives.poll()) != null) {
            for (AssertionSet currentAlternative : currentAlternatives) {
                if (testedAlternative.isCompatibleWith(currentAlternative, this.mode)) {
                    alternativesToMerge.add(testedAlternative);
                    alternativesToMerge.add(currentAlternative);
                    finalAlternatives.add(AssertionSet.createMergedAssertionSet(alternativesToMerge));
                    alternativesToMerge.clear();
                }
            }
        }
    }

    return Policy.createPolicy(latestVersion, null, null, finalAlternatives);
}
 
Example 11
Source File: PolicyIntersector.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param policies collection of policies to be intersected. Must not be {@code null} nor empty, otherwise exception is thrown.
 * @return intersected policy as a result of perfromed policy intersection. A {@code null} value is never returned.
 *
 * @throws IllegalArgumentException in case {@code policies} argument is either {@code null} or empty collection.
 */
public Policy intersect(final Policy... policies) {
    if (policies == null || policies.length == 0) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0056_NEITHER_NULL_NOR_EMPTY_POLICY_COLLECTION_EXPECTED()));
    } else if (policies.length == 1) {
        return policies[0];
    }

    // 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;
    NamespaceVersion latestVersion = null;
    for (Policy tested : policies) {
        if (tested.isEmpty()) {
            found = true;
        } else {
            if (tested.isNull()) {
                found = true;
            }
            allPoliciesEmpty = false;
        }
        if (latestVersion == null) {
            latestVersion = tested.getNamespaceVersion();
        } else if (latestVersion.compareTo(tested.getNamespaceVersion()) < 0) {
            latestVersion = tested.getNamespaceVersion();
        }

        if (found && !allPoliciesEmpty) {
            return Policy.createNullPolicy(latestVersion, null, null);
        }
    }
    latestVersion = (latestVersion != null) ? latestVersion : NamespaceVersion.getLatestVersion();
    if (allPoliciesEmpty) {
        return Policy.createEmptyPolicy(latestVersion, null, null);
    }

    // simple tests didn't lead to final answer => let's performe some intersecting ;)
    final List<AssertionSet> finalAlternatives = new LinkedList<AssertionSet>(policies[0].getContent());
    final Queue<AssertionSet> testedAlternatives = new LinkedList<AssertionSet>();
    final List<AssertionSet> alternativesToMerge = new ArrayList<AssertionSet>(2);
    for (int i = 1; i < policies.length; i++) {
        final Collection<AssertionSet> currentAlternatives = policies[i].getContent();

        testedAlternatives.clear();
        testedAlternatives.addAll(finalAlternatives);
        finalAlternatives.clear();

        AssertionSet testedAlternative;
        while ((testedAlternative = testedAlternatives.poll()) != null) {
            for (AssertionSet currentAlternative : currentAlternatives) {
                if (testedAlternative.isCompatibleWith(currentAlternative, this.mode)) {
                    alternativesToMerge.add(testedAlternative);
                    alternativesToMerge.add(currentAlternative);
                    finalAlternatives.add(AssertionSet.createMergedAssertionSet(alternativesToMerge));
                    alternativesToMerge.clear();
                }
            }
        }
    }

    return Policy.createPolicy(latestVersion, null, null, finalAlternatives);
}
 
Example 12
Source File: PolicyIntersector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param policies collection of policies to be intersected. Must not be {@code null} nor empty, otherwise exception is thrown.
 * @return intersected policy as a result of perfromed policy intersection. A {@code null} value is never returned.
 *
 * @throws IllegalArgumentException in case {@code policies} argument is either {@code null} or empty collection.
 */
public Policy intersect(final Policy... policies) {
    if (policies == null || policies.length == 0) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0056_NEITHER_NULL_NOR_EMPTY_POLICY_COLLECTION_EXPECTED()));
    } else if (policies.length == 1) {
        return policies[0];
    }

    // 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;
    NamespaceVersion latestVersion = null;
    for (Policy tested : policies) {
        if (tested.isEmpty()) {
            found = true;
        } else {
            if (tested.isNull()) {
                found = true;
            }
            allPoliciesEmpty = false;
        }
        if (latestVersion == null) {
            latestVersion = tested.getNamespaceVersion();
        } else if (latestVersion.compareTo(tested.getNamespaceVersion()) < 0) {
            latestVersion = tested.getNamespaceVersion();
        }

        if (found && !allPoliciesEmpty) {
            return Policy.createNullPolicy(latestVersion, null, null);
        }
    }
    latestVersion = (latestVersion != null) ? latestVersion : NamespaceVersion.getLatestVersion();
    if (allPoliciesEmpty) {
        return Policy.createEmptyPolicy(latestVersion, null, null);
    }

    // simple tests didn't lead to final answer => let's performe some intersecting ;)
    final List<AssertionSet> finalAlternatives = new LinkedList<AssertionSet>(policies[0].getContent());
    final Queue<AssertionSet> testedAlternatives = new LinkedList<AssertionSet>();
    final List<AssertionSet> alternativesToMerge = new ArrayList<AssertionSet>(2);
    for (int i = 1; i < policies.length; i++) {
        final Collection<AssertionSet> currentAlternatives = policies[i].getContent();

        testedAlternatives.clear();
        testedAlternatives.addAll(finalAlternatives);
        finalAlternatives.clear();

        AssertionSet testedAlternative;
        while ((testedAlternative = testedAlternatives.poll()) != null) {
            for (AssertionSet currentAlternative : currentAlternatives) {
                if (testedAlternative.isCompatibleWith(currentAlternative, this.mode)) {
                    alternativesToMerge.add(testedAlternative);
                    alternativesToMerge.add(currentAlternative);
                    finalAlternatives.add(AssertionSet.createMergedAssertionSet(alternativesToMerge));
                    alternativesToMerge.clear();
                }
            }
        }
    }

    return Policy.createPolicy(latestVersion, null, null, finalAlternatives);
}
 
Example 13
Source File: PolicyIntersector.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param policies collection of policies to be intersected. Must not be {@code null} nor empty, otherwise exception is thrown.
 * @return intersected policy as a result of perfromed policy intersection. A {@code null} value is never returned.
 *
 * @throws IllegalArgumentException in case {@code policies} argument is either {@code null} or empty collection.
 */
public Policy intersect(final Policy... policies) {
    if (policies == null || policies.length == 0) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0056_NEITHER_NULL_NOR_EMPTY_POLICY_COLLECTION_EXPECTED()));
    } else if (policies.length == 1) {
        return policies[0];
    }

    // 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;
    NamespaceVersion latestVersion = null;
    for (Policy tested : policies) {
        if (tested.isEmpty()) {
            found = true;
        } else {
            if (tested.isNull()) {
                found = true;
            }
            allPoliciesEmpty = false;
        }
        if (latestVersion == null) {
            latestVersion = tested.getNamespaceVersion();
        } else if (latestVersion.compareTo(tested.getNamespaceVersion()) < 0) {
            latestVersion = tested.getNamespaceVersion();
        }

        if (found && !allPoliciesEmpty) {
            return Policy.createNullPolicy(latestVersion, null, null);
        }
    }
    latestVersion = (latestVersion != null) ? latestVersion : NamespaceVersion.getLatestVersion();
    if (allPoliciesEmpty) {
        return Policy.createEmptyPolicy(latestVersion, null, null);
    }

    // simple tests didn't lead to final answer => let's performe some intersecting ;)
    final List<AssertionSet> finalAlternatives = new LinkedList<AssertionSet>(policies[0].getContent());
    final Queue<AssertionSet> testedAlternatives = new LinkedList<AssertionSet>();
    final List<AssertionSet> alternativesToMerge = new ArrayList<AssertionSet>(2);
    for (int i = 1; i < policies.length; i++) {
        final Collection<AssertionSet> currentAlternatives = policies[i].getContent();

        testedAlternatives.clear();
        testedAlternatives.addAll(finalAlternatives);
        finalAlternatives.clear();

        AssertionSet testedAlternative;
        while ((testedAlternative = testedAlternatives.poll()) != null) {
            for (AssertionSet currentAlternative : currentAlternatives) {
                if (testedAlternative.isCompatibleWith(currentAlternative, this.mode)) {
                    alternativesToMerge.add(testedAlternative);
                    alternativesToMerge.add(currentAlternative);
                    finalAlternatives.add(AssertionSet.createMergedAssertionSet(alternativesToMerge));
                    alternativesToMerge.clear();
                }
            }
        }
    }

    return Policy.createPolicy(latestVersion, null, null, finalAlternatives);
}
 
Example 14
Source File: PolicyIntersector.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param policies collection of policies to be intersected. Must not be {@code null} nor empty, otherwise exception is thrown.
 * @return intersected policy as a result of perfromed policy intersection. A {@code null} value is never returned.
 *
 * @throws IllegalArgumentException in case {@code policies} argument is either {@code null} or empty collection.
 */
public Policy intersect(final Policy... policies) {
    if (policies == null || policies.length == 0) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0056_NEITHER_NULL_NOR_EMPTY_POLICY_COLLECTION_EXPECTED()));
    } else if (policies.length == 1) {
        return policies[0];
    }

    // 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;
    NamespaceVersion latestVersion = null;
    for (Policy tested : policies) {
        if (tested.isEmpty()) {
            found = true;
        } else {
            if (tested.isNull()) {
                found = true;
            }
            allPoliciesEmpty = false;
        }
        if (latestVersion == null) {
            latestVersion = tested.getNamespaceVersion();
        } else if (latestVersion.compareTo(tested.getNamespaceVersion()) < 0) {
            latestVersion = tested.getNamespaceVersion();
        }

        if (found && !allPoliciesEmpty) {
            return Policy.createNullPolicy(latestVersion, null, null);
        }
    }
    latestVersion = (latestVersion != null) ? latestVersion : NamespaceVersion.getLatestVersion();
    if (allPoliciesEmpty) {
        return Policy.createEmptyPolicy(latestVersion, null, null);
    }

    // simple tests didn't lead to final answer => let's performe some intersecting ;)
    final List<AssertionSet> finalAlternatives = new LinkedList<AssertionSet>(policies[0].getContent());
    final Queue<AssertionSet> testedAlternatives = new LinkedList<AssertionSet>();
    final List<AssertionSet> alternativesToMerge = new ArrayList<AssertionSet>(2);
    for (int i = 1; i < policies.length; i++) {
        final Collection<AssertionSet> currentAlternatives = policies[i].getContent();

        testedAlternatives.clear();
        testedAlternatives.addAll(finalAlternatives);
        finalAlternatives.clear();

        AssertionSet testedAlternative;
        while ((testedAlternative = testedAlternatives.poll()) != null) {
            for (AssertionSet currentAlternative : currentAlternatives) {
                if (testedAlternative.isCompatibleWith(currentAlternative, this.mode)) {
                    alternativesToMerge.add(testedAlternative);
                    alternativesToMerge.add(currentAlternative);
                    finalAlternatives.add(AssertionSet.createMergedAssertionSet(alternativesToMerge));
                    alternativesToMerge.clear();
                }
            }
        }
    }

    return Policy.createPolicy(latestVersion, null, null, finalAlternatives);
}
 
Example 15
Source File: PolicyIntersector.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param policies collection of policies to be intersected. Must not be {@code null} nor empty, otherwise exception is thrown.
 * @return intersected policy as a result of perfromed policy intersection. A {@code null} value is never returned.
 *
 * @throws IllegalArgumentException in case {@code policies} argument is either {@code null} or empty collection.
 */
public Policy intersect(final Policy... policies) {
    if (policies == null || policies.length == 0) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0056_NEITHER_NULL_NOR_EMPTY_POLICY_COLLECTION_EXPECTED()));
    } else if (policies.length == 1) {
        return policies[0];
    }

    // 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;
    NamespaceVersion latestVersion = null;
    for (Policy tested : policies) {
        if (tested.isEmpty()) {
            found = true;
        } else {
            if (tested.isNull()) {
                found = true;
            }
            allPoliciesEmpty = false;
        }
        if (latestVersion == null) {
            latestVersion = tested.getNamespaceVersion();
        } else if (latestVersion.compareTo(tested.getNamespaceVersion()) < 0) {
            latestVersion = tested.getNamespaceVersion();
        }

        if (found && !allPoliciesEmpty) {
            return Policy.createNullPolicy(latestVersion, null, null);
        }
    }
    latestVersion = (latestVersion != null) ? latestVersion : NamespaceVersion.getLatestVersion();
    if (allPoliciesEmpty) {
        return Policy.createEmptyPolicy(latestVersion, null, null);
    }

    // simple tests didn't lead to final answer => let's performe some intersecting ;)
    final List<AssertionSet> finalAlternatives = new LinkedList<AssertionSet>(policies[0].getContent());
    final Queue<AssertionSet> testedAlternatives = new LinkedList<AssertionSet>();
    final List<AssertionSet> alternativesToMerge = new ArrayList<AssertionSet>(2);
    for (int i = 1; i < policies.length; i++) {
        final Collection<AssertionSet> currentAlternatives = policies[i].getContent();

        testedAlternatives.clear();
        testedAlternatives.addAll(finalAlternatives);
        finalAlternatives.clear();

        AssertionSet testedAlternative;
        while ((testedAlternative = testedAlternatives.poll()) != null) {
            for (AssertionSet currentAlternative : currentAlternatives) {
                if (testedAlternative.isCompatibleWith(currentAlternative, this.mode)) {
                    alternativesToMerge.add(testedAlternative);
                    alternativesToMerge.add(currentAlternative);
                    finalAlternatives.add(AssertionSet.createMergedAssertionSet(alternativesToMerge));
                    alternativesToMerge.clear();
                }
            }
        }
    }

    return Policy.createPolicy(latestVersion, null, null, finalAlternatives);
}
 
Example 16
Source File: PolicyIntersector.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param policies collection of policies to be intersected. Must not be {@code null} nor empty, otherwise exception is thrown.
 * @return intersected policy as a result of perfromed policy intersection. A {@code null} value is never returned.
 *
 * @throws IllegalArgumentException in case {@code policies} argument is either {@code null} or empty collection.
 */
public Policy intersect(final Policy... policies) {
    if (policies == null || policies.length == 0) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0056_NEITHER_NULL_NOR_EMPTY_POLICY_COLLECTION_EXPECTED()));
    } else if (policies.length == 1) {
        return policies[0];
    }

    // 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;
    NamespaceVersion latestVersion = null;
    for (Policy tested : policies) {
        if (tested.isEmpty()) {
            found = true;
        } else {
            if (tested.isNull()) {
                found = true;
            }
            allPoliciesEmpty = false;
        }
        if (latestVersion == null) {
            latestVersion = tested.getNamespaceVersion();
        } else if (latestVersion.compareTo(tested.getNamespaceVersion()) < 0) {
            latestVersion = tested.getNamespaceVersion();
        }

        if (found && !allPoliciesEmpty) {
            return Policy.createNullPolicy(latestVersion, null, null);
        }
    }
    latestVersion = (latestVersion != null) ? latestVersion : NamespaceVersion.getLatestVersion();
    if (allPoliciesEmpty) {
        return Policy.createEmptyPolicy(latestVersion, null, null);
    }

    // simple tests didn't lead to final answer => let's performe some intersecting ;)
    final List<AssertionSet> finalAlternatives = new LinkedList<AssertionSet>(policies[0].getContent());
    final Queue<AssertionSet> testedAlternatives = new LinkedList<AssertionSet>();
    final List<AssertionSet> alternativesToMerge = new ArrayList<AssertionSet>(2);
    for (int i = 1; i < policies.length; i++) {
        final Collection<AssertionSet> currentAlternatives = policies[i].getContent();

        testedAlternatives.clear();
        testedAlternatives.addAll(finalAlternatives);
        finalAlternatives.clear();

        AssertionSet testedAlternative;
        while ((testedAlternative = testedAlternatives.poll()) != null) {
            for (AssertionSet currentAlternative : currentAlternatives) {
                if (testedAlternative.isCompatibleWith(currentAlternative, this.mode)) {
                    alternativesToMerge.add(testedAlternative);
                    alternativesToMerge.add(currentAlternative);
                    finalAlternatives.add(AssertionSet.createMergedAssertionSet(alternativesToMerge));
                    alternativesToMerge.clear();
                }
            }
        }
    }

    return Policy.createPolicy(latestVersion, null, null, finalAlternatives);
}