Example usage for javax.xml.soap SOAPElement getParentElement

List of usage examples for javax.xml.soap SOAPElement getParentElement

Introduction

In this page you can find the example usage for javax.xml.soap SOAPElement getParentElement.

Prototype

public SOAPElement getParentElement();

Source Link

Document

Returns the parent element of this Node object.

Usage

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test/*from  w w w  . jav a 2s. co  m*/
public void testGetParentElement() throws Exception {
    SOAPElement parent = saajUtil.createSOAPElement(null, "parent", null);
    SOAPElement child = parent.addChildElement(new QName("child"));
    assertSame(parent, child.getParentElement());
}

From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java

public SOAPElement toSAAJ(OMElement omElement, SOAPElement parent) throws WebServiceException {
    if (log.isDebugEnabled()) {
        log.debug("Converting OMElement to an SAAJ SOAPElement");
        log.debug("The conversion occurs due to " + JavaUtils.stackToString());
    }//w  w w. j  a va 2 s  .  co  m

    XMLStreamReader reader = null;

    // If the OM element is not attached to a parser (builder), then the OM
    // is built and you cannot ask for XMLStreamReaderWithoutCaching.
    // This is probably a bug in OM.  You should be able to ask the OM whether
    // caching is supported.
    if (omElement.getBuilder() == null) {
        reader = omElement.getXMLStreamReader();
    } else {
        reader = omElement.getXMLStreamReaderWithoutCaching();
    }
    SOAPElement env = parent;
    while (env != null && !(env instanceof SOAPEnvelope)) {
        env = env.getParentElement();
    }
    if (env == null) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("SAAJConverterErr1"));
    }
    NameCreator nc = new NameCreator((SOAPEnvelope) env);
    return buildSOAPTree(nc, null, parent, reader, false);
}

From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java

/**
 * Build SOAPTree Either the root or the parent is null. If the root is null, a new element is
 * created under the parent using information from the reader If the parent is null, the existing
 * root is updated with the information from the reader
 *
 * @param nc         NameCreator/*from w  ww.  j  av  a 2 s.  c om*/
 * @param root       SOAPElement (the element that represents the data in the reader)
 * @param parent     (the parent of the element represented by the reader)
 * @param reader     XMLStreamReader. the first START_ELEMENT matches the root
 * @param quitAtBody - true if quit reading after the body START_ELEMENT
 */
protected SOAPElement buildSOAPTree(NameCreator nc, SOAPElement root, SOAPElement parent,
        XMLStreamReader reader, boolean quitAtBody) throws WebServiceException {
    try {
        while (reader.hasNext()) {
            int eventID = reader.next();
            switch (eventID) {
            case XMLStreamReader.START_ELEMENT: {

                // The first START_ELEMENT defines the prefix and attributes of the root
                if (parent == null) {
                    updateTagData(nc, root, reader, false);
                    parent = root;
                } else {
                    parent = createElementFromTag(nc, parent, reader);
                    if (root == null) {
                        root = parent;
                    }
                }
                if (quitAtBody && parent instanceof SOAPBody) {
                    return root;
                }
                break;
            }
            case XMLStreamReader.ATTRIBUTE: {
                String eventName = "ATTRIBUTE";
                this._unexpectedEvent(eventName);
                break;
            }
            case XMLStreamReader.NAMESPACE: {
                String eventName = "NAMESPACE";
                this._unexpectedEvent(eventName);
                break;
            }
            case XMLStreamReader.END_ELEMENT: {
                if (parent instanceof SOAPEnvelope) {
                    parent = null;
                } else {
                    parent = parent.getParentElement();
                }
                break;
            }
            case XMLStreamReader.CHARACTERS: {
                parent.addTextNode(reader.getText());
                break;
            }
            case XMLStreamReader.CDATA: {
                parent.addTextNode(reader.getText());
                break;
            }
            case XMLStreamReader.COMMENT: {
                // SOAP really doesn't have an adequate representation for comments.
                // The defacto standard is to add the whole element as a text node.
                parent.addTextNode("<!--" + reader.getText() + "-->");
                break;
            }
            case XMLStreamReader.SPACE: {
                parent.addTextNode(reader.getText());
                break;
            }
            case XMLStreamReader.START_DOCUMENT: {
                // Ignore
                break;
            }
            case XMLStreamReader.END_DOCUMENT: {
                // Close reader and ignore
                reader.close();
                break;
            }
            case XMLStreamReader.PROCESSING_INSTRUCTION: {
                // Ignore
                break;
            }
            case XMLStreamReader.ENTITY_REFERENCE: {
                // Ignore. this is unexpected in a web service message
                break;
            }
            case XMLStreamReader.DTD: {
                // Ignore. this is unexpected in a web service message
                break;
            }
            default:
                this._unexpectedEvent("EventID " + String.valueOf(eventID));
            }
        }
    } catch (WebServiceException e) {
        throw e;
    } catch (XMLStreamException e) {
        throw ExceptionFactory.makeWebServiceException(e);
    } catch (SOAPException e) {
        throw ExceptionFactory.makeWebServiceException(e);
    }
    return root;
}

From source file:org.jbpm.bpel.integration.soap.SoapUtil.java

public static SOAPEnvelope findEnvelope(SOAPElement element) throws SOAPException {
    do {/*from  w ww.  j a v a2 s .  c o  m*/
        if (element instanceof SOAPEnvelope)
            return (SOAPEnvelope) element;

        element = element.getParentElement();
    } while (element != null);

    return null;
}

From source file:org.springframework.ws.soap.saaj.support.SaajUtils.java

/**
 * Returns the SAAJ <code>SOAPEnvelope</code> for the given element.
 *
 * @param element the element to return the envelope from
 * @return the envelope, or <code>null</code> if not found
 *///ww  w.  j  av  a2s. co  m
public static SOAPEnvelope getEnvelope(SOAPElement element) {
    Assert.notNull(element, "Element should not be null");
    do {
        if (element instanceof SOAPEnvelope) {
            return (SOAPEnvelope) element;
        }
        element = element.getParentElement();
    } while (element != null);
    return null;
}