Search in sources :

Example 96 with OMNamespace

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

the class TestDeclareDefaultNamespaceConflict2 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("urn:ns1", "");
    OMElement element = factory.createOMElement("test", ns);
    try {
        element.declareDefaultNamespace("urn:ns2");
        fail("Expected OMException");
    } catch (OMException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException)

Example 97 with OMNamespace

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

the class TestGetFirstChildWithName method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns1 = factory.createOMNamespace("urn:ns1", "ns1");
    OMNamespace ns2 = factory.createOMNamespace("urn:ns2", "ns2");
    OMElement parent = factory.createOMElement("root", null);
    OMElement child1 = factory.createOMElement("a", ns1, parent);
    factory.createOMComment(parent, "some comment");
    OMElement child2 = factory.createOMElement("b", ns2, parent);
    OMElement child3 = factory.createOMElement("b", ns1, parent);
    OMElement child4 = factory.createOMElement("c", null, parent);
    factory.createOMElement("a", ns1, parent);
    // Check that it's really the first element that is returned
    assertSame(child1, parent.getFirstChildWithName(new QName("urn:ns1", "a")));
    // Test with a child that is not the first one
    assertSame(child2, parent.getFirstChildWithName(new QName("urn:ns2", "b")));
    // Check that the namespace URI is taken into account
    assertNull(parent.getFirstChildWithName(new QName("b")));
    // Check that the prefix of the given QName is not taken into account
    assertSame(child3, parent.getFirstChildWithName(new QName("urn:ns1", "b", "ns2")));
    // Test with null namespace
    assertSame(child4, parent.getFirstChildWithName(new QName("c")));
}
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 98 with OMNamespace

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

the class TestGetDefaultNamespace2 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", "urn:test", "");
    OMElement child = factory.createOMElement("child", null, parent);
    OMNamespace ns = child.getDefaultNamespace();
    assertNull(ns);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 99 with OMNamespace

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

the class TestGetAllDeclaredNamespaces method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<e xmlns:p='urn:test' p:attr='test'/>");
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    assertTrue(it.hasNext());
    OMNamespace ns = it.next();
    assertEquals("p", ns.getPrefix());
    assertEquals("urn:test", ns.getNamespaceURI());
    assertFalse(it.hasNext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 100 with OMNamespace

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

the class TestGetAllDeclaredNamespacesNoSuchElementException method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<e xmlns:p='urn:test' p:attr='test'/>");
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    it.next();
    try {
        it.next();
        fail("Expected NoSuchElementException");
    } catch (NoSuchElementException ex) {
    // Expected
    }
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

OMNamespace (org.apache.axiom.om.OMNamespace)164 OMElement (org.apache.axiom.om.OMElement)101 OMFactory (org.apache.axiom.om.OMFactory)94 QName (javax.xml.namespace.QName)33 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)20 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