|
|
Java EE 5 SDK 深圳电信培训中心.徐海蛟老师. |
||||||||
| 上一个类 下一个类 | 框架 无框架 | ||||||||
| 摘要: 嵌套 | 字段 | 构造器 | 方法 | 详细信息: 字段 | 构造器 | 方法 | ||||||||
javax.xml.soap Interface SOAPEnvelope
- 所有父接口:
- Element, Node, SOAPElement
public interface SOAPEnvelope
- extends SOAPElement
The container for the SOAPHeader and SOAPBody portions of a
SOAPPart object. By default, a SOAPMessage
object is created with a SOAPPart object that has a
SOAPEnvelope object. The SOAPEnvelope object
by default has an empty SOAPBody object and an empty
SOAPHeader object. The SOAPBody object is
required, and the SOAPHeader object, though
optional, is used in the majority of cases. If the
SOAPHeader object is not needed, it can be deleted,
which is shown later.
A client can access the SOAPHeader and SOAPBody
objects by calling the methods SOAPEnvelope.getHeader and
SOAPEnvelope.getBody. The
following lines of code use these two methods after starting with
the SOAPMessage
object message to get the SOAPPart object sp,
which is then used to get the SOAPEnvelope object se.
SOAPPart sp = message.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPHeader sh = se.getHeader();
SOAPBody sb = se.getBody();
It is possible to change the body or header of a SOAPEnvelope
object by retrieving the current one, deleting it, and then adding
a new body or header. The javax.xml.soap.Node method
deleteNode deletes the XML element (node) on which it is
called. For example, the following line of code deletes the
SOAPBody object that is retrieved by the method getBody.
se.getBody().detachNode();
To create a SOAPHeader object to replace the one that was removed,
a client uses
the method SOAPEnvelope.addHeader, which creates a new header and
adds it to the SOAPEnvelope object. Similarly, the method
addBody creates a new SOAPBody object and adds
it to the SOAPEnvelope object. The following code fragment
retrieves the current header, removes it, and adds a new one. Then
it retrieves the current body, removes it, and adds a new one.
SOAPPart sp = message.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
se.getHeader().detachNode();
SOAPHeader sh = se.addHeader();
se.getBody().detachNode();
SOAPBody sb = se.addBody();
It is an error to add a SOAPBody or SOAPHeader
object if one already exists.
The SOAPEnvelope interface provides three methods for creating
Name objects. One method creates Name objects with
a local name, a namespace prefix, and a namesapce URI. The second method creates
Name objects with a local name and a namespace prefix, and the third
creates Name objects with just a local name. The following line of
code, in which se is a SOAPEnvelope object, creates a new
Name object with all three.
Name name = se.createName("GetLastTradePrice", "WOMBAT",
"http://www.wombat.org/trader");
| 字段摘要 |
|---|
| 方法摘要 | |
|---|---|
SOAPBody |
addBody()
Creates a SOAPBody object and sets it as the
SOAPBody object for this SOAPEnvelope
object. |
SOAPHeader |
addHeader()
Creates a SOAPHeader object and sets it as the
SOAPHeader object for this SOAPEnvelope
object. |
Name |
createName(String localName)
Creates a new Name object initialized with the
given local name. |
Name |
createName(String localName,
String prefix,
String uri)
Creates a new Name object initialized with the
given local name, namespace prefix, and namespace URI. |
SOAPBody |
getBody()
Returns the SOAPBody object associated with this
SOAPEnvelope object. |
SOAPHeader |
getHeader()
Returns the SOAPHeader object for
this SOAPEnvelope object. |
| Methods inherited from interface javax.xml.soap.Node |
|---|
detachNode, getParentElement, getValue, recycleNode, setParentElement, setValue |
| Methods inherited from interface org.w3c.dom.Node |
|---|
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData |
| Methods inherited from interface org.w3c.dom.Element |
|---|
getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getElementsByTagName, getElementsByTagNameNS, getSchemaTypeInfo, getTagName, hasAttribute, hasAttributeNS, removeAttribute, removeAttributeNode, removeAttributeNS, setAttribute, setAttributeNode, setAttributeNodeNS, setAttributeNS, setIdAttribute, setIdAttributeNode, setIdAttributeNS |
| Methods inherited from interface org.w3c.dom.Node |
|---|
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData |
| 方法详细信息 |
|---|
createName
Name createName(String localName, String prefix, String uri) throws SOAPException
- Creates a new
Nameobject initialized with the given local name, namespace prefix, and namespace URI.This factory method creates
Nameobjects for use in the SOAP/XML document. - 参数:
localName- aStringgiving the local nameprefix- aStringgiving the prefix of the namespaceuri- aStringgiving the URI of the namespace- 返回:
- a
Nameobject initialized with the given local name, namespace prefix, and namespace URI - 抛出异常:
SOAPException- if there is a SOAP error
createName
Name createName(String localName) throws SOAPException
- Creates a new
Nameobject initialized with the given local name.This factory method creates
Nameobjects for use in the SOAP/XML document. - 参数:
localName- aStringgiving the local name- 返回:
- a
Nameobject initialized with the given local name - 抛出异常:
SOAPException- if there is a SOAP error
getHeader
SOAPHeader getHeader() throws SOAPException
- Returns the
SOAPHeaderobject for thisSOAPEnvelopeobject.A new
SOAPMessageobject is by default created with aSOAPEnvelopeobject that contains an emptySOAPHeaderobject. As a result, the methodgetHeaderwill always return aSOAPHeaderobject unless the header has been removed and a new one has not been added. - 返回:
- the
SOAPHeaderobject ornullif there is none - 抛出异常:
SOAPException- if there is a problem obtaining theSOAPHeaderobject
getBody
SOAPBody getBody() throws SOAPException
- Returns the
SOAPBodyobject associated with thisSOAPEnvelopeobject.A new
SOAPMessageobject is by default created with aSOAPEnvelopeobject that contains an emptySOAPBodyobject. As a result, the methodgetBodywill always return aSOAPBodyobject unless the body has been removed and a new one has not been added. - 返回:
- the
SOAPBodyobject for thisSOAPEnvelopeobject ornullif there is none - 抛出异常:
SOAPException- if there is a problem obtaining theSOAPBodyobject
addHeader
SOAPHeader addHeader() throws SOAPException
- Creates a
SOAPHeaderobject and sets it as theSOAPHeaderobject for thisSOAPEnvelopeobject.It is illegal to add a header when the envelope already contains a header. Therefore, this method should be called only after the existing header has been removed.
- 返回:
- the new
SOAPHeaderobject - 抛出异常:
SOAPException- if thisSOAPEnvelopeobject already contains a validSOAPHeaderobject
addBody
SOAPBody addBody() throws SOAPException
- Creates a
SOAPBodyobject and sets it as theSOAPBodyobject for thisSOAPEnvelopeobject.It is illegal to add a body when the envelope already contains a body. Therefore, this method should be called only after the existing body has been removed.
- 返回:
- the new
SOAPBodyobject - 抛出异常:
SOAPException- if thisSOAPEnvelopeobject already contains a validSOAPBodyobject
|
|
Java EE 5 SDK 深圳电信培训中心.徐海蛟老师. |
||||||||
| 上一个类 下一个类 | 框架 无框架 | ||||||||
| 摘要: 嵌套 | 字段 | 构造器 | 方法 | 详细信息: 字段 | 构造器 | 方法 | ||||||||
提交错误或意见
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。深圳电信培训中心.徐海蛟老师教学参考.