Java Code Examples for org.apache.neethi.PolicyComponent#getType()

The following examples show how to use org.apache.neethi.PolicyComponent#getType() . 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: PolicyEngineImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
void addAssertions(PolicyComponent pc, boolean includeOptional,
                   Collection<Assertion> assertions) {

    if (Constants.TYPE_ASSERTION == pc.getType()) {
        Assertion a = (Assertion)pc;
        if (includeOptional || !a.isOptional()) {
            assertions.add((Assertion)pc);
        }
        return;
    }

    if (Constants.TYPE_POLICY_REF == pc.getType()) {
        PolicyReference pr = (PolicyReference)pc;
        pc = pr.normalize(registry, false);
    }

    PolicyOperator po = (PolicyOperator)pc;

    List<PolicyComponent> pcs = CastUtils.cast(po.getPolicyComponents(), PolicyComponent.class);
    for (PolicyComponent child : pcs) {
        addAssertions(child, includeOptional, assertions);
    }
}
 
Example 2
Source File: PolicyEngineImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Return a collection of all assertions used in the given policy component,
 * optionally including optional assertions.
 * The policy need not be normalised, so any policy references will have to be resolved.
 * @param pc the policy component
 * @param includeOptional flag indicating if optional assertions should be included
 * @return the assertions
 */
Collection<Assertion> getAssertions(PolicyComponent pc, boolean includeOptional) {

    Collection<Assertion> assertions = new ArrayList<>();

    if (Constants.TYPE_ASSERTION == pc.getType()) {
        Assertion a = (Assertion)pc;
        if (includeOptional || !a.isOptional()) {
            assertions.add(a);
        }
    } else {
        addAssertions(pc, includeOptional, assertions);
    }
    return assertions;
}
 
Example 3
Source File: PolicyUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void printPolicyComponent(PolicyComponent pc, StringBuilder buf, int level) {
    indent(buf, level);
    buf.append("type: ");
    buf.append(typeToString(pc.getType()));
    if (Constants.TYPE_ASSERTION == pc.getType()) {
        buf.append(' ');
        buf.append(((Assertion)pc).getName());
        if (((Assertion)pc).isOptional()) {
            buf.append(" (optional)");
        }
        buf.append(" (");
        buf.append(pc);
        buf.append(')');
        nl(buf);
        if (pc instanceof PolicyContainingAssertion) {
            PolicyComponent nested = ((PolicyContainingAssertion)pc).getPolicy();
            level++;
            printPolicyComponent(nested, buf, level);
            level--;
        }
    } else {
        level++;
        List<PolicyComponent> children = CastUtils.cast(((PolicyOperator)pc).getPolicyComponents(),
            PolicyComponent.class);
        nl(buf);
        for (PolicyComponent child : children) {
            printPolicyComponent(child, buf, level);
        }
        level--;
    }
}
 
Example 4
Source File: RM10AssertionBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equal(PolicyComponent policyComponent) {
    if (policyComponent.getType() != Constants.TYPE_ASSERTION
        || !getName().equals(((Assertion)policyComponent).getName())) {
        return false;
    }
    JaxbAssertion<RMAssertion> other =
            JaxbAssertion.cast((Assertion)policyComponent);
    return RMPolicyUtilities.equals(this.getData(), other.getData());
}
 
Example 5
Source File: HTTPServerAssertionBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equal(PolicyComponent policyComponent) {
    if (policyComponent == this) {
        return true;
    }
    if (policyComponent.getType() != Constants.TYPE_ASSERTION
        || !(policyComponent instanceof Assertion)
        || !getName().equals(((Assertion)policyComponent).getName())) {
        return false;
    }
    JaxbAssertion<HTTPServerPolicy> other = JaxbAssertion.cast((Assertion)policyComponent);
    return new ServerPolicyCalculator().equals(this.getData(), other.getData());
}
 
Example 6
Source File: HTTPClientAssertionBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equal(PolicyComponent policyComponent) {
    if (policyComponent == this) {
        return true;
    }
    if (policyComponent.getType() != Constants.TYPE_ASSERTION
        || !(policyComponent instanceof Assertion)
        || !getName().equals(((Assertion)policyComponent).getName())) {
        return false;
    }
    JaxbAssertion<HTTPClientPolicy> other = JaxbAssertion.cast((Assertion)policyComponent);
    return new ClientPolicyCalculator().equals(this.getData(), other.getData());
}