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