001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package javax.xml.soap;
020:
021: import javax.xml.transform.Source;
022: import java.util.Iterator;
023:
024: /**
025: * <P>The container for the SOAP-specific portion of a <CODE> SOAPMessage</CODE> object. All
026: * messages are required to have a SOAP part, so when a <CODE>SOAPMessage</CODE> object is created,
027: * it will automatically have a <CODE>SOAPPart</CODE> object.</P>
028: * <p/>
029: * <P>A <CODE>SOAPPart</CODE> object is a MIME part and has the MIME headers Content-Id,
030: * Content-Location, and Content-Type. Because the value of Content-Type must be "text/xml", a
031: * <CODE> SOAPPart</CODE> object automatically has a MIME header of Content-Type with its value set
032: * to "text/xml". The value must be "text/xml" because content in the SOAP part of a message must be
033: * in XML format. Content that is not of type "text/xml" must be in an <CODE>AttachmentPart</CODE>
034: * object rather than in the <CODE>SOAPPart</CODE> object.</P>
035: * <p/>
036: * <P>When a message is sent, its SOAP part must have the MIME header Content-Type set to
037: * "text/xml". Or, from the other perspective, the SOAP part of any message that is received must
038: * have the MIME header Content-Type with a value of "text/xml".</P>
039: * <p/>
040: * <P>A client can access the <CODE>SOAPPart</CODE> object of a <CODE>SOAPMessage</CODE> object by
041: * calling the method <CODE> SOAPMessage.getSOAPPart</CODE>. The following line of code, in which
042: * <CODE>message</CODE> is a <CODE>SOAPMessage</CODE> object, retrieves the SOAP part of a
043: * message.</P> <PRE> SOAPPart soapPart = message.getSOAPPart(); </PRE>
044: * <p/>
045: * <P>A <CODE>SOAPPart</CODE> object contains a <CODE> SOAPEnvelope</CODE> object, which in turn
046: * contains a <CODE> SOAPBody</CODE> object and a <CODE>SOAPHeader</CODE> object. The
047: * <CODE>SOAPPart</CODE> method <CODE>getEnvelope</CODE> can be used to retrieve the
048: * <CODE>SOAPEnvelope</CODE> object.</P>
049: */
050: public abstract class SOAPPart implements javax.xml.soap.Node,
051: org.w3c.dom.Document {
052:
053: public SOAPPart() {
054: }
055:
056: /**
057: * Gets the <CODE>SOAPEnvelope</CODE> object associated with this <CODE>SOAPPart</CODE> object.
058: * Once the SOAP envelope is obtained, it can be used to get its contents.
059: *
060: * @return the <CODE>SOAPEnvelope</CODE> object for this <CODE> SOAPPart</CODE> object
061: * @throws SOAPException if there is a SOAP error
062: */
063: public abstract SOAPEnvelope getEnvelope() throws SOAPException;
064:
065: /**
066: * Retrieves the value of the MIME header whose name is "Content-Id".
067: *
068: * @return a <CODE>String</CODE> giving the value of the MIME header named "Content-Id"
069: * @see #setContentId(String) setContentId(java.lang.String)
070: */
071: public String getContentId() {
072:
073: String as[] = getMimeHeader("Content-Id");
074:
075: if (as != null && as.length > 0) {
076: return as[0];
077: } else {
078: return null;
079: }
080: }
081:
082: /**
083: * Retrieves the value of the MIME header whose name is "Content-Location".
084: *
085: * @return a <CODE>String</CODE> giving the value of the MIME header whose name is
086: * "Content-Location"
087: * @see #setContentLocation(String) setContentLocation(java.lang.String)
088: */
089: public String getContentLocation() {
090:
091: String as[] = getMimeHeader("Content-Location");
092:
093: if (as != null && as.length > 0) {
094: return as[0];
095: } else {
096: return null;
097: }
098: }
099:
100: /**
101: * Sets the value of the MIME header named "Content-Id" to the given <CODE>String</CODE>.
102: *
103: * @param contentId a <CODE>String</CODE> giving the value of the MIME header "Content-Id"
104: * @throws IllegalArgumentException
105: * if there is a problem in setting the content id
106: * @see #getContentId() getContentId()
107: */
108: public void setContentId(String contentId) {
109: setMimeHeader("Content-Id", contentId);
110: }
111:
112: /**
113: * Sets the value of the MIME header "Content-Location" to the given <CODE>String</CODE>.
114: *
115: * @param contentLocation a <CODE>String</CODE> giving the value of the MIME header
116: * "Content-Location"
117: * @throws IllegalArgumentException
118: * if there is a problem in setting the content location.
119: * @see #getContentLocation() getContentLocation()
120: */
121: public void setContentLocation(String contentLocation) {
122: setMimeHeader("Content-Location", contentLocation);
123: }
124:
125: /**
126: * Removes all MIME headers that match the given name.
127: *
128: * @param header a <CODE>String</CODE> giving the name of the MIME header(s) to be removed
129: */
130: public abstract void removeMimeHeader(String header);
131:
132: /** Removes all the <CODE>MimeHeader</CODE> objects for this <CODE>SOAPEnvelope</CODE> object. */
133: public abstract void removeAllMimeHeaders();
134:
135: /**
136: * Gets all the values of the <CODE>MimeHeader</CODE> object in this <CODE>SOAPPart</CODE>
137: * object that is identified by the given <CODE>String</CODE>.
138: *
139: * @param name the name of the header; example: "Content-Type"
140: * @return a <CODE>String</CODE> array giving all the values for the specified header
141: * @see #setMimeHeader(String, String) setMimeHeader(java.lang.String,
142: * java.lang.String)
143: */
144: public abstract String[] getMimeHeader(String name);
145:
146: /**
147: * Changes the first header entry that matches the given header name so that its value is the
148: * given value, adding a new header with the given name and value if no existing header is a
149: * match. If there is a match, this method clears all existing values for the first header that
150: * matches and sets the given value instead. If more than one header has the given name, this
151: * method removes all of the matching headers after the first one.
152: * <p/>
153: * <P>Note that RFC822 headers can contain only US-ASCII characters.</P>
154: *
155: * @param name a <CODE>String</CODE> giving the header name for which to search
156: * @param value a <CODE>String</CODE> giving the value to be set. This value will be substituted
157: * for the current value(s) of the first header that is a match if there is one. If
158: * there is no match, this value will be the value for a new
159: * <CODE>MimeHeader</CODE> object.
160: * @throws IllegalArgumentException
161: * if there was a problem with the specified mime header name or value
162: * @throws IllegalArgumentException
163: * if there was a problem with the specified mime header name or value
164: * @see #getMimeHeader(String) getMimeHeader(java.lang.String)
165: */
166: public abstract void setMimeHeader(String name, String value);
167:
168: /**
169: * Creates a <CODE>MimeHeader</CODE> object with the specified name and value and adds it to
170: * this <CODE>SOAPPart</CODE> object. If a <CODE>MimeHeader</CODE> with the specified name
171: * already exists, this method adds the specified value to the already existing value(s).
172: * <p/>
173: * <P>Note that RFC822 headers can contain only US-ASCII characters.</P>
174: *
175: * @param name a <CODE>String</CODE> giving the header name
176: * @param value a <CODE>String</CODE> giving the value to be set or added
177: * @throws IllegalArgumentException
178: * if there was a problem with the specified mime header name or value
179: */
180: public abstract void addMimeHeader(String name, String value);
181:
182: /**
183: * Retrieves all the headers for this <CODE>SOAPPart</CODE> object as an iterator over the
184: * <CODE>MimeHeader</CODE> objects.
185: *
186: * @return an <CODE>Iterator</CODE> object with all of the Mime headers for this
187: * <CODE>SOAPPart</CODE> object
188: */
189: public abstract Iterator getAllMimeHeaders();
190:
191: /**
192: * Retrieves all <CODE>MimeHeader</CODE> objects that match a name in the given array.
193: *
194: * @param names a <CODE>String</CODE> array with the name(s) of the MIME headers to be returned
195: * @return all of the MIME headers that match one of the names in the given array, returned as
196: * an <CODE>Iterator</CODE> object
197: */
198: public abstract Iterator getMatchingMimeHeaders(String names[]);
199:
200: /**
201: * Retrieves all <CODE>MimeHeader</CODE> objects whose name does not match a name in the given
202: * array.
203: *
204: * @param names a <CODE>String</CODE> array with the name(s) of the MIME headers not to be
205: * returned
206: * @return all of the MIME headers in this <CODE>SOAPPart</CODE> object except those that match
207: * one of the names in the given array. The nonmatching MIME headers are returned as an
208: * <CODE>Iterator</CODE> object.
209: */
210: public abstract Iterator getNonMatchingMimeHeaders(String names[]);
211:
212: /**
213: * Sets the content of the <CODE>SOAPEnvelope</CODE> object with the data from the given
214: * <CODE>Source</CODE> object.
215: *
216: * @param source javax.xml.transform.Source</CODE> object with the data to be set
217: * @throws SOAPException if there is a problem in setting the source
218: * @see #getContent() getContent()
219: */
220: public abstract void setContent(Source source) throws SOAPException;
221:
222: /**
223: * Returns the content of the SOAPEnvelope as a JAXP <CODE> Source</CODE> object.
224: *
225: * @return the content as a <CODE> javax.xml.transform.Source</CODE> object
226: * @throws SOAPException if the implementation cannot convert the specified <CODE>Source</CODE>
227: * object
228: * @see #setContent(javax.xml.transform.Source) setContent(javax.xml.transform.Source)
229: */
230: public abstract Source getContent() throws SOAPException;
231: }
|