Search in sources :

Example 46 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 47 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)

Example 48 with OMFactory

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

the class TestRootPartStreaming method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    // Programmatically create the message
    OMElement orgRoot = factory.createOMElement("root", null);
    for (int i = 0; i < 10000; i++) {
        factory.createOMElement("child", null, orgRoot).setText("Some text content");
    }
    // Serialize the message as XOP even if there will be no attachment parts
    OMOutputFormat format = new OMOutputFormat();
    format.setDoOptimize(true);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    orgRoot.serialize(baos, format);
    // Parse the message and monitor the number of bytes read
    InstrumentedInputStream in = new InstrumentedInputStream(new ByteArrayInputStream(baos.toByteArray()));
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, StAXParserConfiguration.DEFAULT, MultipartBody.builder().setInputStream(in).setContentType(format.getContentType()).build());
    OMElement root = builder.getDocumentElement();
    long count1 = in.getCount();
    XMLStreamReader reader = root.getXMLStreamReader(false);
    while (reader.hasNext()) {
        reader.next();
    }
    long count2 = in.getCount();
    // We expect that after requesting the document element, only a small part (corresponding to
    // the size of the parser buffer) should have been read:
    assertTrue(count1 < count2 / 2);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) XMLStreamReader(javax.xml.stream.XMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InstrumentedInputStream(org.apache.axiom.testutils.io.InstrumentedInputStream) OMElement(org.apache.axiom.om.OMElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 49 with OMFactory

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

the class TestSetOMDocumentElementNull method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    try {
        document.setOMDocumentElement(null);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMDocument(org.apache.axiom.om.OMDocument)

Example 50 with OMFactory

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

the class TestInsertSibling method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", null);
    OMText child = factory.createOMText(parent, "test");
    OMComment orgSibling = altMetaFactory.getOMFactory().createOMComment(null, "test");
    if (before) {
        child.insertSiblingBefore(orgSibling);
    } else {
        child.insertSiblingAfter(orgSibling);
    }
    OMComment sibling = (OMComment) (before ? child.getPreviousOMSibling() : child.getNextOMSibling());
    assertThat(sibling).isNotSameAs(orgSibling);
    assertThat(sibling.getValue()).isEqualTo("test");
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMComment(org.apache.axiom.om.OMComment) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMFactory (org.apache.axiom.om.OMFactory)270 OMElement (org.apache.axiom.om.OMElement)202 OMNamespace (org.apache.axiom.om.OMNamespace)101 QName (javax.xml.namespace.QName)71 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 DataHandler (javax.activation.DataHandler)14 XMLStreamReader (javax.xml.stream.XMLStreamReader)14 OMNode (org.apache.axiom.om.OMNode)14 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