Search in sources :

Example 1 with PolicyContainingPrimitiveAssertion

use of org.apache.neethi.builders.PolicyContainingPrimitiveAssertion in project cxf by apache.

the class AddressingAssertionBuilder method build.

public Assertion build(Element elem, AssertionBuilderFactory factory) {
    String localName = elem.getLocalName();
    QName qn = new QName(elem.getNamespaceURI(), localName);
    boolean optional = false;
    Attr attribute = PolicyConstants.findOptionalAttribute(elem);
    if (attribute != null) {
        optional = Boolean.valueOf(attribute.getValue());
    }
    if (MetadataConstants.ADDRESSING_ASSERTION_QNAME.equals(qn) || MetadataConstants.ADDRESSING_ASSERTION_QNAME_0705.equals(qn)) {
        Assertion nap = new XMLPrimitiveAssertionBuilder() {

            public Assertion newPrimitiveAssertion(Element element, Map<QName, String> mp) {
                return new PrimitiveAssertion(MetadataConstants.ADDRESSING_ASSERTION_QNAME, isOptional(element), isIgnorable(element), mp);
            }

            public Assertion newPolicyContainingAssertion(Element element, Map<QName, String> mp, Policy policy) {
                return new PolicyContainingPrimitiveAssertion(MetadataConstants.ADDRESSING_ASSERTION_QNAME, isOptional(element), isIgnorable(element), mp, policy);
            }
        }.build(elem, factory);
        if (!(nap instanceof PolicyContainingPrimitiveAssertion || nap instanceof org.apache.neethi.builders.PrimitiveAssertion)) {
            // this happens when neethi fails to recognize the specified addressing policy element
            LOG.warning("Unable to recognize the addressing policy");
        }
        return nap;
    } else if (MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME.equals(qn) || MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME_0705.equals(qn)) {
        return new PrimitiveAssertion(MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME, optional);
    } else if (MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME.getLocalPart().equals(localName) || MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME_0705.getLocalPart().equals(localName)) {
        return new PrimitiveAssertion(MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME, optional);
    }
    return null;
}
Also used : Policy(org.apache.neethi.Policy) QName(javax.xml.namespace.QName) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Element(org.w3c.dom.Element) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) Attr(org.w3c.dom.Attr) XMLPrimitiveAssertionBuilder(org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion)

Example 2 with PolicyContainingPrimitiveAssertion

use of org.apache.neethi.builders.PolicyContainingPrimitiveAssertion in project cxf by apache.

the class AssertionInfoMapTest method testAllAssertionsIn.

@Test
public void testAllAssertionsIn() {
    Policy nested = new Policy();
    Assertion nb = new PrimitiveAssertion(new QName("http://x.y.z", "b"));
    nested.addAssertion(nb);
    Policy p = new Policy();
    Assertion a1 = new PrimitiveAssertion(new QName("http://x.y.z", "a"));
    Assertion a2 = new PrimitiveAssertion(new QName("http://x.y.z", "a"));
    Assertion b = new PrimitiveAssertion(new QName("http://x.y.z", "b"));
    Assertion c = new PolicyContainingPrimitiveAssertion(new QName("http://x.y.z", "c"), false, false, nested);
    All alt1 = new All();
    alt1.addAssertion(a1);
    alt1.addAssertion(b);
    All alt2 = new All();
    alt1.addAssertion(a2);
    alt2.addAssertion(c);
    ExactlyOne ea = new ExactlyOne();
    ea.addPolicyComponent(alt1);
    ea.addPolicyComponent(alt2);
    p.addPolicyComponent(ea);
    AssertionInfoMap aim = new AssertionInfoMap(p);
    Collection<AssertionInfo> listA = aim.getAssertionInfo(new QName("http://x.y.z", "a"));
    assertEquals("2 A assertions should've been added", 2, listA.size());
    AssertionInfo[] ais = listA.toArray(new AssertionInfo[] {});
    assertTrue("Two different A instances should be added", ais[0].getAssertion() == a1 && ais[1].getAssertion() == a2 || ais[0].getAssertion() == a2 && ais[1].getAssertion() == a1);
    Collection<AssertionInfo> listB = aim.getAssertionInfo(new QName("http://x.y.z", "b"));
    assertEquals("2 B assertions should've been added", 2, listB.size());
    ais = listB.toArray(new AssertionInfo[] {});
    assertTrue("Two different B instances should be added", ais[0].getAssertion() == nb && ais[1].getAssertion() == b || ais[0].getAssertion() == b && ais[1].getAssertion() == nb);
    Collection<AssertionInfo> listC = aim.getAssertionInfo(new QName("http://x.y.z", "c"));
    assertEquals("1 C assertion should've been added", 1, listC.size());
    ais = listC.toArray(new AssertionInfo[] {});
    assertSame("One C instances should be added", ais[0].getAssertion(), c);
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) QName(javax.xml.namespace.QName) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) ExactlyOne(org.apache.neethi.ExactlyOne) Test(org.junit.Test)

