Search in sources :

Example 81 with OMElement

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

the class AxiomTraverser method next.

@Override
public Event next() throws TraverserException {
    if (node == null) {
        if (root instanceof OMDocument) {
            node = ((OMDocument) root).getFirstOMChild();
        } else {
            node = (OMElement) root;
        }
    } else if (!visited && node instanceof OMElement) {
        OMNode firstChild = ((OMElement) node).getFirstOMChild();
        if (firstChild != null) {
            node = firstChild;
        } else {
            visited = true;
        }
    } else {
        OMNode nextSibling = node.getNextOMSibling();
        if (node == root) {
            return null;
        } else if (nextSibling != null) {
            node = nextSibling;
            visited = false;
        } else {
            OMContainer parent = node.getParent();
            if (parent instanceof OMDocument) {
                return null;
            } else {
                node = (OMElement) parent;
                visited = true;
            }
        }
    }
    switch(node.getType()) {
        case OMNode.DTD_NODE:
            return Event.DOCUMENT_TYPE;
        case OMNode.ELEMENT_NODE:
            return visited ? Event.END_ELEMENT : Event.START_ELEMENT;
        case OMNode.TEXT_NODE:
            return Event.TEXT;
        case OMNode.SPACE_NODE:
            return Event.WHITESPACE;
        case OMNode.ENTITY_REFERENCE_NODE:
            if (expandEntityReferences) {
                throw new UnsupportedOperationException();
            } else {
                return Event.ENTITY_REFERENCE;
            }
        case OMNode.COMMENT_NODE:
            return Event.COMMENT;
        case OMNode.CDATA_SECTION_NODE:
            return Event.CDATA_SECTION;
        case OMNode.PI_NODE:
            return Event.PROCESSING_INSTRUCTION;
        default:
            throw new IllegalStateException();
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement) OMContainer(org.apache.axiom.om.OMContainer) OMDocument(org.apache.axiom.om.OMDocument)

Example 82 with OMElement

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

the class TestWrongParent3 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPFaultDetail parent = soapFactory.createSOAPFaultDetail();
    OMElement child1 = soapFactory.createOMElement("child1", null, parent);
    SOAPHeaderBlock hb = soapFactory.createSOAPHeaderBlock("MyHeader", soapFactory.createOMNamespace("urn:test", "p"));
    try {
        child1.insertSiblingBefore(hb);
        fail("Expected SOAPProcessingException");
    } catch (SOAPProcessingException ex) {
    // Expected
    }
}
Also used : SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) OMElement(org.apache.axiom.om.OMElement) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock)

Example 83 with OMElement

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

the class TestClone method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPMessage message = soapFactory.createSOAPMessage();
    message.addChild(soapFactory.getDefaultEnvelope());
    OMCloneOptions options = new OMCloneOptions();
    options.setPreserveModel(preserveModel);
    OMInformationItem clone = message.clone(options);
    if (preserveModel) {
        assertTrue(clone instanceof SOAPMessage);
    } else {
        assertTrue(clone instanceof OMDocument);
        assertFalse(clone instanceof SOAPMessage);
    }
    OMElement envelope = ((OMDocument) clone).getOMDocumentElement();
    if (preserveModel) {
        assertTrue(envelope instanceof SOAPEnvelope);
    } else {
        assertFalse(envelope instanceof SOAPEnvelope);
    }
    assertEquals("Envelope", envelope.getLocalName());
    assertEquals(spec.getEnvelopeNamespaceURI(), envelope.getNamespaceURI());
}
Also used : OMInformationItem(org.apache.axiom.om.OMInformationItem) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPMessage(org.apache.axiom.soap.SOAPMessage) OMDocument(org.apache.axiom.om.OMDocument)

Example 84 with OMElement

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

the class TestSetOMDocumentElement method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPMessage message = soapFactory.createSOAPMessage();
    OMElement envelope = soapFactory.getDefaultEnvelope();
    message.setOMDocumentElement(envelope);
    assertSame(envelope, message.getFirstOMChild());
}
Also used : OMElement(org.apache.axiom.om.OMElement) SOAPMessage(org.apache.axiom.soap.SOAPMessage)

Example 85 with OMElement

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

the class TestSetOMDocumentElementNonSOAPEnvelope method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPMessage message = soapFactory.createSOAPMessage();
    OMElement element = soapFactory.createOMElement(new QName("test"));
    try {
        message.setOMDocumentElement(element);
        fail("Expected OMException");
    } catch (OMException ex) {
    // Expected
    }
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) SOAPMessage(org.apache.axiom.soap.SOAPMessage) OMException(org.apache.axiom.om.OMException)

Aggregations

OMElement (org.apache.axiom.om.OMElement)414 OMFactory (org.apache.axiom.om.OMFactory)202 OMNamespace (org.apache.axiom.om.OMNamespace)108 QName (javax.xml.namespace.QName)97 StringReader (java.io.StringReader)63 OMNode (org.apache.axiom.om.OMNode)43 OMText (org.apache.axiom.om.OMText)41 XMLStreamReader (javax.xml.stream.XMLStreamReader)37 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)32 OMAttribute (org.apache.axiom.om.OMAttribute)26 StringWriter (java.io.StringWriter)24 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)21 DataHandler (javax.activation.DataHandler)20 OMDocument (org.apache.axiom.om.OMDocument)19 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)18 Element (org.w3c.dom.Element)18 InputStream (java.io.InputStream)16 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)16 ByteArrayInputStream (java.io.ByteArrayInputStream)13 OMException (org.apache.axiom.om.OMException)13