本文整理匯總了Java中javax.xml.soap.SOAPElement.addNamespaceDeclaration方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPElement.addNamespaceDeclaration方法的具體用法?Java SOAPElement.addNamespaceDeclaration怎麽用?Java SOAPElement.addNamespaceDeclaration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPElement
的用法示例。
在下文中一共展示了SOAPElement.addNamespaceDeclaration方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testAddElementToNullNsQName
import javax.xml.soap.SOAPElement; //導入方法依賴的package包/類
@Test
public void testAddElementToNullNsQName() throws Exception {
// Create empty SOAP message
SOAPMessage msg = createSoapMessage();
SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
// Add elements
SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName(null, "global-child"));
childGlobalNS.addNamespaceDeclaration("", "");
SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
// Check namespace URIs
Assert.assertNull(childGlobalNS.getNamespaceURI());
Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
示例2: testAddElementToGlobalNs
import javax.xml.soap.SOAPElement; //導入方法依賴的package包/類
@Test
public void testAddElementToGlobalNs() throws Exception {
// Create empty SOAP message
SOAPMessage msg = createSoapMessage();
SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
// Add elements
SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
childGlobalNS.addNamespaceDeclaration("", "");
SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
// Check namespace URIs
Assert.assertNull(childGlobalNS.getNamespaceURI());
Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
示例3: testAddElementToNullNs
import javax.xml.soap.SOAPElement; //導入方法依賴的package包/類
@Test
public void testAddElementToNullNs() throws Exception {
// Create empty SOAP message
SOAPMessage msg = createSoapMessage();
SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
// Add elements
SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
childGlobalNS.addNamespaceDeclaration("", null);
SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
// Check namespace URIs
Assert.assertNull(childGlobalNS.getNamespaceURI());
Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
Assert.assertEquals(TEST_NS, childDefaultNS.getNamespaceURI());
}
示例4: testAddElementToGlobalNsQName
import javax.xml.soap.SOAPElement; //導入方法依賴的package包/類
@Test
public void testAddElementToGlobalNsQName() throws Exception {
// Create empty SOAP message
SOAPMessage msg = createSoapMessage();
SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
// Add elements
SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName("", "global-child"));
childGlobalNS.addNamespaceDeclaration("", "");
SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
// Check namespace URIs
Assert.assertNull(childGlobalNS.getNamespaceURI());
Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
Assert.assertEquals(childDefaultNS.getNamespaceURI(),TEST_NS);
}
示例5: addHeader
import javax.xml.soap.SOAPElement; //導入方法依賴的package包/類
private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
for (QName qname : notUnderstoodHeaders) {
SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
Header header = new DOMHeader<Element>(soapEl);
m.getHeaders().add(header);
}
}
示例6: flushTo
import javax.xml.soap.SOAPElement; //導入方法依賴的package包/類
/**
* Flushes state of this element to the {@code target} element.
*
* <p>
* If this element is initialized then it is added with all the namespace declarations and attributes
* to the {@code target} element as a child. The state of this element is reset to uninitialized.
* The newly added element object is returned.
* </p>
* <p>
* If this element is not initialized then the {@code target} is returned immediately, nothing else is done.
* </p>
*
* @param target target element
* @return {@code target} or new element
* @throws XMLStreamException on error
*/
public SOAPElement flushTo(final SOAPElement target) throws XMLStreamException {
try {
if (this.localName != null) {
// add the element appropriately (based on namespace declaration)
final SOAPElement newElement;
if (this.namespaceUri == null) {
// add element with inherited scope
newElement = target.addChildElement(this.localName);
} else if (prefix == null) {
newElement = target.addChildElement(new QName(this.namespaceUri, this.localName));
} else {
newElement = target.addChildElement(this.localName, this.prefix, this.namespaceUri);
}
// add namespace declarations
for (NamespaceDeclaration namespace : this.namespaceDeclarations) {
target.addNamespaceDeclaration(namespace.prefix, namespace.namespaceUri);
}
// add attribute declarations
for (AttributeDeclaration attribute : this.attributeDeclarations) {
addAttibuteToElement(newElement,
attribute.prefix, attribute.namespaceUri, attribute.localName, attribute.value);
}
// reset state
this.reset();
return newElement;
} else {
return target;
}
// else after reset state -> not initialized
} catch (SOAPException e) {
throw new XMLStreamException(e);
}
}
示例7: addUpgradeHeaderElement
import javax.xml.soap.SOAPElement; //導入方法依賴的package包/類
@Override
public SOAPHeaderElement addUpgradeHeaderElement(Iterator supportedSoapUris)
throws SOAPException {
if (supportedSoapUris == null) {
log.severe("SAAJ0411.ver1_2.no.null.supportedURIs");
throw new SOAPException("Argument cannot be null; iterator of supportedURIs cannot be null");
}
if (!supportedSoapUris.hasNext()) {
log.severe("SAAJ0412.ver1_2.no.empty.list.of.supportedURIs");
throw new SOAPException("List of supported URIs cannot be empty");
}
Name upgradeName = getUpgradeName();
SOAPHeaderElement upgradeHeaderElement =
(SOAPHeaderElement) addChildElement(upgradeName);
Name supportedEnvelopeName = getSupportedEnvelopeName();
int i = 0;
while (supportedSoapUris.hasNext()) {
SOAPElement subElement =
upgradeHeaderElement.addChildElement(supportedEnvelopeName);
String ns = "ns" + Integer.toString(i);
subElement.addAttribute(
NameImpl.createFromUnqualifiedName("qname"),
ns + ":Envelope");
subElement.addNamespaceDeclaration(
ns, (String) supportedSoapUris.next());
i ++;
}
return upgradeHeaderElement;
}