Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxws/src/share/jaxws_classes/javax/xml/soap/SOAPElement.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.namespace.QName;3031/**32* An object representing an element of a SOAP message that is allowed but not33* specifically prescribed by a SOAP specification. This interface serves as the34* base interface for those objects that are specifically prescribed by a SOAP35* specification.36* <p>37* Methods in this interface that are required to return SAAJ specific objects38* may "silently" replace nodes in the tree as required to successfully return39* objects of the correct type. See {@link #getChildElements()} and40* {@link <a HREF="package-summary.html#package_description">javax.xml.soap<a>}41* for details.42*/43public interface SOAPElement extends Node, org.w3c.dom.Element {4445/**46* Creates a new <code>SOAPElement</code> object initialized with the47* given <code>Name</code> object and adds the new element to this48* <code>SOAPElement</code> object.49* <P>50* This method may be deprecated in a future release of SAAJ in favor of51* addChildElement(javax.xml.namespace.QName)52*53* @param name a <code>Name</code> object with the XML name for the54* new element55*56* @return the new <code>SOAPElement</code> object that was created57* @exception SOAPException if there is an error in creating the58* <code>SOAPElement</code> object59* @see SOAPElement#addChildElement(javax.xml.namespace.QName)60*/61public SOAPElement addChildElement(Name name) throws SOAPException;6263/**64* Creates a new <code>SOAPElement</code> object initialized with the given65* <code>QName</code> object and adds the new element to this <code>SOAPElement</code>66* object. The <i>namespace</i>, <i>localname</i> and <i>prefix</i> of the new67* <code>SOAPElement</code> are all taken from the <code>qname</code> argument.68*69* @param qname a <code>QName</code> object with the XML name for the70* new element71*72* @return the new <code>SOAPElement</code> object that was created73* @exception SOAPException if there is an error in creating the74* <code>SOAPElement</code> object75* @see SOAPElement#addChildElement(Name)76* @since SAAJ 1.377*/78public SOAPElement addChildElement(QName qname) throws SOAPException;7980/**81* Creates a new <code>SOAPElement</code> object initialized with the82* specified local name and adds the new element to this83* <code>SOAPElement</code> object.84* The new <code>SOAPElement</code> inherits any in-scope default namespace.85*86* @param localName a <code>String</code> giving the local name for87* the element88* @return the new <code>SOAPElement</code> object that was created89* @exception SOAPException if there is an error in creating the90* <code>SOAPElement</code> object91*/92public SOAPElement addChildElement(String localName) throws SOAPException;9394/**95* Creates a new <code>SOAPElement</code> object initialized with the96* specified local name and prefix and adds the new element to this97* <code>SOAPElement</code> object.98*99* @param localName a <code>String</code> giving the local name for100* the new element101* @param prefix a <code>String</code> giving the namespace prefix for102* the new element103*104* @return the new <code>SOAPElement</code> object that was created105* @exception SOAPException if the <code>prefix</code> is not valid in the106* context of this <code>SOAPElement</code> or if there is an error in creating the107* <code>SOAPElement</code> object108*/109public SOAPElement addChildElement(String localName, String prefix)110throws SOAPException;111112/**113* Creates a new <code>SOAPElement</code> object initialized with the114* specified local name, prefix, and URI and adds the new element to this115* <code>SOAPElement</code> object.116*117* @param localName a <code>String</code> giving the local name for118* the new element119* @param prefix a <code>String</code> giving the namespace prefix for120* the new element121* @param uri a <code>String</code> giving the URI of the namespace122* to which the new element belongs123*124* @return the new <code>SOAPElement</code> object that was created125* @exception SOAPException if there is an error in creating the126* <code>SOAPElement</code> object127*/128public SOAPElement addChildElement(String localName, String prefix,129String uri)130throws SOAPException;131132/**133* Add a <code>SOAPElement</code> as a child of this134* <code>SOAPElement</code> instance. The <code>SOAPElement</code>135* is expected to be created by a136* <code>SOAPFactory</code>. Callers should not rely on the137* element instance being added as is into the XML138* tree. Implementations could end up copying the content139* of the <code>SOAPElement</code> passed into an instance of140* a different <code>SOAPElement</code> implementation. For141* instance if <code>addChildElement()</code> is called on a142* <code>SOAPHeader</code>, <code>element</code> will be copied143* into an instance of a <code>SOAPHeaderElement</code>.144*145* <P>The fragment rooted in <code>element</code> is either added146* as a whole or not at all, if there was an error.147*148* <P>The fragment rooted in <code>element</code> cannot contain149* elements named "Envelope", "Header" or "Body" and in the SOAP150* namespace. Any namespace prefixes present in the fragment151* should be fully resolved using appropriate namespace152* declarations within the fragment itself.153*154* @param element the <code>SOAPElement</code> to be added as a155* new child156*157* @exception SOAPException if there was an error in adding this158* element as a child159*160* @return an instance representing the new SOAP element that was161* actually added to the tree.162*/163public SOAPElement addChildElement(SOAPElement element)164throws SOAPException;165166/**167* Detaches all children of this <code>SOAPElement</code>.168* <p>169* This method is useful for rolling back the construction of partially170* completed <code>SOAPHeaders</code> and <code>SOAPBodys</code> in171* preparation for sending a fault when an error condition is detected. It172* is also useful for recycling portions of a document within a SOAP173* message.174*175* @since SAAJ 1.2176*/177public abstract void removeContents();178179/**180* Creates a new <code>Text</code> object initialized with the given181* <code>String</code> and adds it to this <code>SOAPElement</code> object.182*183* @param text a <code>String</code> object with the textual content to be added184*185* @return the <code>SOAPElement</code> object into which186* the new <code>Text</code> object was inserted187* @exception SOAPException if there is an error in creating the188* new <code>Text</code> object or if it is not legal to189* attach it as a child to this190* <code>SOAPElement</code>191*/192public SOAPElement addTextNode(String text) throws SOAPException;193194/**195* Adds an attribute with the specified name and value to this196* <code>SOAPElement</code> object.197*198* @param name a <code>Name</code> object with the name of the attribute199* @param value a <code>String</code> giving the value of the attribute200* @return the <code>SOAPElement</code> object into which the attribute was201* inserted202*203* @exception SOAPException if there is an error in creating the204* Attribute, or it is invalid to set205an attribute with <code>Name</code>206<code>name</code> on this SOAPElement.207* @see SOAPElement#addAttribute(javax.xml.namespace.QName, String)208*/209public SOAPElement addAttribute(Name name, String value)210throws SOAPException;211212/**213* Adds an attribute with the specified name and value to this214* <code>SOAPElement</code> object.215*216* @param qname a <code>QName</code> object with the name of the attribute217* @param value a <code>String</code> giving the value of the attribute218* @return the <code>SOAPElement</code> object into which the attribute was219* inserted220*221* @exception SOAPException if there is an error in creating the222* Attribute, or it is invalid to set223an attribute with <code>QName</code>224<code>qname</code> on this SOAPElement.225* @see SOAPElement#addAttribute(Name, String)226* @since SAAJ 1.3227*/228public SOAPElement addAttribute(QName qname, String value)229throws SOAPException;230231/**232* Adds a namespace declaration with the specified prefix and URI to this233* <code>SOAPElement</code> object.234*235* @param prefix a <code>String</code> giving the prefix of the namespace236* @param uri a <code>String</code> giving the uri of the namespace237* @return the <code>SOAPElement</code> object into which this238* namespace declaration was inserted.239*240* @exception SOAPException if there is an error in creating the241* namespace242*/243public SOAPElement addNamespaceDeclaration(String prefix, String uri)244throws SOAPException;245246/**247* Returns the value of the attribute with the specified name.248*249* @param name a <code>Name</code> object with the name of the attribute250* @return a <code>String</code> giving the value of the specified251* attribute, Null if there is no such attribute252* @see SOAPElement#getAttributeValue(javax.xml.namespace.QName)253*/254public String getAttributeValue(Name name);255256/**257* Returns the value of the attribute with the specified qname.258*259* @param qname a <code>QName</code> object with the qname of the attribute260* @return a <code>String</code> giving the value of the specified261* attribute, Null if there is no such attribute262* @see SOAPElement#getAttributeValue(Name)263* @since SAAJ 1.3264*/265public String getAttributeValue(QName qname);266267/**268* Returns an <code>Iterator</code> over all of the attribute269* <code>Name</code> objects in this270* <code>SOAPElement</code> object. The iterator can be used to get271* the attribute names, which can then be passed to the method272* <code>getAttributeValue</code> to retrieve the value of each273* attribute.274*275* @see SOAPElement#getAllAttributesAsQNames()276* @return an iterator over the names of the attributes277*/278public Iterator getAllAttributes();279280/**281* Returns an <code>Iterator</code> over all of the attributes282* in this <code>SOAPElement</code> as <code>QName</code> objects.283* The iterator can be used to get the attribute QName, which can then284* be passed to the method <code>getAttributeValue</code> to retrieve285* the value of each attribute.286*287* @return an iterator over the QNames of the attributes288* @see SOAPElement#getAllAttributes()289* @since SAAJ 1.3290*/291public Iterator getAllAttributesAsQNames();292293294/**295* Returns the URI of the namespace that has the given prefix.296*297* @param prefix a <code>String</code> giving the prefix of the namespace298* for which to search299* @return a <code>String</code> with the uri of the namespace that has300* the given prefix301*/302public String getNamespaceURI(String prefix);303304/**305* Returns an <code>Iterator</code> over the namespace prefix306* <code>String</code>s declared by this element. The prefixes returned by307* this iterator can be passed to the method308* <code>getNamespaceURI</code> to retrieve the URI of each namespace.309*310* @return an iterator over the namespace prefixes in this311* <code>SOAPElement</code> object312*/313public Iterator getNamespacePrefixes();314315/**316* Returns an <code>Iterator</code> over the namespace prefix317* <code>String</code>s visible to this element. The prefixes returned by318* this iterator can be passed to the method319* <code>getNamespaceURI</code> to retrieve the URI of each namespace.320*321* @return an iterator over the namespace prefixes are within scope of this322* <code>SOAPElement</code> object323*324* @since SAAJ 1.2325*/326public Iterator getVisibleNamespacePrefixes();327328/**329* Creates a <code>QName</code> whose namespace URI is the one associated330* with the parameter, <code>prefix</code>, in the context of this331* <code>SOAPElement</code>. The remaining elements of the new332* <code>QName</code> are taken directly from the parameters,333* <code>localName</code> and <code>prefix</code>.334*335* @param localName336* a <code>String</code> containing the local part of the name.337* @param prefix338* a <code>String</code> containing the prefix for the name.339*340* @return a <code>QName</code> with the specified <code>localName</code>341* and <code>prefix</code>, and with a namespace that is associated342* with the <code>prefix</code> in the context of this343* <code>SOAPElement</code>. This namespace will be the same as344* the one that would be returned by345* <code>{@link #getNamespaceURI(String)}</code> if it were given346* <code>prefix</code> as it's parameter.347*348* @exception SOAPException if the <code>QName</code> cannot be created.349*350* @since SAAJ 1.3351*/352public QName createQName(String localName, String prefix)353throws SOAPException;354/**355* Returns the name of this <code>SOAPElement</code> object.356*357* @return a <code>Name</code> object with the name of this358* <code>SOAPElement</code> object359*/360public Name getElementName();361362/**363* Returns the qname of this <code>SOAPElement</code> object.364*365* @return a <code>QName</code> object with the qname of this366* <code>SOAPElement</code> object367* @see SOAPElement#getElementName()368* @since SAAJ 1.3369*/370public QName getElementQName();371372/**373* Changes the name of this <code>Element</code> to <code>newName</code> if374* possible. SOAP Defined elements such as SOAPEnvelope, SOAPHeader, SOAPBody375* etc. cannot have their names changed using this method. Any attempt to do376* so will result in a SOAPException being thrown.377*<P>378* Callers should not rely on the element instance being renamed as is.379* Implementations could end up copying the content of the380* <code>SOAPElement</code> to a renamed instance.381*382* @param newName the new name for the <code>Element</code>.383*384* @exception SOAPException if changing the name of this <code>Element</code>385* is not allowed.386* @return The renamed Node387*388* @since SAAJ 1.3389*/390public SOAPElement setElementQName(QName newName) throws SOAPException;391392/**393* Removes the attribute with the specified name.394*395* @param name the <code>Name</code> object with the name of the396* attribute to be removed397* @return <code>true</code> if the attribute was398* removed successfully; <code>false</code> if it was not399* @see SOAPElement#removeAttribute(javax.xml.namespace.QName)400*/401public boolean removeAttribute(Name name);402403/**404* Removes the attribute with the specified qname.405*406* @param qname the <code>QName</code> object with the qname of the407* attribute to be removed408* @return <code>true</code> if the attribute was409* removed successfully; <code>false</code> if it was not410* @see SOAPElement#removeAttribute(Name)411* @since SAAJ 1.3412*/413public boolean removeAttribute(QName qname);414415/**416* Removes the namespace declaration corresponding to the given prefix.417*418* @param prefix a <code>String</code> giving the prefix for which419* to search420* @return <code>true</code> if the namespace declaration was421* removed successfully; <code>false</code> if it was not422*/423public boolean removeNamespaceDeclaration(String prefix);424425/**426* Returns an <code>Iterator</code> over all the immediate child427* {@link Node}s of this element. This includes <code>javax.xml.soap.Text</code>428* objects as well as <code>SOAPElement</code> objects.429* <p>430* Calling this method may cause child <code>Element</code>,431* <code>SOAPElement</code> and <code>org.w3c.dom.Text</code> nodes to be432* replaced by <code>SOAPElement</code>, <code>SOAPHeaderElement</code>,433* <code>SOAPBodyElement</code> or <code>javax.xml.soap.Text</code> nodes as434* appropriate for the type of this parent node. As a result the calling435* application must treat any existing references to these child nodes that436* have been obtained through DOM APIs as invalid and either discard them or437* refresh them with the values returned by this <code>Iterator</code>. This438* behavior can be avoided by calling the equivalent DOM APIs. See439* {@link <a HREF="package-summary.html#package_description">javax.xml.soap<a>}440* for more details.441*442* @return an iterator with the content of this <code>SOAPElement</code>443* object444*/445public Iterator getChildElements();446447/**448* Returns an <code>Iterator</code> over all the immediate child449* {@link Node}s of this element with the specified name. All of these450* children will be <code>SOAPElement</code> nodes.451* <p>452* Calling this method may cause child <code>Element</code>,453* <code>SOAPElement</code> and <code>org.w3c.dom.Text</code> nodes to be454* replaced by <code>SOAPElement</code>, <code>SOAPHeaderElement</code>,455* <code>SOAPBodyElement</code> or <code>javax.xml.soap.Text</code> nodes as456* appropriate for the type of this parent node. As a result the calling457* application must treat any existing references to these child nodes that458* have been obtained through DOM APIs as invalid and either discard them or459* refresh them with the values returned by this <code>Iterator</code>. This460* behavior can be avoided by calling the equivalent DOM APIs. See461* {@link <a HREF="package-summary.html#package_description">javax.xml.soap<a>}462* for more details.463*464* @param name a <code>Name</code> object with the name of the child465* elements to be returned466*467* @return an <code>Iterator</code> object over all the elements468* in this <code>SOAPElement</code> object with the469* specified name470* @see SOAPElement#getChildElements(javax.xml.namespace.QName)471*/472public Iterator getChildElements(Name name);473474/**475* Returns an <code>Iterator</code> over all the immediate child476* {@link Node}s of this element with the specified qname. All of these477* children will be <code>SOAPElement</code> nodes.478* <p>479* Calling this method may cause child <code>Element</code>,480* <code>SOAPElement</code> and <code>org.w3c.dom.Text</code> nodes to be481* replaced by <code>SOAPElement</code>, <code>SOAPHeaderElement</code>,482* <code>SOAPBodyElement</code> or <code>javax.xml.soap.Text</code> nodes as483* appropriate for the type of this parent node. As a result the calling484* application must treat any existing references to these child nodes that485* have been obtained through DOM APIs as invalid and either discard them or486* refresh them with the values returned by this <code>Iterator</code>. This487* behavior can be avoided by calling the equivalent DOM APIs. See488* {@link <a HREF="package-summary.html#package_description">javax.xml.soap<a>}489* for more details.490*491* @param qname a <code>QName</code> object with the qname of the child492* elements to be returned493*494* @return an <code>Iterator</code> object over all the elements495* in this <code>SOAPElement</code> object with the496* specified qname497* @see SOAPElement#getChildElements(Name)498* @since SAAJ 1.3499*/500public Iterator getChildElements(QName qname);501502/**503* Sets the encoding style for this <code>SOAPElement</code> object504* to one specified.505*506* @param encodingStyle a <code>String</code> giving the encoding style507*508* @exception IllegalArgumentException if there was a problem in the509* encoding style being set.510* @exception SOAPException if setting the encodingStyle is invalid for this SOAPElement.511* @see #getEncodingStyle512*/513public void setEncodingStyle(String encodingStyle)514throws SOAPException;515/**516* Returns the encoding style for this <code>SOAPElement</code> object.517*518* @return a <code>String</code> giving the encoding style519*520* @see #setEncodingStyle521*/522public String getEncodingStyle();523}524525526