View Javadoc
1   /*
2    * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.  Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10   *
11   * This code is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   * version 2 for more details (a copy is included in the LICENSE file that
15   * accompanied this code).
16   *
17   * You should have received a copy of the GNU General Public License version
18   * 2 along with this work; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20   *
21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22   * or visit www.oracle.com if you need additional information or have any
23   * questions.
24   */
25  
26  package javax.xml.soap;
27  
28  
29  /**
30   * The container for the SOAPHeader and SOAPBody portions of a
31   * <code>SOAPPart</code> object. By default, a <code>SOAPMessage</code>
32   * object is created with a <code>SOAPPart</code> object that has a
33   * <code>SOAPEnvelope</code> object. The <code>SOAPEnvelope</code> object
34   * by default has an empty <code>SOAPBody</code> object and an empty
35   * <code>SOAPHeader</code> object.  The <code>SOAPBody</code> object is
36   * required, and the <code>SOAPHeader</code> object, though
37   * optional, is used in the majority of cases. If the
38   * <code>SOAPHeader</code> object is not needed, it can be deleted,
39   * which is shown later.
40   * <P>
41   * A client can access the <code>SOAPHeader</code> and <code>SOAPBody</code>
42   * objects by calling the methods <code>SOAPEnvelope.getHeader</code> and
43   * <code>SOAPEnvelope.getBody</code>. The
44   * following  lines of code use these two methods after starting with
45   * the <code>SOAPMessage</code>
46   * object <i>message</i> to get the <code>SOAPPart</code> object <i>sp</i>,
47   * which is then used to get the <code>SOAPEnvelope</code> object <i>se</i>.
48   *
49   * <PRE>
50   *     SOAPPart sp = message.getSOAPPart();
51   *     SOAPEnvelope se = sp.getEnvelope();
52   *     SOAPHeader sh = se.getHeader();
53   *     SOAPBody sb = se.getBody();
54   * </PRE>
55   * <P>
56   * It is possible to change the body or header of a <code>SOAPEnvelope</code>
57   * object by retrieving the current one, deleting it, and then adding
58   * a new body or header. The <code>javax.xml.soap.Node</code> method
59   * <code>deleteNode</code> deletes the XML element (node) on which it is
60   * called.  For example, the following line of code deletes the
61   * <code>SOAPBody</code> object that is retrieved by the method <code>getBody</code>.
62   * <PRE>
63   *      se.getBody().detachNode();
64   * </PRE>
65   * To create a <code>SOAPHeader</code> object to replace the one that was removed,
66   * a client uses
67   * the method <code>SOAPEnvelope.addHeader</code>, which creates a new header and
68   * adds it to the <code>SOAPEnvelope</code> object. Similarly, the method
69   * <code>addBody</code> creates a new <code>SOAPBody</code> object and adds
70   * it to the <code>SOAPEnvelope</code> object. The following code fragment
71   * retrieves the current header, removes it, and adds a new one. Then
72   * it retrieves the current body, removes it, and adds a new one.
73   *
74   * <PRE>
75   *     SOAPPart sp = message.getSOAPPart();
76   *     SOAPEnvelope se = sp.getEnvelope();
77   *     se.getHeader().detachNode();
78   *     SOAPHeader sh = se.addHeader();
79   *     se.getBody().detachNode();
80   *     SOAPBody sb = se.addBody();
81   * </PRE>
82   * It is an error to add a <code>SOAPBody</code> or <code>SOAPHeader</code>
83   * object if one already exists.
84   * <P>
85   * The <code>SOAPEnvelope</code> interface provides three methods for creating
86   * <code>Name</code> objects. One method creates <code>Name</code> objects with
87   * a local name, a namespace prefix, and a namesapce URI. The second method creates
88   * <code>Name</code> objects with a local name and a namespace prefix, and the third
89   * creates <code>Name</code> objects with just a local name.  The following line of
90   * code, in which <i>se</i> is a <code>SOAPEnvelope</code> object, creates a new
91   * <code>Name</code> object with all three.
92   * <PRE>
93   *     Name name = se.createName("GetLastTradePrice", "WOMBAT",
94   *                                "http://www.wombat.org/trader");
95   * </PRE>
96   */
97  public interface SOAPEnvelope extends SOAPElement {
98  
99      /**
100      * Creates a new <code>Name</code> object initialized with the
101      * given local name, namespace prefix, and namespace URI.
102      * <P>
103      * This factory method creates <code>Name</code> objects for use in
104      * the SOAP/XML document.
105      *
106      * @param localName a <code>String</code> giving the local name
107      * @param prefix a <code>String</code> giving the prefix of the namespace
108      * @param uri a <code>String</code> giving the URI of the namespace
109      * @return a <code>Name</code> object initialized with the given
110      *         local name, namespace prefix, and namespace URI
111      * @throws SOAPException if there is a SOAP error
112      */
113     public abstract Name createName(String localName, String prefix,
114                                     String uri)
115         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      * Creates a <code>SOAPHeader</code> object and sets it as the
170      * <code>SOAPHeader</code> object for this <code>SOAPEnvelope</code>
171      * object.
172      * <P>
173      * It is illegal to add a header when the envelope already
174      * contains a header.  Therefore, this method should be called
175      * only after the existing header has been removed.
176      *
177      * @return the new <code>SOAPHeader</code> object
178      *
179      * @exception SOAPException if this
180      *            <code>SOAPEnvelope</code> object already contains a
181      *            valid <code>SOAPHeader</code> object
182      */
183     public SOAPHeader addHeader() throws SOAPException;
184     /**
185      * Creates a <code>SOAPBody</code> object and sets it as the
186      * <code>SOAPBody</code> object for this <code>SOAPEnvelope</code>
187      * object.
188      * <P>
189      * It is illegal to add a body when the envelope already
190      * contains a body. Therefore, this method should be called
191      * only after the existing body has been removed.
192      *
193      * @return the new <code>SOAPBody</code> object
194      *
195      * @exception SOAPException if this
196      *            <code>SOAPEnvelope</code> object already contains a
197      *            valid <code>SOAPBody</code> object
198      */
199     public SOAPBody addBody() throws SOAPException;
200 }