Example 3 with PolicyContainingPrimitiveAssertion

use of org.apache.neethi.builders.PolicyContainingPrimitiveAssertion in project cxf by apache.

the class RM12AssertionBuilder method build.

/**
 * @see org.apache.neethi.builders.AssertionBuilder#build(org.w3c.dom.Element,
 *  org.apache.neethi.AssertionBuilderFactory)
 */
public Assertion build(Element elem, AssertionBuilderFactory factory) throws IllegalArgumentException {
    Assertion assertion = null;
    if (RM11Constants.WSRMP_NAMESPACE_URI.equals(elem.getNamespaceURI())) {
        boolean optional = XMLPrimitiveAssertionBuilder.isOptional(elem);
        String lname = elem.getLocalName();
        if (RMConstants.RMASSERTION_NAME.equals(lname)) {
            // top-level RMAssertion, with nested policy
            XMLPrimitiveAssertionBuilder nesting = new XMLPrimitiveAssertionBuilder() {

                public Assertion newPrimitiveAssertion(Element element, Map<QName, String> mp) {
                    return new PrimitiveAssertion(RM11Constants.WSRMP_RMASSERTION_QNAME, isOptional(element), isIgnorable(element), mp);
                }

                public Assertion newPolicyContainingAssertion(Element element, Map<QName, String> mp, Policy policy) {
                    return new PolicyContainingPrimitiveAssertion(RM11Constants.WSRMP_RMASSERTION_QNAME, isOptional(element), isIgnorable(element), mp, policy);
                }
            };
            assertion = nesting.build(elem, factory);
        } else if (SEQUENCESTR_NAME.equals(lname)) {
            assertion = new PrimitiveAssertion(SEQSTR_QNAME, optional);
        } else if (SEQUENCETRANSEC_NAME.equals(lname)) {
            assertion = new PrimitiveAssertion(SEQTRANSSEC_QNAME, optional);
        } else if (DELIVERYASSURANCE_NAME.equals(lname)) {
            // DeliveryAssurance, with nested policy
            XMLPrimitiveAssertionBuilder nesting = new XMLPrimitiveAssertionBuilder() {

                public Assertion newPrimitiveAssertion(Element element, Map<QName, String> mp) {
                    return new PrimitiveAssertion(DELIVERYASSURANCE_QNAME, isOptional(element), isIgnorable(element), mp);
                }

                public Assertion newPolicyContainingAssertion(Element element, Map<QName, String> mp, Policy policy) {
                    return new PolicyContainingPrimitiveAssertion(DELIVERYASSURANCE_QNAME, isOptional(element), isIgnorable(element), mp, policy);
                }
            };
            assertion = nesting.build(elem, factory);
        } else if (EXACTLYONCE_NAME.equals(lname)) {
            assertion = new PrimitiveAssertion(EXACTLYONCE_QNAME, optional);
        } else if (ATLEASTONCE_NAME.equals(lname)) {
            assertion = new PrimitiveAssertion(ATLEASTONCE_QNAME, optional);
        } else if (ATMOSTONCE_NAME.equals(lname)) {
            assertion = new PrimitiveAssertion(ATMOSTONCE_QNAME, optional);
        } else if (INORDER_NAME.equals(lname)) {
            assertion = new PrimitiveAssertion(INORDER_QNAME, optional);
        }
    }
    return assertion;
}
Also used : Policy(org.apache.neethi.Policy) XMLPrimitiveAssertionBuilder(org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) Map(java.util.Map)

Aggregations

QName (javax.xml.namespace.QName)3 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)3 Assertion (org.apache.neethi.Assertion)3 Policy (org.apache.neethi.Policy)3 PolicyContainingPrimitiveAssertion (org.apache.neethi.builders.PolicyContainingPrimitiveAssertion)3 XMLPrimitiveAssertionBuilder (org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder)2 Element (org.w3c.dom.Element)2 Map (java.util.Map)1 All (org.apache.neethi.All)1 ExactlyOne (org.apache.neethi.ExactlyOne)1 Test (org.junit.Test)1 Attr (org.w3c.dom.Attr)1