Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package javax.xml.soap; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.util.Iterator; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import javax.xml.transform.Source; |
aoqi@0 | 31 | |
aoqi@0 | 32 | /** |
aoqi@0 | 33 | * The container for the SOAP-specific portion of a <code>SOAPMessage</code> |
aoqi@0 | 34 | * object. All messages are required to have a SOAP part, so when a |
aoqi@0 | 35 | * <code>SOAPMessage</code> object is created, it will automatically |
aoqi@0 | 36 | * have a <code>SOAPPart</code> object. |
aoqi@0 | 37 | *<P> |
aoqi@0 | 38 | * A <code>SOAPPart</code> object is a MIME part and has the MIME headers |
aoqi@0 | 39 | * Content-Id, Content-Location, and Content-Type. Because the value of |
aoqi@0 | 40 | * Content-Type must be "text/xml", a <code>SOAPPart</code> object automatically |
aoqi@0 | 41 | * has a MIME header of Content-Type with its value set to "text/xml". |
aoqi@0 | 42 | * The value must be "text/xml" because content in the SOAP part of a |
aoqi@0 | 43 | * message must be in XML format. Content that is not of type "text/xml" |
aoqi@0 | 44 | * must be in an <code>AttachmentPart</code> object rather than in the |
aoqi@0 | 45 | * <code>SOAPPart</code> object. |
aoqi@0 | 46 | * <P> |
aoqi@0 | 47 | * When a message is sent, its SOAP part must have the MIME header Content-Type |
aoqi@0 | 48 | * set to "text/xml". Or, from the other perspective, the SOAP part of any |
aoqi@0 | 49 | * message that is received must have the MIME header Content-Type with a |
aoqi@0 | 50 | * value of "text/xml". |
aoqi@0 | 51 | * <P> |
aoqi@0 | 52 | * A client can access the <code>SOAPPart</code> object of a |
aoqi@0 | 53 | * <code>SOAPMessage</code> object by |
aoqi@0 | 54 | * calling the method <code>SOAPMessage.getSOAPPart</code>. The |
aoqi@0 | 55 | * following line of code, in which <code>message</code> is a |
aoqi@0 | 56 | * <code>SOAPMessage</code> object, retrieves the SOAP part of a message. |
aoqi@0 | 57 | * <PRE> |
aoqi@0 | 58 | * SOAPPart soapPart = message.getSOAPPart(); |
aoqi@0 | 59 | * </PRE> |
aoqi@0 | 60 | * <P> |
aoqi@0 | 61 | * A <code>SOAPPart</code> object contains a <code>SOAPEnvelope</code> object, |
aoqi@0 | 62 | * which in turn contains a <code>SOAPBody</code> object and a |
aoqi@0 | 63 | * <code>SOAPHeader</code> object. |
aoqi@0 | 64 | * The <code>SOAPPart</code> method <code>getEnvelope</code> can be used |
aoqi@0 | 65 | * to retrieve the <code>SOAPEnvelope</code> object. |
aoqi@0 | 66 | * <P> |
aoqi@0 | 67 | */ |
aoqi@0 | 68 | public abstract class SOAPPart implements org.w3c.dom.Document, Node { |
aoqi@0 | 69 | |
aoqi@0 | 70 | /** |
aoqi@0 | 71 | * Gets the <code>SOAPEnvelope</code> object associated with this |
aoqi@0 | 72 | * <code>SOAPPart</code> object. Once the SOAP envelope is obtained, it |
aoqi@0 | 73 | * can be used to get its contents. |
aoqi@0 | 74 | * |
aoqi@0 | 75 | * @return the <code>SOAPEnvelope</code> object for this |
aoqi@0 | 76 | * <code>SOAPPart</code> object |
aoqi@0 | 77 | * @exception SOAPException if there is a SOAP error |
aoqi@0 | 78 | */ |
aoqi@0 | 79 | public abstract SOAPEnvelope getEnvelope() throws SOAPException; |
aoqi@0 | 80 | |
aoqi@0 | 81 | /** |
aoqi@0 | 82 | * Retrieves the value of the MIME header whose name is "Content-Id". |
aoqi@0 | 83 | * |
aoqi@0 | 84 | * @return a <code>String</code> giving the value of the MIME header |
aoqi@0 | 85 | * named "Content-Id" |
aoqi@0 | 86 | * @see #setContentId |
aoqi@0 | 87 | */ |
aoqi@0 | 88 | public String getContentId() { |
aoqi@0 | 89 | String[] values = getMimeHeader("Content-Id"); |
aoqi@0 | 90 | if (values != null && values.length > 0) |
aoqi@0 | 91 | return values[0]; |
aoqi@0 | 92 | return null; |
aoqi@0 | 93 | } |
aoqi@0 | 94 | |
aoqi@0 | 95 | /** |
aoqi@0 | 96 | * Retrieves the value of the MIME header whose name is "Content-Location". |
aoqi@0 | 97 | * |
aoqi@0 | 98 | * @return a <code>String</code> giving the value of the MIME header whose |
aoqi@0 | 99 | * name is "Content-Location" |
aoqi@0 | 100 | * @see #setContentLocation |
aoqi@0 | 101 | */ |
aoqi@0 | 102 | public String getContentLocation() { |
aoqi@0 | 103 | String[] values = getMimeHeader("Content-Location"); |
aoqi@0 | 104 | if (values != null && values.length > 0) |
aoqi@0 | 105 | return values[0]; |
aoqi@0 | 106 | return null; |
aoqi@0 | 107 | } |
aoqi@0 | 108 | |
aoqi@0 | 109 | /** |
aoqi@0 | 110 | * Sets the value of the MIME header named "Content-Id" |
aoqi@0 | 111 | * to the given <code>String</code>. |
aoqi@0 | 112 | * |
aoqi@0 | 113 | * @param contentId a <code>String</code> giving the value of the MIME |
aoqi@0 | 114 | * header "Content-Id" |
aoqi@0 | 115 | * |
aoqi@0 | 116 | * @exception IllegalArgumentException if there is a problem in |
aoqi@0 | 117 | * setting the content id |
aoqi@0 | 118 | * @see #getContentId |
aoqi@0 | 119 | */ |
aoqi@0 | 120 | public void setContentId(String contentId) |
aoqi@0 | 121 | { |
aoqi@0 | 122 | setMimeHeader("Content-Id", contentId); |
aoqi@0 | 123 | } |
aoqi@0 | 124 | /** |
aoqi@0 | 125 | * Sets the value of the MIME header "Content-Location" |
aoqi@0 | 126 | * to the given <code>String</code>. |
aoqi@0 | 127 | * |
aoqi@0 | 128 | * @param contentLocation a <code>String</code> giving the value |
aoqi@0 | 129 | * of the MIME |
aoqi@0 | 130 | * header "Content-Location" |
aoqi@0 | 131 | * @exception IllegalArgumentException if there is a problem in |
aoqi@0 | 132 | * setting the content location. |
aoqi@0 | 133 | * @see #getContentLocation |
aoqi@0 | 134 | */ |
aoqi@0 | 135 | public void setContentLocation(String contentLocation) |
aoqi@0 | 136 | { |
aoqi@0 | 137 | setMimeHeader("Content-Location", contentLocation); |
aoqi@0 | 138 | } |
aoqi@0 | 139 | /** |
aoqi@0 | 140 | * Removes all MIME headers that match the given name. |
aoqi@0 | 141 | * |
aoqi@0 | 142 | * @param header a <code>String</code> giving the name of the MIME header(s) to |
aoqi@0 | 143 | * be removed |
aoqi@0 | 144 | */ |
aoqi@0 | 145 | public abstract void removeMimeHeader(String header); |
aoqi@0 | 146 | |
aoqi@0 | 147 | /** |
aoqi@0 | 148 | * Removes all the <code>MimeHeader</code> objects for this |
aoqi@0 | 149 | * <code>SOAPEnvelope</code> object. |
aoqi@0 | 150 | */ |
aoqi@0 | 151 | public abstract void removeAllMimeHeaders(); |
aoqi@0 | 152 | |
aoqi@0 | 153 | /** |
aoqi@0 | 154 | * Gets all the values of the <code>MimeHeader</code> object |
aoqi@0 | 155 | * in this <code>SOAPPart</code> object that |
aoqi@0 | 156 | * is identified by the given <code>String</code>. |
aoqi@0 | 157 | * |
aoqi@0 | 158 | * @param name the name of the header; example: "Content-Type" |
aoqi@0 | 159 | * @return a <code>String</code> array giving all the values for the |
aoqi@0 | 160 | * specified header |
aoqi@0 | 161 | * @see #setMimeHeader |
aoqi@0 | 162 | */ |
aoqi@0 | 163 | public abstract String[] getMimeHeader(String name); |
aoqi@0 | 164 | |
aoqi@0 | 165 | /** |
aoqi@0 | 166 | * Changes the first header entry that matches the given header name |
aoqi@0 | 167 | * so that its value is the given value, adding a new header with the |
aoqi@0 | 168 | * given name and value if no |
aoqi@0 | 169 | * existing header is a match. If there is a match, this method clears |
aoqi@0 | 170 | * all existing values for the first header that matches and sets the |
aoqi@0 | 171 | * given value instead. If more than one header has |
aoqi@0 | 172 | * the given name, this method removes all of the matching headers after |
aoqi@0 | 173 | * the first one. |
aoqi@0 | 174 | * <P> |
aoqi@0 | 175 | * Note that RFC822 headers can contain only US-ASCII characters. |
aoqi@0 | 176 | * |
aoqi@0 | 177 | * @param name a <code>String</code> giving the header name |
aoqi@0 | 178 | * for which to search |
aoqi@0 | 179 | * @param value a <code>String</code> giving the value to be set. |
aoqi@0 | 180 | * This value will be substituted for the current value(s) |
aoqi@0 | 181 | * of the first header that is a match if there is one. |
aoqi@0 | 182 | * If there is no match, this value will be the value for |
aoqi@0 | 183 | * a new <code>MimeHeader</code> object. |
aoqi@0 | 184 | * |
aoqi@0 | 185 | * @exception IllegalArgumentException if there was a problem with |
aoqi@0 | 186 | * the specified mime header name or value |
aoqi@0 | 187 | * @see #getMimeHeader |
aoqi@0 | 188 | */ |
aoqi@0 | 189 | public abstract void setMimeHeader(String name, String value); |
aoqi@0 | 190 | |
aoqi@0 | 191 | /** |
aoqi@0 | 192 | * Creates a <code>MimeHeader</code> object with the specified |
aoqi@0 | 193 | * name and value and adds it to this <code>SOAPPart</code> object. |
aoqi@0 | 194 | * If a <code>MimeHeader</code> with the specified name already |
aoqi@0 | 195 | * exists, this method adds the specified value to the already |
aoqi@0 | 196 | * existing value(s). |
aoqi@0 | 197 | * <P> |
aoqi@0 | 198 | * Note that RFC822 headers can contain only US-ASCII characters. |
aoqi@0 | 199 | * |
aoqi@0 | 200 | * @param name a <code>String</code> giving the header name |
aoqi@0 | 201 | * @param value a <code>String</code> giving the value to be set |
aoqi@0 | 202 | * or added |
aoqi@0 | 203 | * @exception IllegalArgumentException if there was a problem with |
aoqi@0 | 204 | * the specified mime header name or value |
aoqi@0 | 205 | */ |
aoqi@0 | 206 | public abstract void addMimeHeader(String name, String value); |
aoqi@0 | 207 | |
aoqi@0 | 208 | /** |
aoqi@0 | 209 | * Retrieves all the headers for this <code>SOAPPart</code> object |
aoqi@0 | 210 | * as an iterator over the <code>MimeHeader</code> objects. |
aoqi@0 | 211 | * |
aoqi@0 | 212 | * @return an <code>Iterator</code> object with all of the Mime |
aoqi@0 | 213 | * headers for this <code>SOAPPart</code> object |
aoqi@0 | 214 | */ |
aoqi@0 | 215 | public abstract Iterator getAllMimeHeaders(); |
aoqi@0 | 216 | |
aoqi@0 | 217 | /** |
aoqi@0 | 218 | * Retrieves all <code>MimeHeader</code> objects that match a name in |
aoqi@0 | 219 | * the given array. |
aoqi@0 | 220 | * |
aoqi@0 | 221 | * @param names a <code>String</code> array with the name(s) of the |
aoqi@0 | 222 | * MIME headers to be returned |
aoqi@0 | 223 | * @return all of the MIME headers that match one of the names in the |
aoqi@0 | 224 | * given array, returned as an <code>Iterator</code> object |
aoqi@0 | 225 | */ |
aoqi@0 | 226 | public abstract Iterator getMatchingMimeHeaders(String[] names); |
aoqi@0 | 227 | |
aoqi@0 | 228 | /** |
aoqi@0 | 229 | * Retrieves all <code>MimeHeader</code> objects whose name does |
aoqi@0 | 230 | * not match a name in the given array. |
aoqi@0 | 231 | * |
aoqi@0 | 232 | * @param names a <code>String</code> array with the name(s) of the |
aoqi@0 | 233 | * MIME headers not to be returned |
aoqi@0 | 234 | * @return all of the MIME headers in this <code>SOAPPart</code> object |
aoqi@0 | 235 | * except those that match one of the names in the |
aoqi@0 | 236 | * given array. The nonmatching MIME headers are returned as an |
aoqi@0 | 237 | * <code>Iterator</code> object. |
aoqi@0 | 238 | */ |
aoqi@0 | 239 | public abstract Iterator getNonMatchingMimeHeaders(String[] names); |
aoqi@0 | 240 | |
aoqi@0 | 241 | /** |
aoqi@0 | 242 | * Sets the content of the <code>SOAPEnvelope</code> object with the data |
aoqi@0 | 243 | * from the given <code>Source</code> object. This <code>Source</code> |
aoqi@0 | 244 | * must contain a valid SOAP document. |
aoqi@0 | 245 | * |
aoqi@0 | 246 | * @param source the <code>javax.xml.transform.Source</code> object with the |
aoqi@0 | 247 | * data to be set |
aoqi@0 | 248 | * |
aoqi@0 | 249 | * @exception SOAPException if there is a problem in setting the source |
aoqi@0 | 250 | * @see #getContent |
aoqi@0 | 251 | */ |
aoqi@0 | 252 | public abstract void setContent(Source source) throws SOAPException; |
aoqi@0 | 253 | |
aoqi@0 | 254 | /** |
aoqi@0 | 255 | * Returns the content of the SOAPEnvelope as a JAXP <code>Source</code> |
aoqi@0 | 256 | * object. |
aoqi@0 | 257 | * |
aoqi@0 | 258 | * @return the content as a <code>javax.xml.transform.Source</code> object |
aoqi@0 | 259 | * |
aoqi@0 | 260 | * @exception SOAPException if the implementation cannot convert |
aoqi@0 | 261 | * the specified <code>Source</code> object |
aoqi@0 | 262 | * @see #setContent |
aoqi@0 | 263 | */ |
aoqi@0 | 264 | public abstract Source getContent() throws SOAPException; |
aoqi@0 | 265 | } |