Search in sources :

Example 46 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 47 with OMSourcedElement

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

the class TextFileDataSourceTest method testWithXMLChars.

public void testWithXMLChars() throws Exception {
    String testString = "Test string with ampersand (&)";
    OMSourcedElement element = createSourcedElement(testString, UTF8);
    assertEquals(testString, element.getText());
}
Also used : OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Aggregations

OMSourcedElement (org.apache.axiom.om.OMSourcedElement)47 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 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 StringWriter (java.io.StringWriter)3 DataSource (javax.activation.DataSource)3 XMLStreamException (javax.xml.stream.XMLStreamException)3