001: /*
002: * $Id: SAAJResult.java,v 1.5 2006/03/30 00:59:39 ofung Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
025: */
026:
027: package javax.xml.soap;
028:
029: import javax.xml.transform.dom.DOMResult;
030:
031: /**
032: * Acts as a holder for the results of a JAXP transformation or a JAXB
033: * marshalling, in the form of a SAAJ tree. These results should be accessed
034: * by using the {@link #getResult()} method. The {@link DOMResult#getNode()}
035: * method should be avoided in almost all cases.
036: *
037: * @author XWS-Security Development Team
038: *
039: * @since SAAJ 1.3
040: */
041: public class SAAJResult extends DOMResult {
042:
043: /**
044: * Creates a <code>SAAJResult</code> that will present results in the form
045: * of a SAAJ tree that supports the default (SOAP 1.1) protocol.
046: * <p>
047: * This kind of <code>SAAJResult</code> is meant for use in situations where the
048: * results will be used as a parameter to a method that takes a parameter
049: * whose type, such as <code>SOAPElement</code>, is drawn from the SAAJ
050: * API. When used in a transformation, the results are populated into the
051: * <code>SOAPPart</code> of a <code>SOAPMessage</code> that is created internally.
052: * The <code>SOAPPart</code> returned by {@link DOMResult#getNode()}
053: * is not guaranteed to be well-formed.
054: *
055: * @throws SOAPException if there is a problem creating a <code>SOAPMessage</code>
056: *
057: * @since SAAJ 1.3
058: */
059: public SAAJResult() throws SOAPException {
060: this (MessageFactory.newInstance().createMessage());
061: }
062:
063: /**
064: * Creates a <code>SAAJResult</code> that will present results in the form
065: * of a SAAJ tree that supports the specified protocol. The
066: * <code>DYNAMIC_SOAP_PROTOCOL</code> is ambiguous in this context and will
067: * cause this constructor to throw an <code>UnsupportedOperationException</code>.
068: * <p>
069: * This kind of <code>SAAJResult</code> is meant for use in situations where the
070: * results will be used as a parameter to a method that takes a parameter
071: * whose type, such as <code>SOAPElement</code>, is drawn from the SAAJ
072: * API. When used in a transformation the results are populated into the
073: * <code>SOAPPart</code> of a <code>SOAPMessage</code> that is created
074: * internally. The <code>SOAPPart</code> returned by {@link DOMResult#getNode()}
075: * is not guaranteed to be well-formed.
076: *
077: * @param protocol - the name of the SOAP protocol that the resulting SAAJ
078: * tree should support
079: *
080: * @throws SOAPException if a <code>SOAPMessage</code> supporting the
081: * specified protocol cannot be created
082: *
083: * @since SAAJ 1.3
084: */
085: public SAAJResult(String protocol) throws SOAPException {
086: this (MessageFactory.newInstance(protocol).createMessage());
087: }
088:
089: /**
090: * Creates a <code>SAAJResult</code> that will write the results into the
091: * <code>SOAPPart</code> of the supplied <code>SOAPMessage</code>.
092: * In the normal case these results will be written using DOM APIs and,
093: * as a result, the finished <code>SOAPPart</code> will not be guaranteed
094: * to be well-formed unless the data used to create it is also well formed.
095: * When used in a transformation the validity of the <code>SOAPMessage</code>
096: * after the transformation can be guaranteed only by means outside SAAJ
097: * specification.
098: *
099: * @param message - the message whose <code>SOAPPart</code> will be
100: * populated as a result of some transformation or
101: * marshalling operation
102: *
103: * @since SAAJ 1.3
104: */
105: public SAAJResult(SOAPMessage message) {
106: super (message.getSOAPPart());
107: }
108:
109: /**
110: * Creates a <code>SAAJResult</code> that will write the results as a
111: * child node of the <code>SOAPElement</code> specified. In the normal
112: * case these results will be written using DOM APIs and as a result may
113: * invalidate the structure of the SAAJ tree. This kind of
114: * <code>SAAJResult</code> should only be used when the validity of the
115: * incoming data can be guaranteed by means outside of the SAAJ
116: * specification.
117: *
118: * @param rootNode - the root to which the results will be appended
119: *
120: * @since SAAJ 1.3
121: */
122: public SAAJResult(SOAPElement rootNode) {
123: super (rootNode);
124: }
125:
126: /**
127: * @return the resulting Tree that was created under the specified root Node.
128: * @since SAAJ 1.3
129: */
130: public javax.xml.soap.Node getResult() {
131: return (javax.xml.soap.Node) super.getNode().getFirstChild();
132: }
133: }
|