Search in sources :

Example 26 with OMFactory

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

the class TestRemoveChildren method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<?pi data?><root>text</root>")).getDocument();
    if (complete) {
        document.build();
    }
    OMProcessingInstruction firstChild = (OMProcessingInstruction) document.getFirstOMChild();
    OMElement documentElement;
    if (accessDocumentElement) {
        documentElement = document.getOMDocumentElement();
        assertEquals(complete, documentElement.isComplete());
    } else {
        documentElement = null;
    }
    document.removeChildren();
    // Test that the child has been detached correctly.
    assertNull(firstChild.getParent());
    assertNull(firstChild.getPreviousOMSibling());
    assertNull(firstChild.getNextOMSibling());
    if (documentElement != null) {
        // Test that the child has been detached correctly.
        assertNull(documentElement.getParent());
        assertNull(documentElement.getPreviousOMSibling());
        assertNull(documentElement.getNextOMSibling());
        // Test that we can still get the content of the document element.
        assertEquals("text", documentElement.getText());
    }
    // Test that the document is now empty.
    assertNull(document.getFirstOMChild());
    // Check that the document is in a clean state and that we are able to add
    // new children.
    document.addChild(factory.createOMElement("newroot", null));
    assertAbout(xml()).that(xml(OMDocument.class, document)).hasSameContentAs("<newroot/>");
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 27 with OMFactory

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

the class TestSerializeAndConsumeWithIncompleteDescendant method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement incompleteElement = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<elem>text</elem>")).getDocumentElement(true);
    OMDocument document = factory.createOMDocument();
    OMElement root = factory.createOMElement("root", null, document);
    root.addChild(incompleteElement);
    StringWriter out = new StringWriter();
    document.serializeAndConsume(out);
    assertAbout(xml()).that(out.toString()).hasSameContentAs("<root><elem>text</elem></root>");
    assertConsumed(incompleteElement);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 28 with OMFactory

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

the class TestGetDocumentElementWithDiscardDocumentIllFormedEpilog method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root/> there shouldn't be text here!"));
    OMElement element = builder.getDocumentElement(true);
    try {
        element.build();
        fail("Expected OMException");
    } catch (OMException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper) OMException(org.apache.axiom.om.OMException)

Example 29 with OMFactory

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

the class TestAddChildWithExistingDocumentElement method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    document.addChild(factory.createOMElement(new QName("root1")));
    try {
        document.addChild(factory.createOMElement(new QName("root2")));
        fail("Expected OMException");
    } catch (OMException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) QName(javax.xml.namespace.QName) OMException(org.apache.axiom.om.OMException) OMDocument(org.apache.axiom.om.OMDocument)

Example 30 with OMFactory

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

the class TestGetOMDocumentElementAfterDetach method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    OMElement documentElement = factory.createOMElement("root", null, document);
    assertSame(documentElement, document.getOMDocumentElement());
    documentElement.detach();
    assertNull(document.getOMDocumentElement());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

OMFactory (org.apache.axiom.om.OMFactory)254 OMElement (org.apache.axiom.om.OMElement)189 OMNamespace (org.apache.axiom.om.OMNamespace)94 QName (javax.xml.namespace.QName)62 StringReader (java.io.StringReader)37 OMText (org.apache.axiom.om.OMText)35 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)32 OMAttribute (org.apache.axiom.om.OMAttribute)31 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)26 StringWriter (java.io.StringWriter)18 OMDocument (org.apache.axiom.om.OMDocument)18 XMLStreamReader (javax.xml.stream.XMLStreamReader)14 OMNode (org.apache.axiom.om.OMNode)14 DataHandler (javax.activation.DataHandler)12 OMException (org.apache.axiom.om.OMException)12 DataSource (javax.activation.DataSource)11 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)9 RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)9 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)8 Element (org.w3c.dom.Element)8