Search in sources :

Example 61 with OMNamespace

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

the class TestAddAttributeGeneratedPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace otherNS = factory.createOMNamespace("urn:ns2", "p");
    OMElement parent = factory.createOMElement("parent", otherNS);
    if (defaultNamespaceInScope) {
        parent.declareDefaultNamespace("urn:test");
    }
    OMElement element = factory.createOMElement("test", otherNS, parent);
    OMAttribute attr = element.addAttribute("attr", "value", factory.createOMNamespace("urn:test", null));
    OMNamespace ns = attr.getNamespace();
    assertTrue(ns.getPrefix().length() > 0);
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    assertTrue(it.hasNext());
    assertEquals(ns, it.next());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 62 with OMNamespace

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

the class TestAddAttributeReplace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    // Use same namespace URI but different prefixes
    OMNamespace ns1 = factory.createOMNamespace("urn:ns", "p1");
    OMNamespace ns2 = factory.createOMNamespace("urn:ns", "p2");
    OMElement element = factory.createOMElement(new QName("test"));
    OMAttribute att1 = strategy.addAttribute(element, "test", ns1, "value1");
    OMAttribute att2 = strategy.addAttribute(element, "test", ns2, "value2");
    Iterator<OMAttribute> it = element.getAllAttributes();
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isSameAs(att2);
    assertThat(it.hasNext()).isFalse();
    assertThat(att1.getOwner()).isNull();
    assertThat(att2.getOwner()).isSameAs(element);
    assertThat(att1).hasValue("value1");
    assertThat(att2).hasValue("value2");
}
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) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 63 with OMNamespace

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

the class TestAddAttributeWithExistingNamespaceDeclarationInScope method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement root = factory.createOMElement(new QName("test"));
    OMNamespace ns = factory.createOMNamespace("urn:ns", "p");
    root.declareNamespace(ns);
    OMElement child = factory.createOMElement(new QName("test"), root);
    strategy.addAttribute(child, "test", ns, "test");
    Iterator<OMNamespace> it = child.getAllDeclaredNamespaces();
    assertFalse(it.hasNext());
}
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 64 with OMNamespace

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

the class TestFindNamespaceURIWithPrefixUndeclaring method runTest.

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

Example 65 with OMNamespace

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

the class TestDeclareNamespaceWithEmptyPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement(new QName("test"));
    OMNamespace ns = element.declareNamespace("urn:ns", "");
    assertThat(ns.getNamespaceURI()).isEqualTo("urn:ns");
    assertThat(ns.getPrefix()).isEmpty();
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    assertThat(it.hasNext()).isTrue();
    OMNamespace ns2 = it.next();
    assertThat(ns2).isEqualTo(ns);
    assertThat(it.hasNext()).isFalse();
}
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