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