Search in sources :

Example 21 with OMNode

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

the class TestInsertSiblingBeforeSameParent method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory fac = metaFactory.getOMFactory();
    OMElement parent = fac.createOMElement("test", null);
    OMText text1 = fac.createOMText("text1");
    OMText text2 = fac.createOMText("text2");
    OMText text3 = fac.createOMText("text3");
    parent.addChild(text1);
    parent.addChild(text2);
    parent.addChild(text3);
    text2.insertSiblingBefore(text3);
    assertSame(parent, text3.getParent());
    Iterator<OMNode> it = parent.getChildren();
    assertSame(text1, it.next());
    assertSame(text3, it.next());
    assertSame(text2, it.next());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 22 with OMNode

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

the class TestBlobOMDataSource method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    String localName = "myPayload";
    String encoding = "utf-8";
    String payload = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
    OMNamespace ns = factory.createOMNamespace("urn://test", "tns");
    BlobOMDataSource ds = new BlobOMDataSource(Blobs.createBlob(payload.getBytes(encoding)), encoding);
    OMElement parent = factory.createOMElement("root", null);
    OMSourcedElement omse = factory.createOMElement(ds, localName, ns);
    parent.addChild(omse);
    OMNode firstChild = parent.getFirstOMChild();
    assertTrue("Expected OMSourcedElement child", firstChild instanceof OMSourcedElement);
    OMSourcedElement child = (OMSourcedElement) firstChild;
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    assertThat(child.getDataSource()).isSameAs(ds);
    // A BlobOMDataSource does not consume the backing object when read.
    // Thus getting the XMLStreamReader of the BlobOMDataSource should not 
    // cause expansion of the OMSourcedElement.
    XMLStreamReader reader = child.getXMLStreamReader();
    reader.next();
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    // Likewise, a BlobOMDataSource does not consume the backing object when 
    // written.  Thus serializing the OMSourcedElement should not cause the expansion
    // of the OMSourcedElement.
    assertTrue("The payload was not present in the output", parent.toString().indexOf(payload) > 0);
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    // If a consumer calls build or buildWithAttachments on the tree, the 
    // tree should not be expanded.
    parent.build();
    assertTrue("OMSourcedElement is expanded after build().  This is unexpected", !child.isExpanded());
    parent.buildWithAttachments();
    assertTrue("OMSourcedElement is expanded after buildWithAttachments().  This is unexpected", !child.isExpanded());
    // Test getting the raw bytes from the BlobOMDataSource.
    assertThat(child.getDataSource()).isSameAs(ds);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMNamespace(org.apache.axiom.om.OMNamespace) XMLStreamReader(javax.xml.stream.XMLStreamReader) BlobOMDataSource(org.apache.axiom.om.ds.BlobOMDataSource) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 23 with OMNode

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

the class TestGetNextOMSiblingAfterDiscard method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<element><!--comment--><a/><!--comment--></element>")).getDocumentElement();
    OMNode child = element.getFirstOMChild();
    element.discard();
    try {
        child.getNextOMSibling();
        fail("Expected NodeUnavailableException");
    } catch (NodeUnavailableException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) StringReader(java.io.StringReader) NodeUnavailableException(org.apache.axiom.om.NodeUnavailableException) OMElement(org.apache.axiom.om.OMElement)

Example 24 with OMNode

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

the class TestDetachFirstChild method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement root = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<root><a/><b/></root>");
    if (build) {
        root.build();
    } else {
        assertFalse(root.isComplete());
    }
    OMNode oldFirstChild = root.getFirstOMChild();
    assertNotNull(oldFirstChild);
    oldFirstChild.detach();
    OMNode newFirstChild = root.getFirstOMChild();
    assertNotNull(newFirstChild);
    assertNotSame(oldFirstChild, newFirstChild);
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement)

Example 25 with OMNode

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

the class TestInsertSiblingAfterSameParent method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory fac = metaFactory.getOMFactory();
    OMElement parent = fac.createOMElement("test", null);
    OMText text1 = fac.createOMText("text1");
    OMText text2 = fac.createOMText("text2");
    OMText text3 = fac.createOMText("text3");
    parent.addChild(text1);
    parent.addChild(text2);
    parent.addChild(text3);
    text1.insertSiblingAfter(text3);
    assertSame(parent, text3.getParent());
    Iterator<OMNode> it = parent.getChildren();
    assertSame(text1, it.next());
    assertSame(text3, it.next());
    assertSame(text2, it.next());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMNode (org.apache.axiom.om.OMNode)69 OMElement (org.apache.axiom.om.OMElement)42 StringReader (java.io.StringReader)16 OMFactory (org.apache.axiom.om.OMFactory)14 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)11 OMText (org.apache.axiom.om.OMText)10 OMDocument (org.apache.axiom.om.OMDocument)9 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)7 XMLStreamReader (javax.xml.stream.XMLStreamReader)6 OMComment (org.apache.axiom.om.OMComment)6 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)6 QName (javax.xml.namespace.QName)5 SOAPHeader (org.apache.axiom.soap.SOAPHeader)5 OMAttribute (org.apache.axiom.om.OMAttribute)4 OMNamespace (org.apache.axiom.om.OMNamespace)4 SOAPBody (org.apache.axiom.soap.SOAPBody)4 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)4 OMProcessingInstruction (org.apache.axiom.om.OMProcessingInstruction)3 SOAPFault (org.apache.axiom.soap.SOAPFault)3 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)3