本文整理汇总了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;
}