Search in sources :

Example 31 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestGetNamespacesInScope method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<a xmlns:ns1='urn:ns1'><b xmlns:ns2='urn:ns2'/></a>");
    boolean ns1seen = false;
    boolean ns2seen = false;
    Iterator<OMNamespace> it = element.getFirstElement().getNamespacesInScope();
    int count = 0;
    while (it.hasNext()) {
        OMNamespace ns = it.next();
        count++;
        if (ns.getPrefix().equals("ns1")) {
            ns1seen = true;
            assertEquals("urn:ns1", ns.getNamespaceURI());
        } else if (ns.getPrefix().equals("ns2")) {
            ns2seen = true;
            assertEquals("urn:ns2", ns.getNamespaceURI());
        } else {
            fail("Unexpected prefix: " + ns.getPrefix());
        }
    }
    assertEquals("Number of namespaces in scope", 2, count);
    assertTrue(ns1seen);
    assertTrue(ns2seen);
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 32 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestMultipleDefaultNS method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory omFactory = metaFactory.getOMFactory();
    OMNamespace defaultNS1 = omFactory.createOMNamespace("http://defaultNS1.org", null);
    OMNamespace defaultNS2 = omFactory.createOMNamespace("http://defaultNS2.org", null);
    OMElement omElementOne = omFactory.createOMElement("DocumentElement", omFactory.createOMNamespace("http://defaultNS1.org", ""));
    OMElement omElementOneChild = omFactory.createOMElement("ChildOne", null, omElementOne);
    OMElement omElementTwo = omFactory.createOMElement("Foo", defaultNS2, omElementOne);
    omElementTwo.declareDefaultNamespace("http://defaultNS2.org");
    OMElement omElementTwoChild = omFactory.createOMElement("ChildOne", null, omElementTwo);
    OMElement omElementThree = omFactory.createOMElement("Bar", defaultNS1, omElementTwo);
    omElementThree.declareDefaultNamespace("http://defaultNS1.org");
    OMNamespace omElementOneChildNS = omElementOneChild.getNamespace();
    OMNamespace omElementTwoChildNS = omElementTwoChild.getNamespace();
    // TODO: LLOM's and DOOM's behaviors are slightly different here; need to check if both are allowed
    assertTrue(omElementOneChildNS == null || "".equals(omElementOneChildNS.getNamespaceURI()));
    assertTrue(omElementTwoChildNS == null || "".equals(omElementTwoChildNS.getNamespaceURI()));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 33 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestGetChildrenWithName3 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace testNamespace = factory.createOMNamespace("http://test.ws.org", "test");
    OMElement documentElement = factory.createOMElement("Employees", testNamespace);
    documentElement.declareNamespace(testNamespace);
    factory.createOMText(documentElement, " ");
    OMElement e = factory.createOMElement("Employee", testNamespace, documentElement);
    e.setText("Apache Developer");
    Iterator<OMElement> childrenIter = documentElement.getChildrenWithName(new QName("http://test.ws.org", "Employee", "test"));
    // should walk past OMText
    OMElement employee = childrenIter.next();
    assertEquals("Employee test was incorrect", employee.getText(), "Apache Developer");
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 34 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestGetChildrenWithName4 method runTest.

@Override
protected void runTest() throws Throwable {
    // Create a document with 2 children, each named "sample" but
    // have different namespaces.
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace a = factory.createOMNamespace(NS_A, "a");
    OMNamespace b = factory.createOMNamespace(NS_B, "b");
    OMElement documentElement = factory.createOMElement("Document", a);
    factory.createOMElement("sample", a, documentElement);
    factory.createOMElement("sample", b, documentElement);
    // Test for fully qualified names
    QName qName = new QName(NS_A, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
    qName = new QName(NS_B, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
    qName = new QName(NS_C, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
    // Test for QName with no namespace.
    // Axiom 1.2.x implemented a legacy behavior where an empty namespace URI was interpreted
    // as a wildcard (see AXIOM-11). In Axiom 1.3.x, the matching is always strict.
    qName = new QName("", "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
    // Now add an unqualified sample element to the documentElement
    factory.createOMElement("sample", null, documentElement);
    // Repeat the tests
    qName = new QName(NS_A, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
    qName = new QName(NS_B, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
    qName = new QName(NS_C, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
    // Since there actually is an unqualified element child, the most accurate
    // interpretation of getChildrenWithName should be to return this one 
    // child
    qName = new QName("", "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 35 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestGetDefaultNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", "urn:ns1", "");
    OMElement child = factory.createOMElement(new QName("urn:ns2", "child", "p"), parent);
    OMNamespace ns = child.getDefaultNamespace();
    assertNotNull(ns);
    assertEquals("", ns.getPrefix());
    assertEquals("urn:ns1", ns.getNamespaceURI());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMNamespace (org.apache.axiom.om.OMNamespace)171 OMElement (org.apache.axiom.om.OMElement)108 OMFactory (org.apache.axiom.om.OMFactory)101 QName (javax.xml.namespace.QName)34 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)22 OMAttribute (org.apache.axiom.om.OMAttribute)18 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)16 StringWriter (java.io.StringWriter)15 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)13 SOAPHeader (org.apache.axiom.soap.SOAPHeader)12 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)9 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 OMText (org.apache.axiom.om.OMText)7 Iterator (java.util.Iterator)6 SOAPBody (org.apache.axiom.soap.SOAPBody)6 StringReader (java.io.StringReader)5 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)5 HashSet (java.util.HashSet)4 OMDataSource (org.apache.axiom.om.OMDataSource)4 OMNode (org.apache.axiom.om.OMNode)4