Search in sources :

Example 81 with OMNode

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

the class TestCloseOnComplete method runTest.

@Override
protected void runTest() throws Throwable {
    PullOMDataSource ds = new PullOMDataSource("<root><a/></root>");
    OMSourcedElement element = metaFactory.getOMFactory().createOMElement(ds);
    OMNode child = element.getFirstOMChild();
    assertFalse(element.isComplete());
    assertTrue(ds.hasUnclosedReaders());
    child.getNextOMSibling();
    assertTrue(element.isComplete());
    assertFalse(ds.hasUnclosedReaders());
}
Also used : OMNode(org.apache.axiom.om.OMNode) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 82 with OMNode

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

the class TestExpand method runTest.

@Override
protected void runTest() throws Throwable {
    OMSourcedElement element = TestDocument.DOCUMENT1.createOMSourcedElement(metaFactory.getOMFactory(), false, true);
    element.getAllDeclaredNamespaces();
    assertEquals("Expanded namespace count error", 1, countItems(element.getAllDeclaredNamespaces()));
    assertEquals("Expanded attribute count error", 1, countItems(element.getAllAttributes()));
    assertEquals("Expanded attribute value error", "1", element.getAttributeValue(new QName("books")));
    OMElement child = element.getFirstElement();
    assertEquals("Child element name", "type", child.getLocalName());
    assertEquals("Child element namespace", "http://www.sosnoski.com/uwjws/library", child.getNamespace().getNamespaceURI());
    OMNode next = child.getNextOMSibling();
    assertTrue("Expected child element", next instanceof OMElement);
    next = next.getNextOMSibling();
    assertTrue("Expected child element", next instanceof OMElement);
    child = (OMElement) next;
    assertEquals("Child element name", "book", child.getLocalName());
    assertEquals("Child element namespace", "http://www.sosnoski.com/uwjws/library", child.getNamespace().getNamespaceURI());
    assertEquals("Attribute value error", "xml", child.getAttributeValue(new QName("type")));
}
Also used : OMNode(org.apache.axiom.om.OMNode) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 83 with OMNode

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

the class TestDetach method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMContainer root;
    if (document) {
        root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<!--a--><b/><!--c-->")).getDocument();
    } else {
        root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><!--a--><b/><!--c--></root>")).getDocumentElement();
    }
    if (build) {
        root.build();
    } else {
        assertFalse(root.isComplete());
    }
    OMComment a = (OMComment) root.getFirstOMChild();
    assertEquals("a", a.getValue());
    OMElement b = (OMElement) a.getNextOMSibling();
    assertEquals("b", b.getLocalName());
    OMNode returnValue = b.detach();
    // Detach is expected to do a "return this"
    assertSame(b, returnValue);
    assertNull(b.getParent());
    assertNull(b.getPreviousOMSibling());
    assertNull(b.getNextOMSibling());
    OMComment c = (OMComment) a.getNextOMSibling();
    assertEquals("c", c.getValue());
    assertSame(c, a.getNextOMSibling());
    assertSame(a, c.getPreviousOMSibling());
    root.close(false);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMComment(org.apache.axiom.om.OMComment) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMContainer(org.apache.axiom.om.OMContainer)

Example 84 with OMNode

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

the class TestAddSOAPTextMultiple method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPFaultReason reason = soapFactory.createSOAPFaultReason();
    SOAPFaultText text1 = soapFactory.createSOAPFaultText();
    text1.setLang("en");
    text1.setText("System error");
    reason.addSOAPText(text1);
    SOAPFaultText text2 = soapFactory.createSOAPFaultText();
    text2.setLang("de");
    text2.setText("Systemfehler");
    reason.addSOAPText(text2);
    OMNode child = reason.getFirstOMChild();
    assertThat(child).isSameAs(text1);
    child = child.getNextOMSibling();
    assertThat(child).isSameAs(text2);
}
Also used : OMNode(org.apache.axiom.om.OMNode) SOAPFaultReason(org.apache.axiom.soap.SOAPFaultReason) SOAPFaultText(org.apache.axiom.soap.SOAPFaultText)

Example 85 with OMNode

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

the class TestStandaloneConfiguration method runTest.

@Override
protected void runTest() throws Throwable {
    InputStream is = TestStandaloneConfiguration.class.getResourceAsStream("web_w_dtd2.xml");
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.STANDALONE, is);
    OMElement root = builder.getDocumentElement();
    assertTrue(root.getLocalName().equals("web-app"));
    OMDocument document = builder.getDocument();
    Iterator<OMNode> i = document.getChildren();
    OMDocType docType = null;
    while (docType == null && i.hasNext()) {
        OMNode obj = i.next();
        if (obj instanceof OMDocType) {
            docType = (OMDocType) obj;
        }
    }
    assertTrue(docType != null);
    root.close(false);
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMDocType(org.apache.axiom.om.OMDocType) InputStream(java.io.InputStream) OMElement(org.apache.axiom.om.OMElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

OMNode (org.apache.axiom.om.OMNode)150 OMElement (org.apache.axiom.om.OMElement)87 Iterator (java.util.Iterator)28 OMText (org.apache.axiom.om.OMText)23 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)20 BXMLItem (org.ballerinalang.model.values.BXMLItem)18 StringReader (java.io.StringReader)17 SynapseException (org.apache.synapse.SynapseException)15 OMAttribute (org.apache.axiom.om.OMAttribute)14 OMFactory (org.apache.axiom.om.OMFactory)14 BValue (org.ballerinalang.model.values.BValue)14 BXML (org.ballerinalang.model.values.BXML)14 Test (org.testng.annotations.Test)14 QName (javax.xml.namespace.QName)13 BJSON (org.ballerinalang.model.values.BJSON)13 OMDocument (org.apache.axiom.om.OMDocument)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 SOAPHeader (org.apache.axiom.soap.SOAPHeader)10 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)10