Search in sources :

Example 11 with OMDataSource

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

the class TestWrappedTextNodeOMDataSourceFromReader method runTest.

@Override
protected void runTest() throws Throwable {
    Random random = new Random();
    StringBuilder buffer = new StringBuilder(40000);
    for (int i = 0; i < 40000; i++) {
        buffer.append((char) (32 + random.nextInt(96)));
    }
    String testData = buffer.toString();
    QName qname = new QName("data");
    OMDataSource ds = new WrappedTextNodeOMDataSourceFromReader(qname, new StringReader(testData));
    OMFactory factory = metaFactory.getOMFactory();
    OMSourcedElement element = factory.createOMElement(ds, qname);
    assertEquals(testData, element.getText());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) Random(java.util.Random) OMDataSource(org.apache.axiom.om.OMDataSource) QName(javax.xml.namespace.QName) StringReader(java.io.StringReader) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) WrappedTextNodeOMDataSourceFromReader(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromReader)

Example 12 with OMDataSource

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

the class FirstElementNameWithParserTestCase method runTest.

@Override
protected final void runTest() throws Throwable {
    SOAPEnvelope orgEnvelope = soapFactory.getDefaultEnvelope();
    orgEnvelope.getBody().addChild(soapFactory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix()));
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(orgEnvelope.toString()));
    SOAPBody body = builder.getSOAPEnvelope().getBody();
    runTest(body);
    if (supportsOptimization) {
        // The expectation is that even after looking at the payload element name, registering
        // a custom builder still transforms the element.
        ((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new CustomBuilder() {

            @Override
            public OMDataSource create(OMElement element) throws OMException {
                try {
                    element.getXMLStreamReaderWithoutCaching().close();
                } catch (XMLStreamException ex) {
                    throw new OMException(ex);
                }
                return new AbstractPushOMDataSource() {

                    @Override
                    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
                        xmlWriter.writeEmptyElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
                    }

                    @Override
                    public boolean isDestructiveWrite() {
                        return false;
                    }
                };
            }
        });
        assertThat(body.getFirstElement()).isInstanceOf(OMSourcedElement.class);
    }
}
Also used : OMDataSource(org.apache.axiom.om.OMDataSource) AbstractPushOMDataSource(org.apache.axiom.om.ds.AbstractPushOMDataSource) CustomBuilderSupport(org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) CustomBuilder(org.apache.axiom.om.ds.custombuilder.CustomBuilder) SOAPBody(org.apache.axiom.soap.SOAPBody) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StringReader(java.io.StringReader) AbstractPushOMDataSource(org.apache.axiom.om.ds.AbstractPushOMDataSource) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) OMException(org.apache.axiom.om.OMException)

Aggregations

OMDataSource (org.apache.axiom.om.OMDataSource)12 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 SOAPBody (org.apache.axiom.soap.SOAPBody)3 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)3 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 StringWriter (java.io.StringWriter)1 Random (java.util.Random)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 ByteArrayDataSource (org.apache.axiom.attachments.ByteArrayDataSource)1