Search in sources :

Example 36 with OMSourcedElement

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

the class CloneTestCase method identityCheck.

/**
     * Check the identity of each object in the tree
     * @param source
     * @param target
     * @param depth
     */
protected void identityCheck(OMNode source, OMNode target, String depth) {
    // System.out.println(depth + source.getClass().getName());
    if (source instanceof OMElement) {
        if (source instanceof OMSourcedElement) {
            assertTrue("Source = " + source.getClass().getName() + "Target = " + target.getClass().getName(), target instanceof OMSourcedElement);
            assertEquals(((OMSourcedElement) source).isExpanded(), ((OMSourcedElement) target).isExpanded());
            if (((OMSourcedElement) source).isExpanded()) {
                Iterator<OMNode> i = ((OMElement) source).getChildren();
                Iterator<OMNode> j = ((OMElement) target).getChildren();
                while (i.hasNext() && j.hasNext()) {
                    OMNode sourceChild = i.next();
                    OMNode targetChild = j.next();
                    identityCheck(sourceChild, targetChild, depth + "  ");
                }
                assertEquals("Source and Target have different number of children", i.hasNext(), j.hasNext());
            }
        } else {
            assertEquals(source.getClass(), target.getClass());
            Iterator<OMNode> i = ((OMElement) source).getChildren();
            Iterator<OMNode> j = ((OMElement) target).getChildren();
            while (i.hasNext() && j.hasNext()) {
                OMNode sourceChild = i.next();
                OMNode targetChild = j.next();
                identityCheck(sourceChild, targetChild, depth + "  ");
            }
            assertEquals("Source and Target have different number of children", i.hasNext(), j.hasNext());
        }
    } else {
        assertEquals(source.getClass(), target.getClass());
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 37 with OMSourcedElement

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

the class TestGetNextOMSiblingIncomplete method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMSourcedElement omse = factory.createOMElement(new StringOMDataSource("<sourcedelement/>"));
    OMElement parent = factory.createOMElement(new QName("parent"));
    parent.addChild(omse);
    // Cause expansion of the sourced element without building it completely
    omse.getLocalName();
    assertTrue(omse.isExpanded());
    assertFalse(omse.isComplete());
    // Call getNextOMSibling(); this should not build the element
    omse.getNextOMSibling();
    assertFalse(omse.isComplete());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 38 with OMSourcedElement

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

the class TestGetTextAsStreamWithNonDestructiveOMDataSource method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    DataSource ds = new RandomDataSource(445566, 32, 128, 20000000);
    QName qname = new QName("a");
    Charset cs = Charset.forName("ascii");
    OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, cs), qname);
    Reader in = element.getTextAsStream(true);
    assertFalse(in instanceof StringReader);
    IOTestUtils.compareStreams(new InputStreamReader(ds.getInputStream(), cs), in);
    assertFalse(element.isExpanded());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) InputStreamReader(java.io.InputStreamReader) QName(javax.xml.namespace.QName) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) StringReader(java.io.StringReader) Charset(java.nio.charset.Charset) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Example 39 with OMSourcedElement

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

the class TestRemoveChildrenUnexpanded method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMSourcedElement element = factory.createOMElement(new StringOMDataSource("<element attr='value'><a/></element>"));
    element.removeChildren();
    // Check that the attribute has been added
    Iterator<OMAttribute> it = element.getAllAttributes();
    assertTrue(it.hasNext());
    OMAttribute attr = it.next();
    assertEquals("attr", attr.getLocalName());
    assertEquals("value", attr.getAttributeValue());
    assertFalse(it.hasNext());
    // Check that the element is empty
    assertNull(element.getFirstOMChild());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 40 with OMSourcedElement

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

the class TestSetDataSourceOnAlreadyExpandedElement method runTest.

@Override
protected void runTest() throws Throwable {
    OMSourcedElement element = TestDocument.DOCUMENT1.createOMSourcedElement(metaFactory.getOMFactory(), false, true);
    // Make sure the OMSourcedElement is expanded
    element.getFirstOMChild();
    assertTrue(element.isExpanded());
    // Now set a new data source
    element.setDataSource(new PullOMDataSource(TestDocument.DOCUMENT2.getContent()));
    assertFalse(element.isExpanded());
    // getNextOMSibling should not expand the element
    assertNull(element.getNextOMSibling());
    assertFalse(element.isExpanded());
}
Also used : PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Aggregations

OMSourcedElement (org.apache.axiom.om.OMSourcedElement)44 OMFactory (org.apache.axiom.om.OMFactory)32 OMElement (org.apache.axiom.om.OMElement)16 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)14 QName (javax.xml.namespace.QName)13 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)11 OMNamespace (org.apache.axiom.om.OMNamespace)9 OMDataSource (org.apache.axiom.om.OMDataSource)8 OMNode (org.apache.axiom.om.OMNode)7 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)7 JAXBContext (javax.xml.bind.JAXBContext)6 JAXBOMDataSource (org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)6 XMLStreamReader (javax.xml.stream.XMLStreamReader)5 StringReader (java.io.StringReader)4 OMAttribute (org.apache.axiom.om.OMAttribute)4 DocumentBean (org.apache.axiom.ts.jaxb.beans.DocumentBean)4 DataSource (javax.activation.DataSource)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 BlobOMDataSource (org.apache.axiom.om.ds.BlobOMDataSource)3 WrappedTextNodeOMDataSourceFromDataSource (org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource)3