Search in sources :

Example 1 with OMDataSource

use of org.apache.axiom.om.OMDataSource in project webservices-axiom by apache.

the class CustomBuilderManager method getAction.

private Runnable getAction(CoreNode node, int depth, int firstCustomBuilder) {
    lastCandidateElement = null;
    lastCandidateDepth = -1;
    if (node instanceof AxiomElement && (node instanceof AxiomSOAPHeaderBlock || !(node instanceof AxiomSOAPElement))) {
        final AxiomElement element = (AxiomElement) node;
        if (registrations != null) {
            for (int i = firstCustomBuilder; i < registrations.size(); i++) {
                CustomBuilderRegistration registration = registrations.get(i);
                final String namespaceURI = element.coreGetNamespaceURI();
                final String localName = element.coreGetLocalName();
                if (registration.getSelector().accepts(element.getParent(), depth, namespaceURI, localName)) {
                    final CustomBuilder customBuilder = registration.getCustomBuilder();
                    if (log.isDebugEnabled()) {
                        log.debug("Custom builder " + customBuilder + " accepted element {" + namespaceURI + "}" + localName + " at depth " + depth);
                    }
                    return new Runnable() {

                        @Override
                        public void run() {
                            if (log.isDebugEnabled()) {
                                log.debug("Invoking custom builder " + customBuilder);
                            }
                            OMDataSource dataSource = customBuilder.create(element);
                            Class<? extends AxiomSourcedElement> type;
                            if (element instanceof AxiomSOAP11HeaderBlock) {
                                type = AxiomSOAP11HeaderBlock.class;
                            } else if (element instanceof AxiomSOAP12HeaderBlock) {
                                type = AxiomSOAP12HeaderBlock.class;
                            } else {
                                type = AxiomSourcedElement.class;
                            }
                            if (log.isDebugEnabled()) {
                                log.debug("Replacing element with new sourced element of type " + type);
                            }
                            AxiomSourcedElement newElement = element.coreCreateNode(type);
                            newElement.init(localName, new OMNamespaceImpl(namespaceURI, null), dataSource);
                            try {
                                element.coreReplaceWith(newElement, AxiomSemantics.INSTANCE);
                            } catch (CoreModelException ex) {
                                throw AxiomExceptionTranslator.translate(ex);
                            }
                        }
                    };
                }
            }
        }
        // Save a reference to the element so that we can process it when another custom builder is registered
        lastCandidateElement = element;
        lastCandidateDepth = depth;
    }
    return null;
}
Also used : OMDataSource(org.apache.axiom.om.OMDataSource) AxiomSOAPHeaderBlock(org.apache.axiom.soap.impl.intf.AxiomSOAPHeaderBlock) CustomBuilder(org.apache.axiom.om.ds.custombuilder.CustomBuilder) AxiomSOAP12HeaderBlock(org.apache.axiom.soap.impl.intf.AxiomSOAP12HeaderBlock) AxiomSOAPElement(org.apache.axiom.soap.impl.intf.AxiomSOAPElement) AxiomSourcedElement(org.apache.axiom.om.impl.intf.AxiomSourcedElement) CoreModelException(org.apache.axiom.core.CoreModelException) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) AxiomSOAP11HeaderBlock(org.apache.axiom.soap.impl.intf.AxiomSOAP11HeaderBlock) OMNamespaceImpl(org.apache.axiom.om.impl.common.OMNamespaceImpl)

Example 2 with OMDataSource

use of org.apache.axiom.om.OMDataSource in project webservices-axiom by apache.

