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 import java.util.Iterator; 29 30 import javax.xml.transform.Source; 31 32 /** 33 * The container for the SOAP-specific portion of a <code>SOAPMessage</code> 34 * object. All messages are required to have a SOAP part, so when a 35 * <code>SOAPMessage</code> object is created, it will automatically 36 * have a <code>SOAPPart</code> object. 37 *<P> 38 * A <code>SOAPPart</code> object is a MIME part and has the MIME headers 39 * Content-Id, Content-Location, and Content-Type. Because the value of 40 * Content-Type must be "text/xml", a <code>SOAPPart</code> object automatically 41 * has a MIME header of Content-Type with its value set to "text/xml". 42 * The value must be "text/xml" because content in the SOAP part of a 43 * message must be in XML format. Content that is not of type "text/xml" 44 * must be in an <code>AttachmentPart</code> object rather than in the 45 * <code>SOAPPart</code> object. 46 * <P> 47 * When a message is sent, its SOAP part must have the MIME header Content-Type 48 * set to "text/xml". Or, from the other perspective, the SOAP part of any 49 * message that is received must have the MIME header Content-Type with a 50 * value of "text/xml". 51 * <P> 52 * A client can access the <code>SOAPPart</code> object of a 53 * <code>SOAPMessage</code> object by 54 * calling the method <code>SOAPMessage.getSOAPPart</code>. The 55 * following line of code, in which <code>message</code> is a 56 * <code>SOAPMessage</code> object, retrieves the SOAP part of a message. 57 * <PRE> 58 * SOAPPart soapPart = message.getSOAPPart(); 59 * </PRE> 60 * <P> 61 * A <code>SOAPPart</code> object contains a <code>SOAPEnvelope</code> object, 62 * which in turn contains a <code>SOAPBody</code> object and a 63 * <code>SOAPHeader</code> object. 64 * The <code>SOAPPart</code> method <code>getEnvelope</code> can be used 65 * to retrieve the <code>SOAPEnvelope</code> object. 66 * <P> 67 * 68 * @since 1.6 69 */ 70 public abstract class SOAPPart implements org.w3c.dom.Document, Node { 71 72 /** 73 * Gets the <code>SOAPEnvelope</code> object associated with this 74 * <code>SOAPPart</code> object. Once the SOAP envelope is obtained, it 75 * can be used to get its contents. 76 * 77 * @return the <code>SOAPEnvelope</code> object for this 78 * <code>SOAPPart</code> object 79 * @exception SOAPException if there is a SOAP error 80 */ 81 public abstract SOAPEnvelope getEnvelope() throws SOAPException; 82 83 /** 84 * Retrieves the value of the MIME header whose name is "Content-Id". 85 * 86 * @return a <code>String</code> giving the value of the MIME header 87 * named "Content-Id" 88 * @see #setContentId 89 */ 90 public String getContentId() { 91 String[] values = getMimeHeader("Content-Id"); 92 if (values != null && values.length > 0) 93 return values[0]; 94 return null; 95 } 96 97 /** 98 * Retrieves the value of the MIME header whose name is "Content-Location". 99 * 100 * @return a <code>String</code> giving the value of the MIME header whose 101 * name is "Content-Location" 102 * @see #setContentLocation 103 */ 104 public String getContentLocation() { 105 String[] values = getMimeHeader("Content-Location"); 106 if (values != null && values.length > 0) 107 return values[0]; 108 return null; 109 } 110 111 /** 112 * Sets the value of the MIME header named "Content-Id" 113 * to the given <code>String</code>. 114 * 115 * @param contentId a <code>String</code> giving the value of the MIME 116 * header "Content-Id" 117 * 118 * @exception IllegalArgumentException if there is a problem in 119 * setting the content id 120 * @see #getContentId 121 */ 122 public void setContentId(String contentId) 123 { 124 setMimeHeader("Content-Id", contentId); 125 } 126 /** 127 * Sets the value of the MIME header "Content-Location" 128 * to the given <code>String</code>. 129 * 130 * @param contentLocation a <code>String</code> giving the value 131 * of the MIME 132 * header "Content-Location" 133 * @exception IllegalArgumentException if there is a problem in 134 * setting the content location. 135 * @see #getContentLocation 136 */ 137 public void setContentLocation(String contentLocation) 138 { 139 setMimeHeader("Content-Location", contentLocation); 140 } 141 /** 142 * Removes all MIME headers that match the given name. 143 * 144 * @param header a <code>String</code> giving the name of the MIME header(s) to 145 * be removed 146 */ 147 public abstract void removeMimeHeader(String header); 148 149 /** 150 * Removes all the <code>MimeHeader</code> objects for this 151 * <code>SOAPEnvelope</code> object. 152 */ 153 public abstract void removeAllMimeHeaders(); 154 155 /** 156 * Gets all the values of the <code>MimeHeader</code> object 157 * in this <code>SOAPPart</code> object that 158 * is identified by the given <code>String</code>. 159 * 160 * @param name the name of the header; example: "Content-Type" 161 * @return a <code>String</code> array giving all the values for the 162 * specified header 163 * @see #setMimeHeader 164 */ 165 public abstract String[] getMimeHeader(String name); 166 167 /** 168 * Changes the first header entry that matches the given header name 169 * so that its value is the given value, adding a new header with the 170 * given name and value if no 171 * existing header is a match. If there is a match, this method clears 172 * all existing values for the first header that matches and sets the 173 * given value instead. If more than one header has 174 * the given name, this method removes all of the matching headers after 175 * the first one. 176 * <P> 177 * Note that RFC822 headers can contain only US-ASCII characters. 178 * 179 * @param name a <code>String</code> giving the header name 180 * for which to search 181 * @param value a <code>String</code> giving the value to be set. 182 * This value will be substituted for the current value(s) 183 * of the first header that is a match if there is one. 184 * If there is no match, this value will be the value for 185 * a new <code>MimeHeader</code> object. 186 * 187 * @exception IllegalArgumentException if there was a problem with 188 * the specified mime header name or value 189 * @see #getMimeHeader 190 */ 191 public abstract void setMimeHeader(String name, String value); 192 193 /** 194 * Creates a <code>MimeHeader</code> object with the specified 195 * name and value and adds it to this <code>SOAPPart</code> object. 196 * If a <code>MimeHeader</code> with the specified name already 197 * exists, this method adds the specified value to the already 198 * existing value(s). 199 * <P> 200 * Note that RFC822 headers can contain only US-ASCII characters. 201 * 202 * @param name a <code>String</code> giving the header name 203 * @param value a <code>String</code> giving the value to be set 204 * or added 205 * @exception IllegalArgumentException if there was a problem with 206 * the specified mime header name or value 207 */ 208 public abstract void addMimeHeader(String name, String value); 209 210 /** 211 * Retrieves all the headers for this <code>SOAPPart</code> object 212 * as an iterator over the <code>MimeHeader</code> objects. 213 * 214 * @return an <code>Iterator</code> object with all of the Mime 215 * headers for this <code>SOAPPart</code> object 216 */ 217 public abstract Iterator getAllMimeHeaders(); 218 219 /** 220 * Retrieves all <code>MimeHeader</code> objects that match a name in 221 * the given array. 222 * 223 * @param names a <code>String</code> array with the name(s) of the 224 * MIME headers to be returned 225 * @return all of the MIME headers that match one of the names in the 226 * given array, returned as an <code>Iterator</code> object 227 */ 228 public abstract Iterator getMatchingMimeHeaders(String[] names); 229 230 /** 231 * Retrieves all <code>MimeHeader</code> objects whose name does 232 * not match a name in the given array. 233 * 234 * @param names a <code>String</code> array with the name(s) of the 235 * MIME headers not to be returned 236 * @return all of the MIME headers in this <code>SOAPPart</code> object 237 * except those that match one of the names in the 238 * given array. The nonmatching MIME headers are returned as an 239 * <code>Iterator</code> object. 240 */ 241 public abstract Iterator getNonMatchingMimeHeaders(String[] names); 242 243 /** 244 * Sets the content of the <code>SOAPEnvelope</code> object with the data 245 * from the given <code>Source</code> object. This <code>Source</code> 246 * must contain a valid SOAP document. 247 * 248 * @param source the <code>javax.xml.transform.Source</code> object with the 249 * data to be set 250 * 251 * @exception SOAPException if there is a problem in setting the source 252 * @see #getContent 253 */ 254 public abstract void setContent(Source source) throws SOAPException; 255 256 /** 257 * Returns the content of the SOAPEnvelope as a JAXP <code>Source</code> 258 * object. 259 * 260 * @return the content as a <code>javax.xml.transform.Source</code> object 261 * 262 * @exception SOAPException if the implementation cannot convert 263 * the specified <code>Source</code> object 264 * @see #setContent 265 */ 266 public abstract Source getContent() throws SOAPException; 267 } | 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 import java.util.Iterator; 29 30 import javax.xml.transform.Source; 31 32 /** 33 * The container for the SOAP-specific portion of a {@code SOAPMessage} 34 * object. All messages are required to have a SOAP part, so when a 35 * {@code SOAPMessage} object is created, it will automatically 36 * have a {@code SOAPPart} object. 37 * <P> 38 * A {@code SOAPPart} object is a MIME part and has the MIME headers 39 * Content-Id, Content-Location, and Content-Type. Because the value of 40 * Content-Type must be "text/xml", a {@code SOAPPart} object automatically 41 * has a MIME header of Content-Type with its value set to "text/xml". 42 * The value must be "text/xml" because content in the SOAP part of a 43 * message must be in XML format. Content that is not of type "text/xml" 44 * must be in an {@code AttachmentPart} object rather than in the 45 * {@code SOAPPart} object. 46 * <P> 47 * When a message is sent, its SOAP part must have the MIME header Content-Type 48 * set to "text/xml". Or, from the other perspective, the SOAP part of any 49 * message that is received must have the MIME header Content-Type with a 50 * value of "text/xml". 51 * <P> 52 * A client can access the {@code SOAPPart} object of a 53 * {@code SOAPMessage} object by 54 * calling the method {@code SOAPMessage.getSOAPPart}. The 55 * following line of code, in which {@code message} is a 56 * {@code SOAPMessage} object, retrieves the SOAP part of a message. 57 * <PRE> 58 * SOAPPart soapPart = message.getSOAPPart(); 59 * </PRE> 60 * <P> 61 * A {@code SOAPPart} object contains a {@code SOAPEnvelope} object, 62 * which in turn contains a {@code SOAPBody} object and a 63 * {@code SOAPHeader} object. 64 * The {@code SOAPPart} method {@code getEnvelope} can be used 65 * to retrieve the {@code SOAPEnvelope} object. 66 * 67 * @since 1.6 68 */ 69 public abstract class SOAPPart implements org.w3c.dom.Document, Node { 70 71 /** 72 * Gets the {@code SOAPEnvelope} object associated with this 73 * {@code SOAPPart} object. Once the SOAP envelope is obtained, it 74 * can be used to get its contents. 75 * 76 * @return the {@code SOAPEnvelope} object for this 77 * {@code SOAPPart} object 78 * @exception SOAPException if there is a SOAP error 79 */ 80 public abstract SOAPEnvelope getEnvelope() throws SOAPException; 81 82 /** 83 * Retrieves the value of the MIME header whose name is "Content-Id". 84 * 85 * @return a {@code String} giving the value of the MIME header 86 * named "Content-Id" 87 * @see #setContentId 88 */ 89 public String getContentId() { 90 String[] values = getMimeHeader("Content-Id"); 91 if (values != null && values.length > 0) 92 return values[0]; 93 return null; 94 } 95 96 /** 97 * Retrieves the value of the MIME header whose name is "Content-Location". 98 * 99 * @return a {@code String} giving the value of the MIME header whose 100 * name is "Content-Location" 101 * @see #setContentLocation 102 */ 103 public String getContentLocation() { 104 String[] values = getMimeHeader("Content-Location"); 105 if (values != null && values.length > 0) 106 return values[0]; 107 return null; 108 } 109 110 /** 111 * Sets the value of the MIME header named "Content-Id" 112 * to the given {@code String}. 113 * 114 * @param contentId a {@code String} giving the value of the MIME 115 * header "Content-Id" 116 * 117 * @exception IllegalArgumentException if there is a problem in 118 * setting the content id 119 * @see #getContentId 120 */ 121 public void setContentId(String contentId) 122 { 123 setMimeHeader("Content-Id", contentId); 124 } 125 /** 126 * Sets the value of the MIME header "Content-Location" 127 * to the given {@code String}. 128 * 129 * @param contentLocation a {@code String} giving the value 130 * of the MIME 131 * header "Content-Location" 132 * @exception IllegalArgumentException if there is a problem in 133 * setting the content location. 134 * @see #getContentLocation 135 */ 136 public void setContentLocation(String contentLocation) 137 { 138 setMimeHeader("Content-Location", contentLocation); 139 } 140 /** 141 * Removes all MIME headers that match the given name. 142 * 143 * @param header a {@code String} giving the name of the MIME header(s) to 144 * be removed 145 */ 146 public abstract void removeMimeHeader(String header); 147 148 /** 149 * Removes all the {@code MimeHeader} objects for this 150 * {@code SOAPEnvelope} object. 151 */ 152 public abstract void removeAllMimeHeaders(); 153 154 /** 155 * Gets all the values of the {@code MimeHeader} object 156 * in this {@code SOAPPart} object that 157 * is identified by the given {@code String}. 158 * 159 * @param name the name of the header; example: "Content-Type" 160 * @return a {@code String} array giving all the values for the 161 * specified header 162 * @see #setMimeHeader 163 */ 164 public abstract String[] getMimeHeader(String name); 165 166 /** 167 * Changes the first header entry that matches the given header name 168 * so that its value is the given value, adding a new header with the 169 * given name and value if no 170 * existing header is a match. If there is a match, this method clears 171 * all existing values for the first header that matches and sets the 172 * given value instead. If more than one header has 173 * the given name, this method removes all of the matching headers after 174 * the first one. 175 * <P> 176 * Note that RFC822 headers can contain only US-ASCII characters. 177 * 178 * @param name a {@code String} giving the header name 179 * for which to search 180 * @param value a {@code String} giving the value to be set. 181 * This value will be substituted for the current value(s) 182 * of the first header that is a match if there is one. 183 * If there is no match, this value will be the value for 184 * a new {@code MimeHeader} object. 185 * 186 * @exception IllegalArgumentException if there was a problem with 187 * the specified mime header name or value 188 * @see #getMimeHeader 189 */ 190 public abstract void setMimeHeader(String name, String value); 191 192 /** 193 * Creates a {@code MimeHeader} object with the specified 194 * name and value and adds it to this {@code SOAPPart} object. 195 * If a {@code MimeHeader} with the specified name already 196 * exists, this method adds the specified value to the already 197 * existing value(s). 198 * <P> 199 * Note that RFC822 headers can contain only US-ASCII characters. 200 * 201 * @param name a {@code String} giving the header name 202 * @param value a {@code String} giving the value to be set 203 * or added 204 * @exception IllegalArgumentException if there was a problem with 205 * the specified mime header name or value 206 */ 207 public abstract void addMimeHeader(String name, String value); 208 209 /** 210 * Retrieves all the headers for this {@code SOAPPart} object 211 * as an iterator over the {@code MimeHeader} objects. 212 * 213 * @return an {@code Iterator} object with all of the Mime 214 * headers for this {@code SOAPPart} object 215 */ 216 public abstract Iterator getAllMimeHeaders(); 217 218 /** 219 * Retrieves all {@code MimeHeader} objects that match a name in 220 * the given array. 221 * 222 * @param names a {@code String} array with the name(s) of the 223 * MIME headers to be returned 224 * @return all of the MIME headers that match one of the names in the 225 * given array, returned as an {@code Iterator} object 226 */ 227 public abstract Iterator getMatchingMimeHeaders(String[] names); 228 229 /** 230 * Retrieves all {@code MimeHeader} objects whose name does 231 * not match a name in the given array. 232 * 233 * @param names a {@code String} array with the name(s) of the 234 * MIME headers not to be returned 235 * @return all of the MIME headers in this {@code SOAPPart} object 236 * except those that match one of the names in the 237 * given array. The nonmatching MIME headers are returned as an 238 * {@code Iterator} object. 239 */ 240 public abstract Iterator getNonMatchingMimeHeaders(String[] names); 241 242 /** 243 * Sets the content of the {@code SOAPEnvelope} object with the data 244 * from the given {@code Source} object. This {@code Source} 245 * must contain a valid SOAP document. 246 * 247 * @param source the {@code javax.xml.transform.Source} object with the 248 * data to be set 249 * 250 * @exception SOAPException if there is a problem in setting the source 251 * @see #getContent 252 */ 253 public abstract void setContent(Source source) throws SOAPException; 254 255 /** 256 * Returns the content of the SOAPEnvelope as a JAXP {@code Source} 257 * object. 258 * 259 * @return the content as a {@code javax.xml.transform.Source} object 260 * 261 * @exception SOAPException if the implementation cannot convert 262 * the specified {@code Source} object 263 * @see #setContent 264 */ 265 public abstract Source getContent() throws SOAPException; 266 } |