1 /*
2 * $Id: SOAPBody.java,v 1.16 2005/04/05 22:28:13 mk125090 Exp $
3 * $Revision: 1.16 $
4 * $Date: 2005/04/05 22:28:13 $
5 */
6
7 /*
8 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
9 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10 *
11 * This code is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 only, as
13 * published by the Free Software Foundation. Sun designates this
14 * particular file as subject to the "Classpath" exception as provided
15 * by Sun in the LICENSE file that accompanied this code.
16 *
17 * This code is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * version 2 for more details (a copy is included in the LICENSE file that
21 * accompanied this code).
22 *
23 * You should have received a copy of the GNU General Public License version
24 * 2 along with this work; if not, write to the Free Software Foundation,
25 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26 *
27 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
28 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * have any questions.
30 */
31 package javax.xml.soap;
32
33 import java.util.Locale;
34
35 import org.w3c.dom.Document;
36
37 import javax.xml.namespace.QName;
38
39 /**
40 * An object that represents the contents of the SOAP body
41 * element in a SOAP message. A SOAP body element consists of XML data
42 * that affects the way the application-specific content is processed.
43 * <P>
44 * A <code>SOAPBody</code> object contains <code>SOAPBodyElement</code>
45 * objects, which have the content for the SOAP body.
46 * A <code>SOAPFault</code> object, which carries status and/or
47 * error information, is an example of a <code>SOAPBodyElement</code> object.
48 *
49 * @see SOAPFault
50 */
51 public interface SOAPBody extends SOAPElement {
52
53 /**
54 * Creates a new <code>SOAPFault</code> object and adds it to
55 * this <code>SOAPBody</code> object. The new <code>SOAPFault</code> will
56 * have default values set for the mandatory child elements. The type of
57 * the <code>SOAPFault</code> will be a SOAP 1.1 or a SOAP 1.2 <code>SOAPFault</code>
58 * depending on the <code>protocol</code> specified while creating the
59 * <code>MessageFactory</code> instance.
60 * <p>
61 * A <code>SOAPBody</code> may contain at most one <code>SOAPFault</code>
62 * child element.
63 *
64 * @return the new <code>SOAPFault</code> object
65 * @exception SOAPException if there is a SOAP error
66 */
67 public SOAPFault addFault() throws SOAPException;
68
69
70 /**
71 * Creates a new <code>SOAPFault</code> object and adds it to
72 * this <code>SOAPBody</code> object. The type of the
73 * <code>SOAPFault</code> will be a SOAP 1.1 or a SOAP 1.2
74 * <code>SOAPFault</code> depending on the <code>protocol</code>
75 * specified while creating the <code>MessageFactory</code> instance.
76 * <p>
77 * For SOAP 1.2 the <code>faultCode</code> parameter is the value of the
78 * <i>Fault/Code/Value</i> element and the <code>faultString</code> parameter
79 * is the value of the <i>Fault/Reason/Text</i> element. For SOAP 1.1
80 * the <code>faultCode</code> parameter is the value of the <code>faultcode</code>
81 * element and the <code>faultString</code> parameter is the value of the <code>faultstring</code>
82 * element.
83 * <p>
84 * A <code>SOAPBody</code> may contain at most one <code>SOAPFault</code>
85 * child element.
86 *
87 * @param faultCode a <code>Name</code> object giving the fault
88 * code to be set; must be one of the fault codes defined in the Version
89 * of SOAP specification in use
90 * @param faultString a <code>String</code> giving an explanation of
91 * the fault
92 * @param locale a {@link java.util.Locale} object indicating
93 * the native language of the <code>faultString</code>
94 * @return the new <code>SOAPFault</code> object
95 * @exception SOAPException if there is a SOAP error
96 * @see SOAPFault#setFaultCode
97 * @see SOAPFault#setFaultString
98 * @since SAAJ 1.2
99 */
100 public SOAPFault addFault(Name faultCode, String faultString, Locale locale) throws SOAPException;
101
102 /**
103 * Creates a new <code>SOAPFault</code> object and adds it to this
104 * <code>SOAPBody</code> object. The type of the <code>SOAPFault</code>
105 * will be a SOAP 1.1 or a SOAP 1.2 <code>SOAPFault</code> depending on
106 * the <code>protocol</code> specified while creating the <code>MessageFactory</code>
107 * instance.
108 * <p>
109 * For SOAP 1.2 the <code>faultCode</code> parameter is the value of the
110 * <i>Fault/Code/Value</i> element and the <code>faultString</code> parameter
111 * is the value of the <i>Fault/Reason/Text</i> element. For SOAP 1.1
112 * the <code>faultCode</code> parameter is the value of the <code>faultcode</code>
113 * element and the <code>faultString</code> parameter is the value of the <code>faultstring</code>
114 * element.
115 * <p>
116 * A <code>SOAPBody</code> may contain at most one <code>SOAPFault</code>
117 * child element.
118 *
119 * @param faultCode
120 * a <code>QName</code> object giving the fault code to be
121 * set; must be one of the fault codes defined in the version
122 * of SOAP specification in use.
123 * @param faultString
124 * a <code>String</code> giving an explanation of the fault
125 * @param locale
126 * a {@link java.util.Locale Locale} object indicating the
127 * native language of the <code>faultString</code>
128 * @return the new <code>SOAPFault</code> object
129 * @exception SOAPException
130 * if there is a SOAP error
131 * @see SOAPFault#setFaultCode
132 * @see SOAPFault#setFaultString
133 * @see SOAPBody#addFault(Name faultCode, String faultString, Locale locale)
134 *
135 * @since SAAJ 1.3
136 */
137 public SOAPFault addFault(QName faultCode, String faultString, Locale locale)
138 throws SOAPException;
139
140 /**
141 * Creates a new <code>SOAPFault</code> object and adds it to this
142 * <code>SOAPBody</code> object. The type of the <code>SOAPFault</code>
143 * will be a SOAP 1.1 or a SOAP 1.2 <code>SOAPFault</code> depending on
144 * the <code>protocol</code> specified while creating the <code>MessageFactory</code>
145 * instance.
146 * <p>
147 * For SOAP 1.2 the <code>faultCode</code> parameter is the value of the
148 * <i>Fault/Code/Value</i> element and the <code>faultString</code> parameter
149 * is the value of the <i>Fault/Reason/Text</i> element. For SOAP 1.1
150 * the <code>faultCode</code> parameter is the value of the <i>faultcode</i>
151 * element and the <code>faultString</code> parameter is the value of the <i>faultstring</i>
152 * element.
153 * <p>
154 * In case of a SOAP 1.2 fault, the default value for the mandatory <code>xml:lang</code>
155 * attribute on the <i>Fault/Reason/Text</i> element will be set to
156 * <code>java.util.Locale.getDefault()</code>
157 * <p>
158 * A <code>SOAPBody</code> may contain at most one <code>SOAPFault</code>
159 * child element.
160 *
161 * @param faultCode
162 * a <code>Name</code> object giving the fault code to be set;
163 * must be one of the fault codes defined in the version of SOAP
164 * specification in use
165 * @param faultString
166 * a <code>String</code> giving an explanation of the fault
167 * @return the new <code>SOAPFault</code> object
168 * @exception SOAPException
169 * if there is a SOAP error
170 * @see SOAPFault#setFaultCode
171 * @see SOAPFault#setFaultString
172 * @since SAAJ 1.2
173 */
174 public SOAPFault addFault(Name faultCode, String faultString)
175 throws SOAPException;
176
177 /**
178 * Creates a new <code>SOAPFault</code> object and adds it to this <code>SOAPBody</code>
179 * object. The type of the <code>SOAPFault</code>
180 * will be a SOAP 1.1 or a SOAP 1.2 <code>SOAPFault</code> depending on
181 * the <code>protocol</code> specified while creating the <code>MessageFactory</code>
182 * instance.
183 * <p>
184 * For SOAP 1.2 the <code>faultCode</code> parameter is the value of the
185 * <i>Fault/Code/Value</i> element and the <code>faultString</code> parameter
186 * is the value of the <i>Fault/Reason/Text</i> element. For SOAP 1.1
187 * the <code>faultCode</code> parameter is the value of the <i>faultcode</i>
188 * element and the <code>faultString</code> parameter is the value of the <i>faultstring</i>
189 * element.
190 * <p>
191 * In case of a SOAP 1.2 fault, the default value for the mandatory <code>xml:lang</code>
192 * attribute on the <i>Fault/Reason/Text</i> element will be set to
193 * <code>java.util.Locale.getDefault()</code>
194 * <p>
195 * A <code>SOAPBody</code> may contain at most one <code>SOAPFault</code>
196 * child element
197 *
198 * @param faultCode
199 * a <code>QName</code> object giving the fault code to be
200 * set; must be one of the fault codes defined in the version
201 * of SOAP specification in use
202 * @param faultString
203 * a <code>String</code> giving an explanation of the fault
204 * @return the new <code>SOAPFault</code> object
205 * @exception SOAPException
206 * if there is a SOAP error
207 * @see SOAPFault#setFaultCode
208 * @see SOAPFault#setFaultString
209 * @see SOAPBody#addFault(Name faultCode, String faultString)
210 * @since SAAJ 1.3
211 */
212 public SOAPFault addFault(QName faultCode, String faultString)
213 throws SOAPException;
214
215 /**
216 * Indicates whether a <code>SOAPFault</code> object exists in this
217 * <code>SOAPBody</code> object.
218 *
219 * @return <code>true</code> if a <code>SOAPFault</code> object exists
220 * in this <code>SOAPBody</code> object; <code>false</code>
221 * otherwise
222 */
223 public boolean hasFault();
224
225 /**
226 * Returns the <code>SOAPFault</code> object in this <code>SOAPBody</code>
227 * object.
228 *
229 * @return the <code>SOAPFault</code> object in this <code>SOAPBody</code>
230 * object if present, null otherwise.
231 */
232 public SOAPFault getFault();
233
234 /**
235 * Creates a new <code>SOAPBodyElement</code> object with the specified
236 * name and adds it to this <code>SOAPBody</code> object.
237 *
238 * @param name
239 * a <code>Name</code> object with the name for the new <code>SOAPBodyElement</code>
240 * object
241 * @return the new <code>SOAPBodyElement</code> object
242 * @exception SOAPException
243 * if a SOAP error occurs
244 * @see SOAPBody#addBodyElement(javax.xml.namespace.QName)
245 */
246 public SOAPBodyElement addBodyElement(Name name) throws SOAPException;
247
248
249 /**
250 * Creates a new <code>SOAPBodyElement</code> object with the specified
251 * QName and adds it to this <code>SOAPBody</code> object.
252 *
253 * @param qname
254 * a <code>QName</code> object with the qname for the new
255 * <code>SOAPBodyElement</code> object
256 * @return the new <code>SOAPBodyElement</code> object
257 * @exception SOAPException
258 * if a SOAP error occurs
259 * @see SOAPBody#addBodyElement(Name)
260 * @since SAAJ 1.3
261 */
262 public SOAPBodyElement addBodyElement(QName qname) throws SOAPException;
263
264 /**
265 * Adds the root node of the DOM <code>{@link org.w3c.dom.Document}</code>
266 * to this <code>SOAPBody</code> object.
267 * <p>
268 * Calling this method invalidates the <code>document</code> parameter.
269 * The client application should discard all references to this <code>Document</code>
270 * and its contents upon calling <code>addDocument</code>. The behavior
271 * of an application that continues to use such references is undefined.
272 *
273 * @param document
274 * the <code>Document</code> object whose root node will be
275 * added to this <code>SOAPBody</code>.
276 * @return the <code>SOAPBodyElement</code> that represents the root node
277 * that was added.
278 * @exception SOAPException
279 * if the <code>Document</code> cannot be added
280 * @since SAAJ 1.2
281 */
282 public SOAPBodyElement addDocument(org.w3c.dom.Document document)
283 throws SOAPException;
284
285 /**
286 * Creates a new DOM <code>{@link org.w3c.dom.Document}</code> and sets
287 * the first child of this <code>SOAPBody</code> as it's document
288 * element. The child <code>SOAPElement</code> is removed as part of the
289 * process.
290 *
291 * @return the <code>{@link org.w3c.dom.Document}</code> representation
292 * of the <code>SOAPBody</code> content.
293 *
294 * @exception SOAPException
295 * if there is not exactly one child <code>SOAPElement</code> of the
296 * <code>SOAPBody</code>.
297 *
298 * @since SAAJ 1.3
299 */
300 public org.w3c.dom.Document extractContentAsDocument()
301 throws SOAPException;
302 }