001 /* 002 * Copyright 2001-2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package javax.xml.soap; 017 018 import javax.xml.transform.Source; 019 import java.util.Iterator; 020 021 /** 022 * <P>The container for the SOAP-specific portion of a <CODE> 023 * SOAPMessage</CODE> object. All messages are required to have a 024 * SOAP part, so when a <CODE>SOAPMessage</CODE> object is 025 * created, it will automatically have a <CODE>SOAPPart</CODE> 026 * object.</P> 027 * 028 * <P>A <CODE>SOAPPart</CODE> object is a MIME part and has the 029 * MIME headers Content-Id, Content-Location, and Content-Type. 030 * Because the value of Content-Type must be "text/xml", a <CODE> 031 * SOAPPart</CODE> object automatically has a MIME header of 032 * Content-Type with its value set to "text/xml". The value must 033 * be "text/xml" because content in the SOAP part of a message 034 * must be in XML format. Content that is not of type "text/xml" 035 * must be in an <CODE>AttachmentPart</CODE> object rather than in 036 * the <CODE>SOAPPart</CODE> object.</P> 037 * 038 * <P>When a message is sent, its SOAP part must have the MIME 039 * header Content-Type set to "text/xml". Or, from the other 040 * perspective, the SOAP part of any message that is received must 041 * have the MIME header Content-Type with a value of 042 * "text/xml".</P> 043 * 044 * <P>A client can access the <CODE>SOAPPart</CODE> object of a 045 * <CODE>SOAPMessage</CODE> object by calling the method <CODE> 046 * SOAPMessage.getSOAPPart</CODE>. The following line of code, in 047 * which <CODE>message</CODE> is a <CODE>SOAPMessage</CODE> 048 * object, retrieves the SOAP part of a message.</P> 049 * <PRE> 050 * SOAPPart soapPart = message.getSOAPPart(); 051 * </PRE> 052 * 053 * <P>A <CODE>SOAPPart</CODE> object contains a <CODE> 054 * SOAPEnvelope</CODE> object, which in turn contains a <CODE> 055 * SOAPBody</CODE> object and a <CODE>SOAPHeader</CODE> object. 056 * The <CODE>SOAPPart</CODE> method <CODE>getEnvelope</CODE> can 057 * be used to retrieve the <CODE>SOAPEnvelope</CODE> object.</P> 058 */ 059 public abstract class SOAPPart implements org.w3c.dom.Document { 060 061 public SOAPPart() {} 062 063 /** 064 * Gets the <CODE>SOAPEnvelope</CODE> object associated with 065 * this <CODE>SOAPPart</CODE> object. Once the SOAP envelope is 066 * obtained, it can be used to get its contents. 067 * @return the <CODE>SOAPEnvelope</CODE> object for this <CODE> 068 * SOAPPart</CODE> object 069 * @throws SOAPException if there is a SOAP error 070 */ 071 public abstract SOAPEnvelope getEnvelope() throws SOAPException; 072 073 /** 074 * Retrieves the value of the MIME header whose name is 075 * "Content-Id". 076 * @return a <CODE>String</CODE> giving the value of the MIME 077 * header named "Content-Id" 078 * @see #setContentId(java.lang.String) setContentId(java.lang.String) 079 */ 080 public String getContentId() { 081 082 String as[] = getMimeHeader("Content-Id"); 083 084 if (as != null && as.length > 0) { 085 return as[0]; 086 } else { 087 return null; 088 } 089 } 090 091 /** 092 * Retrieves the value of the MIME header whose name is 093 * "Content-Location". 094 * @return a <CODE>String</CODE> giving the value of the MIME 095 * header whose name is "Content-Location" 096 * @see #setContentLocation(java.lang.String) setContentLocation(java.lang.String) 097 */ 098 public String getContentLocation() { 099 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 }