Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxws/src/share/jaxws_classes/javax/xml/soap/SOAPEnvelope.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;262728/**29* The container for the SOAPHeader and SOAPBody portions of a30* <code>SOAPPart</code> object. By default, a <code>SOAPMessage</code>31* object is created with a <code>SOAPPart</code> object that has a32* <code>SOAPEnvelope</code> object. The <code>SOAPEnvelope</code> object33* by default has an empty <code>SOAPBody</code> object and an empty34* <code>SOAPHeader</code> object. The <code>SOAPBody</code> object is35* required, and the <code>SOAPHeader</code> object, though36* optional, is used in the majority of cases. If the37* <code>SOAPHeader</code> object is not needed, it can be deleted,38* which is shown later.39* <P>40* A client can access the <code>SOAPHeader</code> and <code>SOAPBody</code>41* objects by calling the methods <code>SOAPEnvelope.getHeader</code> and42* <code>SOAPEnvelope.getBody</code>. The43* following lines of code use these two methods after starting with44* the <code>SOAPMessage</code>45* object <i>message</i> to get the <code>SOAPPart</code> object <i>sp</i>,46* which is then used to get the <code>SOAPEnvelope</code> object <i>se</i>.47*48* <PRE>49* SOAPPart sp = message.getSOAPPart();50* SOAPEnvelope se = sp.getEnvelope();51* SOAPHeader sh = se.getHeader();52* SOAPBody sb = se.getBody();53* </PRE>54* <P>55* It is possible to change the body or header of a <code>SOAPEnvelope</code>56* object by retrieving the current one, deleting it, and then adding57* a new body or header. The <code>javax.xml.soap.Node</code> method58* <code>deleteNode</code> deletes the XML element (node) on which it is59* called. For example, the following line of code deletes the60* <code>SOAPBody</code> object that is retrieved by the method <code>getBody</code>.61* <PRE>62* se.getBody().detachNode();63* </PRE>64* To create a <code>SOAPHeader</code> object to replace the one that was removed,65* a client uses66* the method <code>SOAPEnvelope.addHeader</code>, which creates a new header and67* adds it to the <code>SOAPEnvelope</code> object. Similarly, the method68* <code>addBody</code> creates a new <code>SOAPBody</code> object and adds69* it to the <code>SOAPEnvelope</code> object. The following code fragment70* retrieves the current header, removes it, and adds a new one. Then71* it retrieves the current body, removes it, and adds a new one.72*73* <PRE>74* SOAPPart sp = message.getSOAPPart();75* SOAPEnvelope se = sp.getEnvelope();76* se.getHeader().detachNode();77* SOAPHeader sh = se.addHeader();78* se.getBody().detachNode();79* SOAPBody sb = se.addBody();80* </PRE>81* It is an error to add a <code>SOAPBody</code> or <code>SOAPHeader</code>82* object if one already exists.83* <P>84* The <code>SOAPEnvelope</code> interface provides three methods for creating85* <code>Name</code> objects. One method creates <code>Name</code> objects with86* a local name, a namespace prefix, and a namesapce URI. The second method creates87* <code>Name</code> objects with a local name and a namespace prefix, and the third88* creates <code>Name</code> objects with just a local name. The following line of89* code, in which <i>se</i> is a <code>SOAPEnvelope</code> object, creates a new90* <code>Name</code> object with all three.91* <PRE>92* Name name = se.createName("GetLastTradePrice", "WOMBAT",93* "http://www.wombat.org/trader");94* </PRE>95*/96public interface SOAPEnvelope extends SOAPElement {9798/**99* Creates a new <code>Name</code> object initialized with the100* given local name, namespace prefix, and namespace URI.101* <P>102* This factory method creates <code>Name</code> objects for use in103* the SOAP/XML document.104*105* @param localName a <code>String</code> giving the local name106* @param prefix a <code>String</code> giving the prefix of the namespace107* @param uri a <code>String</code> giving the URI of the namespace108* @return a <code>Name</code> object initialized with the given109* local name, namespace prefix, and namespace URI110* @throws SOAPException if there is a SOAP error111*/112public abstract Name createName(String localName, String prefix,113String uri)114throws SOAPException;115116/**117* Creates a new <code>Name</code> object initialized with the118* given local name.119* <P>120* This factory method creates <code>Name</code> objects for use in121* the SOAP/XML document.122*123* @param localName a <code>String</code> giving the local name124* @return a <code>Name</code> object initialized with the given125* local name126* @throws SOAPException if there is a SOAP error127*/128public abstract Name createName(String localName)129throws SOAPException;130131/**132* Returns the <code>SOAPHeader</code> object for133* this <code>SOAPEnvelope</code> object.134* <P>135* A new <code>SOAPMessage</code> object is by default created with a136* <code>SOAPEnvelope</code> object that contains an empty137* <code>SOAPHeader</code> object. As a result, the method138* <code>getHeader</code> will always return a <code>SOAPHeader</code>139* object unless the header has been removed and a new one has not140* been added.141*142* @return the <code>SOAPHeader</code> object or <code>null</code> if143* there is none144* @exception SOAPException if there is a problem obtaining the145* <code>SOAPHeader</code> object146*/147public SOAPHeader getHeader() throws SOAPException;148149/**150* Returns the <code>SOAPBody</code> object associated with this151* <code>SOAPEnvelope</code> object.152* <P>153* A new <code>SOAPMessage</code> object is by default created with a154* <code>SOAPEnvelope</code> object that contains an empty155* <code>SOAPBody</code> object. As a result, the method156* <code>getBody</code> will always return a <code>SOAPBody</code>157* object unless the body has been removed and a new one has not158* been added.159*160* @return the <code>SOAPBody</code> object for this161* <code>SOAPEnvelope</code> object or <code>null</code>162* if there is none163* @exception SOAPException if there is a problem obtaining the164* <code>SOAPBody</code> object165*/166public SOAPBody getBody() throws SOAPException;167/**168* Creates a <code>SOAPHeader</code> object and sets it as the169* <code>SOAPHeader</code> object for this <code>SOAPEnvelope</code>170* object.171* <P>172* It is illegal to add a header when the envelope already173* contains a header. Therefore, this method should be called174* only after the existing header has been removed.175*176* @return the new <code>SOAPHeader</code> object177*178* @exception SOAPException if this179* <code>SOAPEnvelope</code> object already contains a180* valid <code>SOAPHeader</code> object181*/182public SOAPHeader addHeader() throws SOAPException;183/**184* Creates a <code>SOAPBody</code> object and sets it as the185* <code>SOAPBody</code> object for this <code>SOAPEnvelope</code>186* object.187* <P>188* It is illegal to add a body when the envelope already189* contains a body. Therefore, this method should be called190* only after the existing body has been removed.191*192* @return the new <code>SOAPBody</code> object193*194* @exception SOAPException if this195* <code>SOAPEnvelope</code> object already contains a196* valid <code>SOAPBody</code> object197*/198public SOAPBody addBody() throws SOAPException;199}200201202