Search in sources :

Example 41 with OMSourcedElement

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

the class TestExceptionDuringSerialization method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory omFactory = metaFactory.getOMFactory();
    JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
    DocumentBean object = new DocumentBean();
    object.setId("test");
    OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, object));
    XMLStreamException exception = new XMLStreamException("TEST");
    try {
        element.serialize(new ExceptionXMLStreamWriterWrapper(StAX.createNullXMLStreamWriter(), exception));
        fail("Expected XMLStreamException");
    } catch (XMLStreamException ex) {
        assertSame(exception, ex);
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) XMLStreamException(javax.xml.stream.XMLStreamException) DocumentBean(org.apache.axiom.ts.jaxb.beans.DocumentBean) JAXBContext(javax.xml.bind.JAXBContext) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)

Example 42 with OMSourcedElement

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

the class TestGetNameFromPlainObject method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory omFactory = metaFactory.getOMFactory();
    JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
    OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, new DocumentBean()));
    assertEquals("http://ws.apache.org/axiom/test/jaxb", element.getNamespaceURI());
    assertEquals("document", element.getLocalName());
    assertFalse(element.isExpanded());
    // Force expansion so that OMSourcedElement compares the namespace URI and local name
    // provided by JAXBOMDataSource with the actual name of the element
    element.getFirstOMChild();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) DocumentBean(org.apache.axiom.ts.jaxb.beans.DocumentBean) JAXBContext(javax.xml.bind.JAXBContext) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)

Example 43 with OMSourcedElement

use of org.apache.axiom.om.OMSourcedElement 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 44 with OMSourcedElement

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

the class TestWriteTextToWithNonDestructiveOMDataSource method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    DataSource ds = new RandomDataSource(665544, 32, 128, 20000000);
    QName qname = new QName("a");
    OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, Charset.forName("ascii")), qname);
    Reader in = new InputStreamReader(ds.getInputStream(), "ascii");
    Writer out = new CharacterStreamComparator(in);
    // cache doesn't matter here
    element.writeTextTo(out, true);
    out.close();
    assertFalse(element.isExpanded());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) InputStreamReader(java.io.InputStreamReader) QName(javax.xml.namespace.QName) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) CharacterStreamComparator(org.apache.axiom.testutils.io.CharacterStreamComparator) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) Writer(java.io.Writer) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Aggregations

OMSourcedElement (org.apache.axiom.om.OMSourcedElement)44 OMFactory (org.apache.axiom.om.OMFactory)32 OMElement (org.apache.axiom.om.OMElement)16 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)14 QName (javax.xml.namespace.QName)13 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)11 OMNamespace (org.apache.axiom.om.OMNamespace)9 OMDataSource (org.apache.axiom.om.OMDataSource)8 OMNode (org.apache.axiom.om.OMNode)7 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)7 JAXBContext (javax.xml.bind.JAXBContext)6 JAXBOMDataSource (org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)6 XMLStreamReader (javax.xml.stream.XMLStreamReader)5 StringReader (java.io.StringReader)4 OMAttribute (org.apache.axiom.om.OMAttribute)4 DocumentBean (org.apache.axiom.ts.jaxb.beans.DocumentBean)4 DataSource (javax.activation.DataSource)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 BlobOMDataSource (org.apache.axiom.om.ds.BlobOMDataSource)3 WrappedTextNodeOMDataSourceFromDataSource (org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource)3