001: /*
002: * $Id: SOAPEnvelope.java,v 1.7 2006/03/30 00:59:41 ofung Exp $
003: * $Revision: 1.7 $
004: * $Date: 2006/03/30 00:59:41 $
005: */
006:
007: /*
008: * The contents of this file are subject to the terms
009: * of the Common Development and Distribution License
010: * (the License). You may not use this file except in
011: * compliance with the License.
012: *
013: * You can obtain a copy of the license at
014: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * See the License for the specific language governing
016: * permissions and limitations under the License.
017: *
018: * When distributing Covered Code, include this CDDL
019: * Header Notice in each file and include the License file
020: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
021: * If applicable, add the following below the CDDL Header,
022: * with the fields enclosed by brackets [] replaced by
023: * you own identifying information:
024: * "Portions Copyrighted [year] [name of copyright owner]"
025: *
026: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
027: */
028: package javax.xml.soap;
029:
030: /**
031: * The container for the SOAPHeader and SOAPBody portions of a
032: * <code>SOAPPart</code> object. By default, a <code>SOAPMessage</code>
033: * object is created with a <code>SOAPPart</code> object that has a
034: * <code>SOAPEnvelope</code> object. The <code>SOAPEnvelope</code> object
035: * by default has an empty <code>SOAPBody</code> object and an empty
036: * <code>SOAPHeader</code> object. The <code>SOAPBody</code> object is
037: * required, and the <code>SOAPHeader</code> object, though
038: * optional, is used in the majority of cases. If the
039: * <code>SOAPHeader</code> object is not needed, it can be deleted,
040: * which is shown later.
041: * <P>
042: * A client can access the <code>SOAPHeader</code> and <code>SOAPBody</code>
043: * objects by calling the methods <code>SOAPEnvelope.getHeader</code> and
044: * <code>SOAPEnvelope.getBody</code>. The
045: * following lines of code use these two methods after starting with
046: * the <code>SOAPMessage</code>
047: * object <i>message</i> to get the <code>SOAPPart</code> object <i>sp</i>,
048: * which is then used to get the <code>SOAPEnvelope</code> object <i>se</i>.
049: *
050: * <PRE>
051: * SOAPPart sp = message.getSOAPPart();
052: * SOAPEnvelope se = sp.getEnvelope();
053: * SOAPHeader sh = se.getHeader();
054: * SOAPBody sb = se.getBody();
055: * </PRE>
056: * <P>
057: * It is possible to change the body or header of a <code>SOAPEnvelope</code>
058: * object by retrieving the current one, deleting it, and then adding
059: * a new body or header. The <code>javax.xml.soap.Node</code> method
060: * <code>deleteNode</code> deletes the XML element (node) on which it is
061: * called. For example, the following line of code deletes the
062: * <code>SOAPBody</code> object that is retrieved by the method <code>getBody</code>.
063: * <PRE>
064: * se.getBody().detachNode();
065: * </PRE>
066: * To create a <code>SOAPHeader</code> object to replace the one that was removed,
067: * a client uses
068: * the method <code>SOAPEnvelope.addHeader</code>, which creates a new header and
069: * adds it to the <code>SOAPEnvelope</code> object. Similarly, the method
070: * <code>addBody</code> creates a new <code>SOAPBody</code> object and adds
071: * it to the <code>SOAPEnvelope</code> object. The following code fragment
072: * retrieves the current header, removes it, and adds a new one. Then
073: * it retrieves the current body, removes it, and adds a new one.
074: *
075: * <PRE>
076: * SOAPPart sp = message.getSOAPPart();
077: * SOAPEnvelope se = sp.getEnvelope();
078: * se.getHeader().detachNode();
079: * SOAPHeader sh = se.addHeader();
080: * se.getBody().detachNode();
081: * SOAPBody sb = se.addBody();
082: * </PRE>
083: * It is an error to add a <code>SOAPBody</code> or <code>SOAPHeader</code>
084: * object if one already exists.
085: * <P>
086: * The <code>SOAPEnvelope</code> interface provides three methods for creating
087: * <code>Name</code> objects. One method creates <code>Name</code> objects with
088: * a local name, a namespace prefix, and a namesapce URI. The second method creates
089: * <code>Name</code> objects with a local name and a namespace prefix, and the third
090: * creates <code>Name</code> objects with just a local name. The following line of
091: * code, in which <i>se</i> is a <code>SOAPEnvelope</code> object, creates a new
092: * <code>Name</code> object with all three.
093: * <PRE>
094: * Name name = se.createName("GetLastTradePrice", "WOMBAT",
095: * "http://www.wombat.org/trader");
096: * </PRE>
097: */
098: public interface SOAPEnvelope extends SOAPElement {
099:
100: /**
101: * Creates a new <code>Name</code> object initialized with the
102: * given local name, namespace prefix, and namespace URI.
103: * <P>
104: * This factory method creates <code>Name</code> objects for use in
105: * the SOAP/XML document.
106: *
107: * @param localName a <code>String</code> giving the local name
108: * @param prefix a <code>String</code> giving the prefix of the namespace
109: * @param uri a <code>String</code> giving the URI of the namespace
110: * @return a <code>Name</code> object initialized with the given
111: * local name, namespace prefix, and namespace URI
112: * @throws SOAPException if there is a SOAP error
113: */
114: public abstract Name createName(String localName, String prefix,
115: String uri) throws SOAPException;
116:
117: /**
118: * Creates a new <code>Name</code> object initialized with the
119: * given local name.
120: * <P>
121: * This factory method creates <code>Name</code> objects for use in
122: * the SOAP/XML document.
123: *
124: * @param localName a <code>String</code> giving the local name
125: * @return a <code>Name</code> object initialized with the given
126: * local name
127: * @throws SOAPException if there is a SOAP error
128: */
129: public abstract Name createName(String localName)
130: throws SOAPException;
131:
132: /**
133: * Returns the <code>SOAPHeader</code> object for
134: * this <code>SOAPEnvelope</code> object.
135: * <P>
136: * A new <code>SOAPMessage</code> object is by default created with a
137: * <code>SOAPEnvelope</code> object that contains an empty
138: * <code>SOAPHeader</code> object. As a result, the method
139: * <code>getHeader</code> will always return a <code>SOAPHeader</code>
140: * object unless the header has been removed and a new one has not
141: * been added.
142: *
143: * @return the <code>SOAPHeader</code> object or <code>null</code> if
144: * there is none
145: * @exception SOAPException if there is a problem obtaining the
146: * <code>SOAPHeader</code> object
147: */
148: public SOAPHeader getHeader() throws SOAPException;
149:
150: /**
151: * Returns the <code>SOAPBody</code> object associated with this
152: * <code>SOAPEnvelope</code> object.
153: * <P>
154: * A new <code>SOAPMessage</code> object is by default created with a
155: * <code>SOAPEnvelope</code> object that contains an empty
156: * <code>SOAPBody</code> object. As a result, the method
157: * <code>getBody</code> will always return a <code>SOAPBody</code>
158: * object unless the body has been removed and a new one has not
159: * been added.
160: *
161: * @return the <code>SOAPBody</code> object for this
162: * <code>SOAPEnvelope</code> object or <code>null</code>
163: * if there is none
164: * @exception SOAPException if there is a problem obtaining the
165: * <code>SOAPBody</code> object
166: */
167: public SOAPBody getBody() throws SOAPException;
168:
169: /**
170: * Creates a <code>SOAPHeader</code> object and sets it as the
171: * <code>SOAPHeader</code> object for this <code>SOAPEnvelope</code>
172: * object.
173: * <P>
174: * It is illegal to add a header when the envelope already
175: * contains a header. Therefore, this method should be called
176: * only after the existing header has been removed.
177: *
178: * @return the new <code>SOAPHeader</code> object
179: *
180: * @exception SOAPException if this
181: * <code>SOAPEnvelope</code> object already contains a
182: * valid <code>SOAPHeader</code> object
183: */
184: public SOAPHeader addHeader() throws SOAPException;
185:
186: /**
187: * Creates a <code>SOAPBody</code> object and sets it as the
188: * <code>SOAPBody</code> object for this <code>SOAPEnvelope</code>
189: * object.
190: * <P>
191: * It is illegal to add a body when the envelope already
192: * contains a body. Therefore, this method should be called
193: * only after the existing body has been removed.
194: *
195: * @return the new <code>SOAPBody</code> object
196: *
197: * @exception SOAPException if this
198: * <code>SOAPEnvelope</code> object already contains a
199: * valid <code>SOAPBody</code> object
200: */
201: public SOAPBody addBody() throws SOAPException;
202: }
|