Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxws/src/share/jaxws_classes/javax/xml/soap/SOAPPart.java
38890 views
/*1* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.soap;2627import java.util.Iterator;2829import javax.xml.transform.Source;3031/**32* The container for the SOAP-specific portion of a <code>SOAPMessage</code>33* object. All messages are required to have a SOAP part, so when a34* <code>SOAPMessage</code> object is created, it will automatically35* have a <code>SOAPPart</code> object.36*<P>37* A <code>SOAPPart</code> object is a MIME part and has the MIME headers38* Content-Id, Content-Location, and Content-Type. Because the value of39* Content-Type must be "text/xml", a <code>SOAPPart</code> object automatically40* has a MIME header of Content-Type with its value set to "text/xml".41* The value must be "text/xml" because content in the SOAP part of a42* message must be in XML format. Content that is not of type "text/xml"43* must be in an <code>AttachmentPart</code> object rather than in the44* <code>SOAPPart</code> object.45* <P>46* When a message is sent, its SOAP part must have the MIME header Content-Type47* set to "text/xml". Or, from the other perspective, the SOAP part of any48* message that is received must have the MIME header Content-Type with a49* value of "text/xml".50* <P>51* A client can access the <code>SOAPPart</code> object of a52* <code>SOAPMessage</code> object by53* calling the method <code>SOAPMessage.getSOAPPart</code>. The54* following line of code, in which <code>message</code> is a55* <code>SOAPMessage</code> object, retrieves the SOAP part of a message.56* <PRE>57* SOAPPart soapPart = message.getSOAPPart();58* </PRE>59* <P>60* A <code>SOAPPart</code> object contains a <code>SOAPEnvelope</code> object,61* which in turn contains a <code>SOAPBody</code> object and a62* <code>SOAPHeader</code> object.63* The <code>SOAPPart</code> method <code>getEnvelope</code> can be used64* to retrieve the <code>SOAPEnvelope</code> object.65* <P>66*/67public abstract class SOAPPart implements org.w3c.dom.Document, Node {6869/**70* Gets the <code>SOAPEnvelope</code> object associated with this71* <code>SOAPPart</code> object. Once the SOAP envelope is obtained, it72* can be used to get its contents.73*74* @return the <code>SOAPEnvelope</code> object for this75* <code>SOAPPart</code> object76* @exception SOAPException if there is a SOAP error77*/78public abstract SOAPEnvelope getEnvelope() throws SOAPException;7980/**81* Retrieves the value of the MIME header whose name is "Content-Id".82*83* @return a <code>String</code> giving the value of the MIME header84* named "Content-Id"85* @see #setContentId86*/87public String getContentId() {88String[] values = getMimeHeader("Content-Id");89if (values != null && values.length > 0)90return values[0];91return null;92}9394/**95* Retrieves the value of the MIME header whose name is "Content-Location".96*97* @return a <code>String</code> giving the value of the MIME header whose98* name is "Content-Location"99* @see #setContentLocation100*/101public String getContentLocation() {102String[] values = getMimeHeader("Content-Location");103if (values != null && values.length > 0)104return values[0];105return null;106}107108/**109* Sets the value of the MIME header named "Content-Id"110* to the given <code>String</code>.111*112* @param contentId a <code>String</code> giving the value of the MIME113* header "Content-Id"114*115* @exception IllegalArgumentException if there is a problem in116* setting the content id117* @see #getContentId118*/119public void setContentId(String contentId)120{121setMimeHeader("Content-Id", contentId);122}123/**124* Sets the value of the MIME header "Content-Location"125* to the given <code>String</code>.126*127* @param contentLocation a <code>String</code> giving the value128* of the MIME129* header "Content-Location"130* @exception IllegalArgumentException if there is a problem in131* setting the content location.132* @see #getContentLocation133*/134public void setContentLocation(String contentLocation)135{136setMimeHeader("Content-Location", contentLocation);137}138/**139* Removes all MIME headers that match the given name.140*141* @param header a <code>String</code> giving the name of the MIME header(s) to142* be removed143*/144public abstract void removeMimeHeader(String header);145146/**147* Removes all the <code>MimeHeader</code> objects for this148* <code>SOAPEnvelope</code> object.149*/150public abstract void removeAllMimeHeaders();151152/**153* Gets all the values of the <code>MimeHeader</code> object154* in this <code>SOAPPart</code> object that155* is identified by the given <code>String</code>.156*157* @param name the name of the header; example: "Content-Type"158* @return a <code>String</code> array giving all the values for the159* specified header160* @see #setMimeHeader161*/162public abstract String[] getMimeHeader(String name);163164/**165* Changes the first header entry that matches the given header name166* so that its value is the given value, adding a new header with the167* given name and value if no168* existing header is a match. If there is a match, this method clears169* all existing values for the first header that matches and sets the170* given value instead. If more than one header has171* the given name, this method removes all of the matching headers after172* the first one.173* <P>174* Note that RFC822 headers can contain only US-ASCII characters.175*176* @param name a <code>String</code> giving the header name177* for which to search178* @param value a <code>String</code> giving the value to be set.179* This value will be substituted for the current value(s)180* of the first header that is a match if there is one.181* If there is no match, this value will be the value for182* a new <code>MimeHeader</code> object.183*184* @exception IllegalArgumentException if there was a problem with185* the specified mime header name or value186* @see #getMimeHeader187*/188public abstract void setMimeHeader(String name, String value);189190/**191* Creates a <code>MimeHeader</code> object with the specified192* name and value and adds it to this <code>SOAPPart</code> object.193* If a <code>MimeHeader</code> with the specified name already194* exists, this method adds the specified value to the already195* existing value(s).196* <P>197* Note that RFC822 headers can contain only US-ASCII characters.198*199* @param name a <code>String</code> giving the header name200* @param value a <code>String</code> giving the value to be set201* or added202* @exception IllegalArgumentException if there was a problem with203* the specified mime header name or value204*/205public abstract void addMimeHeader(String name, String value);206207/**208* Retrieves all the headers for this <code>SOAPPart</code> object209* as an iterator over the <code>MimeHeader</code> objects.210*211* @return an <code>Iterator</code> object with all of the Mime212* headers for this <code>SOAPPart</code> object213*/214public abstract Iterator getAllMimeHeaders();215216/**217* Retrieves all <code>MimeHeader</code> objects that match a name in218* the given array.219*220* @param names a <code>String</code> array with the name(s) of the221* MIME headers to be returned222* @return all of the MIME headers that match one of the names in the223* given array, returned as an <code>Iterator</code> object224*/225public abstract Iterator getMatchingMimeHeaders(String[] names);226227/**228* Retrieves all <code>MimeHeader</code> objects whose name does229* not match a name in the given array.230*231* @param names a <code>String</code> array with the name(s) of the232* MIME headers not to be returned233* @return all of the MIME headers in this <code>SOAPPart</code> object234* except those that match one of the names in the235* given array. The nonmatching MIME headers are returned as an236* <code>Iterator</code> object.237*/238public abstract Iterator getNonMatchingMimeHeaders(String[] names);239240/**241* Sets the content of the <code>SOAPEnvelope</code> object with the data242* from the given <code>Source</code> object. This <code>Source</code>243* must contain a valid SOAP document.244*245* @param source the <code>javax.xml.transform.Source</code> object with the246* data to be set247*248* @exception SOAPException if there is a problem in setting the source249* @see #getContent250*/251public abstract void setContent(Source source) throws SOAPException;252253/**254* Returns the content of the SOAPEnvelope as a JAXP <code>Source</code>255* object.256*257* @return the content as a <code>javax.xml.transform.Source</code> object258*259* @exception SOAPException if the implementation cannot convert260* the specified <code>Source</code> object261* @see #setContent262*/263public abstract Source getContent() throws SOAPException;264}265266267