Search in sources :

Example 51 with OMNamespace

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

the class TestCreateOMElementWithNamespaceInScope2 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", "urn:test", "p1");
    OMElement child = variant.createOMElement(factory, parent, "child", "urn:test", "p2");
    OMNamespace ns = factory.createOMNamespace("urn:test", "p2");
    assertEquals(ns, child.getNamespace());
    Iterator<OMNamespace> it = child.getAllDeclaredNamespaces();
    assertTrue(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 52 with OMNamespace

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

the class TestSerialization method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory fac = metaFactory.getOMFactory();
    OMNamespace nsParent = createNamespace(fac, parent);
    OMNamespace nsChildren = createNamespace(fac, children);
    OMElement personElem = fac.createOMElement("person", nsParent);
    OMElement nameElem = fac.createOMElement("name", nsChildren);
    nameElem.setText("John");
    OMElement ageElem = fac.createOMElement("age", nsChildren);
    ageElem.setText("34");
    OMElement weightElem = fac.createOMElement("weight", nsChildren);
    weightElem.setText("50");
    //Add children to the person element
    personElem.addChild(nameElem);
    personElem.addChild(ageElem);
    personElem.addChild(weightElem);
    assertEquals(expected, personElem.toString());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 53 with OMNamespace

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

the class TestCreateOMAttributeWithInvalidNamespace2 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("urn:test", "");
    try {
        factory.createOMAttribute("attr", ns, "value");
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
        assertEquals("Cannot create an unprefixed attribute with a namespace", ex.getMessage());
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace)

Example 54 with OMNamespace

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

the class TestCreateOMElementWithNonDefaultNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = variant.createOMElement(factory, parentSupplier.createParent(factory), "test", "urn:ns", "ns");
    assertTrue(element.isComplete());
    assertEquals("test", element.getLocalName());
    OMNamespace ns = factory.createOMNamespace("urn:ns", "ns");
    assertEquals(ns, element.getNamespace());
    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)

Example 55 with OMNamespace

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

the class TestCreateOMElementWithoutNamespaceNullPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = variant.createOMElement(factory, parentSupplier.createParent(factory), "test", "", null);
    assertEquals("test", element.getLocalName());
    assertNull(element.getNamespace());
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) 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