aoqi@0: /*
aoqi@0: * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0: *
aoqi@0: * This code is free software; you can redistribute it and/or modify it
aoqi@0: * under the terms of the GNU General Public License version 2 only, as
aoqi@0: * published by the Free Software Foundation. Oracle designates this
aoqi@0: * particular file as subject to the "Classpath" exception as provided
aoqi@0: * by Oracle in the LICENSE file that accompanied this code.
aoqi@0: *
aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0: * accompanied this code).
aoqi@0: *
aoqi@0: * You should have received a copy of the GNU General Public License version
aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0: *
aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0: * or visit www.oracle.com if you need additional information or have any
aoqi@0: * questions.
aoqi@0: */
aoqi@0:
aoqi@0: package javax.xml.soap;
aoqi@0:
aoqi@0:
aoqi@0: /**
aoqi@0: * The container for the SOAPHeader and SOAPBody portions of a
aoqi@0: * SOAPPart
object. By default, a SOAPMessage
aoqi@0: * object is created with a SOAPPart
object that has a
aoqi@0: * SOAPEnvelope
object. The SOAPEnvelope
object
aoqi@0: * by default has an empty SOAPBody
object and an empty
aoqi@0: * SOAPHeader
object. The SOAPBody
object is
aoqi@0: * required, and the SOAPHeader
object, though
aoqi@0: * optional, is used in the majority of cases. If the
aoqi@0: * SOAPHeader
object is not needed, it can be deleted,
aoqi@0: * which is shown later.
aoqi@0: *
aoqi@0: * A client can access the SOAPHeader
and SOAPBody
aoqi@0: * objects by calling the methods SOAPEnvelope.getHeader
and
aoqi@0: * SOAPEnvelope.getBody
. The
aoqi@0: * following lines of code use these two methods after starting with
aoqi@0: * the SOAPMessage
aoqi@0: * object message to get the SOAPPart
object sp,
aoqi@0: * which is then used to get the SOAPEnvelope
object se.
aoqi@0: *
aoqi@0: *
aoqi@0: * SOAPPart sp = message.getSOAPPart(); aoqi@0: * SOAPEnvelope se = sp.getEnvelope(); aoqi@0: * SOAPHeader sh = se.getHeader(); aoqi@0: * SOAPBody sb = se.getBody(); aoqi@0: *aoqi@0: *
aoqi@0: * It is possible to change the body or header of a SOAPEnvelope
aoqi@0: * object by retrieving the current one, deleting it, and then adding
aoqi@0: * a new body or header. The javax.xml.soap.Node
method
aoqi@0: * deleteNode
deletes the XML element (node) on which it is
aoqi@0: * called. For example, the following line of code deletes the
aoqi@0: * SOAPBody
object that is retrieved by the method getBody
.
aoqi@0: *
aoqi@0: * se.getBody().detachNode(); aoqi@0: *aoqi@0: * To create a
SOAPHeader
object to replace the one that was removed,
aoqi@0: * a client uses
aoqi@0: * the method SOAPEnvelope.addHeader
, which creates a new header and
aoqi@0: * adds it to the SOAPEnvelope
object. Similarly, the method
aoqi@0: * addBody
creates a new SOAPBody
object and adds
aoqi@0: * it to the SOAPEnvelope
object. The following code fragment
aoqi@0: * retrieves the current header, removes it, and adds a new one. Then
aoqi@0: * it retrieves the current body, removes it, and adds a new one.
aoqi@0: *
aoqi@0: * aoqi@0: * SOAPPart sp = message.getSOAPPart(); aoqi@0: * SOAPEnvelope se = sp.getEnvelope(); aoqi@0: * se.getHeader().detachNode(); aoqi@0: * SOAPHeader sh = se.addHeader(); aoqi@0: * se.getBody().detachNode(); aoqi@0: * SOAPBody sb = se.addBody(); aoqi@0: *aoqi@0: * It is an error to add a
SOAPBody
or SOAPHeader
aoqi@0: * object if one already exists.
aoqi@0: *
aoqi@0: * The SOAPEnvelope
interface provides three methods for creating
aoqi@0: * Name
objects. One method creates Name
objects with
aoqi@0: * a local name, a namespace prefix, and a namesapce URI. The second method creates
aoqi@0: * Name
objects with a local name and a namespace prefix, and the third
aoqi@0: * creates Name
objects with just a local name. The following line of
aoqi@0: * code, in which se is a SOAPEnvelope
object, creates a new
aoqi@0: * Name
object with all three.
aoqi@0: *
aoqi@0: * Name name = se.createName("GetLastTradePrice", "WOMBAT", aoqi@0: * "http://www.wombat.org/trader"); aoqi@0: *aoqi@0: */ aoqi@0: public interface SOAPEnvelope extends SOAPElement { aoqi@0: aoqi@0: /** aoqi@0: * Creates a new
Name
object initialized with the
aoqi@0: * given local name, namespace prefix, and namespace URI.
aoqi@0: *
aoqi@0: * This factory method creates Name
objects for use in
aoqi@0: * the SOAP/XML document.
aoqi@0: *
aoqi@0: * @param localName a String
giving the local name
aoqi@0: * @param prefix a String
giving the prefix of the namespace
aoqi@0: * @param uri a String
giving the URI of the namespace
aoqi@0: * @return a Name
object initialized with the given
aoqi@0: * local name, namespace prefix, and namespace URI
aoqi@0: * @throws SOAPException if there is a SOAP error
aoqi@0: */
aoqi@0: public abstract Name createName(String localName, String prefix,
aoqi@0: String uri)
aoqi@0: throws SOAPException;
aoqi@0:
aoqi@0: /**
aoqi@0: * Creates a new Name
object initialized with the
aoqi@0: * given local name.
aoqi@0: *
aoqi@0: * This factory method creates Name
objects for use in
aoqi@0: * the SOAP/XML document.
aoqi@0: *
aoqi@0: * @param localName a String
giving the local name
aoqi@0: * @return a Name
object initialized with the given
aoqi@0: * local name
aoqi@0: * @throws SOAPException if there is a SOAP error
aoqi@0: */
aoqi@0: public abstract Name createName(String localName)
aoqi@0: throws SOAPException;
aoqi@0:
aoqi@0: /**
aoqi@0: * Returns the SOAPHeader
object for
aoqi@0: * this SOAPEnvelope
object.
aoqi@0: *
aoqi@0: * A new SOAPMessage
object is by default created with a
aoqi@0: * SOAPEnvelope
object that contains an empty
aoqi@0: * SOAPHeader
object. As a result, the method
aoqi@0: * getHeader
will always return a SOAPHeader
aoqi@0: * object unless the header has been removed and a new one has not
aoqi@0: * been added.
aoqi@0: *
aoqi@0: * @return the SOAPHeader
object or null
if
aoqi@0: * there is none
aoqi@0: * @exception SOAPException if there is a problem obtaining the
aoqi@0: * SOAPHeader
object
aoqi@0: */
aoqi@0: public SOAPHeader getHeader() throws SOAPException;
aoqi@0:
aoqi@0: /**
aoqi@0: * Returns the SOAPBody
object associated with this
aoqi@0: * SOAPEnvelope
object.
aoqi@0: *
aoqi@0: * A new SOAPMessage
object is by default created with a
aoqi@0: * SOAPEnvelope
object that contains an empty
aoqi@0: * SOAPBody
object. As a result, the method
aoqi@0: * getBody
will always return a SOAPBody
aoqi@0: * object unless the body has been removed and a new one has not
aoqi@0: * been added.
aoqi@0: *
aoqi@0: * @return the SOAPBody
object for this
aoqi@0: * SOAPEnvelope
object or null
aoqi@0: * if there is none
aoqi@0: * @exception SOAPException if there is a problem obtaining the
aoqi@0: * SOAPBody
object
aoqi@0: */
aoqi@0: public SOAPBody getBody() throws SOAPException;
aoqi@0: /**
aoqi@0: * Creates a SOAPHeader
object and sets it as the
aoqi@0: * SOAPHeader
object for this SOAPEnvelope
aoqi@0: * object.
aoqi@0: *
aoqi@0: * It is illegal to add a header when the envelope already
aoqi@0: * contains a header. Therefore, this method should be called
aoqi@0: * only after the existing header has been removed.
aoqi@0: *
aoqi@0: * @return the new SOAPHeader
object
aoqi@0: *
aoqi@0: * @exception SOAPException if this
aoqi@0: * SOAPEnvelope
object already contains a
aoqi@0: * valid SOAPHeader
object
aoqi@0: */
aoqi@0: public SOAPHeader addHeader() throws SOAPException;
aoqi@0: /**
aoqi@0: * Creates a SOAPBody
object and sets it as the
aoqi@0: * SOAPBody
object for this SOAPEnvelope
aoqi@0: * object.
aoqi@0: *
aoqi@0: * It is illegal to add a body when the envelope already
aoqi@0: * contains a body. Therefore, this method should be called
aoqi@0: * only after the existing body has been removed.
aoqi@0: *
aoqi@0: * @return the new SOAPBody
object
aoqi@0: *
aoqi@0: * @exception SOAPException if this
aoqi@0: * SOAPEnvelope
object already contains a
aoqi@0: * valid SOAPBody
object
aoqi@0: */
aoqi@0: public SOAPBody addBody() throws SOAPException;
aoqi@0: }