use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestSerializeAndConsumeWithOMSEInBody method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
SOAPBody body = soapFactory.createSOAPBody();
envelope.addChild(body);
OMNamespace ns = soapFactory.createOMNamespace("http://ns1", "d");
OMElement payload = soapFactory.createOMElement(new DummySource(), "dummy", ns);
// This line will cause NoSuchElementException
payload.setNamespace(ns);
body.addChild(payload);
StringWriter writer = new StringWriter();
envelope.serializeAndConsume(writer);
// System.out.println(writer);
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class PushOMDataSourceReader method proceed.
@Override
public boolean proceed() throws StreamException {
// TODO: we might want to unwrap the NamespaceRepairingFilter (and some other filters) here
XmlHandler handler = this.handler;
OMOutputFormat format = null;
XmlHandler current = handler;
while (current instanceof XmlHandlerWrapper) {
if (current instanceof XmlDeclarationRewriterHandler) {
format = ((XmlDeclarationRewriterHandler) current).getFormat();
break;
}
current = ((XmlHandlerWrapper) current).getParent();
}
if (format == null) {
// This is for the OMSourcedElement expansion case
format = new OMOutputFormat();
format.setDoOptimize(true);
handler = new PushOMDataSourceXOPHandler(handler);
}
try {
XMLStreamWriter writer = new XmlHandlerStreamWriter(handler, null, AxiomXMLStreamWriterExtensionFactory.INSTANCE);
// Seed the namespace context with the namespace context from the parent
OMContainer parent = root.getParent();
if (parent instanceof OMElement) {
for (Iterator<OMNamespace> it = ((OMElement) parent).getNamespacesInScope(); it.hasNext(); ) {
OMNamespace ns = it.next();
writer.setPrefix(ns.getPrefix(), ns.getNamespaceURI());
}
}
handler.startFragment();
dataSource.serialize(new MTOMXMLStreamWriterImpl(new PushOMDataSourceStreamWriter(writer), format));
handler.completed();
} catch (XMLStreamException ex) {
Throwable cause = ex.getCause();
if (cause instanceof StreamException) {
throw (StreamException) cause;
} else {
throw new StreamException(ex);
}
}
return true;
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class RolePlayerChecker method matches.
@Override
public boolean matches(AxiomElement header, String unused1, String unused2) {
// If we're filtering on namespace, check that first since the compare is simpler.
if (namespace != null) {
OMNamespace headerNamespace = header.getNamespace();
if (headerNamespace == null || !namespace.equals(headerNamespace.getNamespaceURI())) {
return false;
}
}
String role = SOAPHeaderBlockHelper.getRole(header, soapHelper);
SOAPVersion version = soapHelper.getVersion();
// 1. If role is ultimatedest, go by what the rolePlayer says
if (role == null || role.equals("") || (version instanceof SOAP12Version && role.equals(SOAP12Constants.SOAP_ROLE_ULTIMATE_RECEIVER))) {
return (rolePlayer == null || rolePlayer.isUltimateDestination());
}
// 2. If role is next, always return true
if (role.equals(version.getNextRoleURI()))
return true;
// 3. If role is none, always return false
if (version instanceof SOAP12Version && role.equals(SOAP12Constants.SOAP_ROLE_NONE)) {
return false;
}
// 4. Return t/f depending on match
List<String> roles = (rolePlayer == null) ? null : rolePlayer.getRoles();
if (roles != null) {
for (String thisRole : roles) {
if (thisRole.equals(role))
return true;
}
}
return false;
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestSetTextQName method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("TestElement", null);
QName qname = new QName("urn:ns1", "test", "ns");
element.setText(qname);
boolean foundNamespace = false;
for (Iterator<OMNamespace> it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
OMNamespace ns = it.next();
if ("urn:ns1".equals(ns.getNamespaceURI()) && "ns".equals(ns.getPrefix())) {
foundNamespace = true;
}
}
assertTrue("Namespace of the text is not defined in the parent element", foundNamespace);
assertTrue(element.toString().contains("ns:test"));
assertEquals("ns:test", element.getText());
assertEquals(qname, element.getTextAsQName());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestSetTextQNameWithEmptyPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", null);
QName qname = new QName("urn:test", "test");
element.setText(qname);
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
OMNamespace ns = it.next();
assertEquals("urn:test", ns.getNamespaceURI());
String prefix = ns.getPrefix();
assertTrue(prefix.length() > 0);
assertEquals(prefix + ":test", element.getText());
assertFalse(it.hasNext());
}
Aggregations