Search in sources :

Example 26 with OMNamespace

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);
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) OMNamespace(org.apache.axiom.om.OMNamespace) StringWriter(java.io.StringWriter) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 27 with OMNamespace

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;
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) XmlHandlerStreamWriter(org.apache.axiom.core.stream.stax.push.XmlHandlerStreamWriter) StreamException(org.apache.axiom.core.stream.StreamException) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamException(javax.xml.stream.XMLStreamException) XmlHandlerWrapper(org.apache.axiom.core.stream.XmlHandlerWrapper) XmlHandler(org.apache.axiom.core.stream.XmlHandler) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) XmlDeclarationRewriterHandler(org.apache.axiom.om.impl.stream.XmlDeclarationRewriterHandler) OMContainer(org.apache.axiom.om.OMContainer)

Example 28 with OMNamespace

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;
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) SOAPVersion(org.apache.axiom.soap.SOAPVersion) SOAP12Version(org.apache.axiom.soap.SOAP12Version)

Example 29 with OMNamespace

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());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 30 with OMNamespace

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());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMNamespace (org.apache.axiom.om.OMNamespace)164 OMElement (org.apache.axiom.om.OMElement)101 OMFactory (org.apache.axiom.om.OMFactory)94 QName (javax.xml.namespace.QName)33 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)20 OMAttribute (org.apache.axiom.om.OMAttribute)18 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)16 StringWriter (java.io.StringWriter)15 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)13 SOAPHeader (org.apache.axiom.soap.SOAPHeader)12 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)9 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 OMText (org.apache.axiom.om.OMText)7 Iterator (java.util.Iterator)6 SOAPBody (org.apache.axiom.soap.SOAPBody)6 StringReader (java.io.StringReader)5 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)5 HashSet (java.util.HashSet)4 OMDataSource (org.apache.axiom.om.OMDataSource)4 OMNode (org.apache.axiom.om.OMNode)4