the class TestCloneWithSourcedElement1 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope sourceEnv = soapFactory.getDefaultEnvelope();
    SOAPBody body = sourceEnv.getBody();
    // Create a payload
    OMDataSource bads = new StringOMDataSource("<tns:payload xmlns:tns=\"urn://test\">Hello World</tns:payload>");
    OMNamespace ns = body.getOMFactory().createOMNamespace("urn://test", "tns");
    OMSourcedElement omse = body.getOMFactory().createOMElement(bads, "payload", ns);
    body.addChild(omse);
    copyAndCheck(sourceEnv);
    assertFalse(omse.isExpanded());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) OMNamespace(org.apache.axiom.om.OMNamespace) OMDataSource(org.apache.axiom.om.OMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 3 with OMDataSource

use of org.apache.axiom.om.OMDataSource in project webservices-axiom by apache.

the class TestSerialize method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMSourcedElement element = TestDocument.DOCUMENT1.createOMSourcedElement(factory, push, destructive);
    OMDataSource ds = element.getDataSource();
    OMContainer parent = elementContext.wrap(element);
    boolean parentComplete = parent != null && parent.isComplete();
    expansionStrategy.apply(element);
    boolean consuming = expansionStrategy.isConsumedAfterSerialization(push, destructive, serializationStrategy);
    for (int iteration = 0; iteration < count; iteration++) {
        boolean expectException = iteration != 0 && (consuming || serializeParent && !serializationStrategy.isCaching() && !parentComplete);
        XML result;
        try {
            result = serializationStrategy.serialize(serializeParent ? parent : element);
            if (expectException) {
                fail("Expected exception");
            }
        } catch (Exception ex) {
            if (!expectException) {
                throw ex;
            } else {
                continue;
            }
        }
        InputSource expectedXML = new InputSource(new StringReader(TestDocument.DOCUMENT1.getContent()));
        if (serializeParent) {
            expectedXML = elementContext.getControl(expectedXML);
        }
        assertAbout(xml()).that(result.getInputSource()).hasSameContentAs(expectedXML);
        // the sourced element should be expanded.
        if (expansionStrategy.isExpandedAfterSerialization(push, destructive, serializationStrategy)) {
            assertTrue(element.isExpanded());
            assertEquals("OMSourcedElement completion status", !consuming, element.isComplete());
        } else {
            assertFalse(element.isExpanded());
        }
        if (parent != null && !serializeParent) {
            // Operations on the OMSourcedElement should have no impact on the parent
            assertEquals("Parent completion status", parentComplete, parent.isComplete());
        }
    }
    if (ds instanceof PullOMDataSource) {
        assertFalse(((PullOMDataSource) ds).hasUnclosedReaders());
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) InputSource(org.xml.sax.InputSource) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) AbstractPullOMDataSource(org.apache.axiom.om.ds.AbstractPullOMDataSource) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) OMDataSource(org.apache.axiom.om.OMDataSource) AbstractPullOMDataSource(org.apache.axiom.om.ds.AbstractPullOMDataSource) AbstractPushOMDataSource(org.apache.axiom.om.ds.AbstractPushOMDataSource) XML(org.apache.axiom.ts.dimension.serialization.XML) StringReader(java.io.StringReader) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) OMContainer(org.apache.axiom.om.OMContainer)

Example 4 with OMDataSource

use of org.apache.axiom.om.OMDataSource in project webservices-axiom by apache.

the class TestCloneUnknownName method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDataSource ds = new StringOMDataSource("<p:element xmlns:p='urn:ns'>test</p:element>");
    OMSourcedElement element = factory.createOMElement(ds);
    OMCloneOptions options = new OMCloneOptions();
    options.setCopyOMDataSources(true);
    OMElement clone = (OMElement) element.clone(options);
    assertTrue(clone instanceof OMSourcedElement);
    assertFalse(element.isExpanded());
    OMNamespace expectedNS = factory.createOMNamespace("urn:ns", "p");
    assertEquals("element", element.getLocalName());
    assertEquals("element", clone.getLocalName());
    assertEquals(expectedNS, element.getNamespace());
    assertEquals(expectedNS, clone.getNamespace());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMDataSource(org.apache.axiom.om.OMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 5 with OMDataSource

use of org.apache.axiom.om.OMDataSource in project webservices-axiom by apache.

the class TestDocument method createOMSourcedElement.

OMSourcedElement createOMSourcedElement(OMFactory factory, boolean push, boolean destructive) {
    OMNamespace ns = factory.createOMNamespace(qname.getNamespaceURI(), qname.getPrefix());
    OMDataSource ds;
    if (push) {
        ds = new PushOMDataSource(factory, getContent(), destructive);
    } else {
        ds = new PullOMDataSource(getContent(), destructive);
    }
    return factory.createOMElement(ds, qname.getLocalPart(), ns);
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) PushOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PushOMDataSource) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) PushOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PushOMDataSource) OMDataSource(org.apache.axiom.om.OMDataSource)

Aggregations

OMDataSource (org.apache.axiom.om.OMDataSource)15 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)8 OMFactory (org.apache.axiom.om.OMFactory)6 OMElement (org.apache.axiom.om.OMElement)4 OMNamespace (org.apache.axiom.om.OMNamespace)4 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)4 StringReader (java.io.StringReader)3 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)3 SOAPBody (org.apache.axiom.soap.SOAPBody)3 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)3 OutputStream (java.io.OutputStream)2 StringWriter (java.io.StringWriter)2 QName (javax.xml.namespace.QName)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 OMCloneOptions (org.apache.axiom.om.OMCloneOptions)2 AbstractPushOMDataSource (org.apache.axiom.om.ds.AbstractPushOMDataSource)2 CustomBuilder (org.apache.axiom.om.ds.custombuilder.CustomBuilder)2 IOException (java.io.IOException)1 Writer (java.io.Writer)1