Search in sources :

Example 96 with OMElement

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

the class TestClose method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement rootElement = XMLSample.SIMPLE.getAdapter(XMLSampleAdapter.class).getDocumentElement(metaFactory);
    // get the first OMElement child
    OMNode omnode = rootElement.getFirstOMChild();
    while (!(omnode instanceof OMElement)) {
        omnode = omnode.getNextOMSibling();
    }
    // Close the element after building the element
    OMElement omElement = (OMElement) omnode;
    omElement.close(true);
    Iterator<OMNode> children = ((OMElement) omnode).getChildren();
    int childrenCount = 0;
    while (children.hasNext()) {
        if (children.next() instanceof OMElement) {
            childrenCount++;
        }
    }
    assertThat(childrenCount).isEqualTo(2);
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement) XMLSampleAdapter(org.apache.axiom.ts.om.XMLSampleAdapter)

Example 97 with OMElement

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

the class TestDeclareDefaultNamespaceConflict1 method runTest.

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

Example 98 with OMElement

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

the class TestDeclareNamespace1 method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement element = metaFactory.getOMFactory().createOMElement(new QName("test"));
    OMNamespace ns = element.declareNamespace("urn:ns1", "ns1");
    assertEquals("urn:ns1", ns.getNamespaceURI());
    assertEquals("ns1", ns.getPrefix());
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    assertTrue(it.hasNext());
    OMNamespace ns2 = it.next();
    assertEquals(ns, ns2);
    assertFalse(it.hasNext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 99 with OMElement

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

the class TestDeclareNamespaceInvalid1 method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement element = metaFactory.getOMFactory().createOMElement(new QName("test"));
    try {
        element.declareNamespace("", "ns");
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
    // Expected
    }
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 100 with OMElement

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

the class TestSetOMDocumentElementReplaceSame method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    OMElement root = factory.createOMElement("root", null, document);
    document.setOMDocumentElement(root);
    assertThat(document.getOMDocumentElement()).isSameAs(root);
    assertThat(root.getPreviousOMSibling()).isNull();
    assertThat(root.getNextOMSibling()).isNull();
    assertThat(root.getParent()).isSameAs(document);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

OMElement (org.apache.axiom.om.OMElement)379 OMFactory (org.apache.axiom.om.OMFactory)189 OMNamespace (org.apache.axiom.om.OMNamespace)101 QName (javax.xml.namespace.QName)90 StringReader (java.io.StringReader)63 OMNode (org.apache.axiom.om.OMNode)42 OMText (org.apache.axiom.om.OMText)40 XMLStreamReader (javax.xml.stream.XMLStreamReader)37 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)28 OMAttribute (org.apache.axiom.om.OMAttribute)26 StringWriter (java.io.StringWriter)23 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)21 OMDocument (org.apache.axiom.om.OMDocument)19 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)18 Element (org.w3c.dom.Element)18 DataHandler (javax.activation.DataHandler)17 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)16 InputStream (java.io.InputStream)15 OMException (org.apache.axiom.om.OMException)13 SOAPBody (org.apache.axiom.soap.SOAPBody)13