Search in sources :

Example 56 with OMFactory

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

the class TestSetTextQNameWithExistingChildren method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("TestElement", null);
    // Add some children of various types
    factory.createOMText(element, "some text");
    factory.createOMText(element, "cdata section", OMNode.CDATA_SECTION_NODE);
    factory.createOMComment(element, "comment");
    factory.createOMProcessingInstruction(element, "piTarget", "piData");
    factory.createOMElement("child", null, element);
    QName qname = new QName("urn:ns1", "test", "ns");
    element.setText(qname);
    assertEquals("ns:test", element.getText());
    // Check that OMElement#setText() has created the expected nodes
    OMNode child = element.getFirstOMChild();
    assertTrue(child instanceof OMText);
    assertSame(element, child.getParent());
    assertEquals("ns:test", ((OMText) child).getText());
    assertNull(child.getNextOMSibling());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) QName(javax.xml.namespace.QName) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 57 with OMFactory

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

the class TestSetTextQNameWithoutNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    QName qname = new QName("test");
    element.setText(qname);
    assertFalse(element.getAllDeclaredNamespaces().hasNext());
    assertEquals("test", element.getText());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 58 with OMFactory

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

the class TestUnmarshalWithDataHandler method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
    DocumentBean orgBean = new DocumentBean();
    orgBean.setId("AB23498");
    orgBean.setContent(new DataHandler("test content", "text/plain"));
    OMElement element = factory.createOMElement(new JAXBOMDataSource(context, orgBean));
    DocumentBean bean = (DocumentBean) element.unmarshal(context, null, true);
    assertEquals(orgBean.getId(), bean.getId());
    assertEquals(orgBean.getContent(), bean.getContent());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) DocumentBean(org.apache.axiom.ts.jaxb.beans.DocumentBean) JAXBContext(javax.xml.bind.JAXBContext) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)

Example 59 with OMFactory

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

the class TestWriteTextTo method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement(new QName("a"));
    factory.createOMText(element, "test");
    StringWriter sw = new StringWriter();
    InstrumentedWriter out = new InstrumentedWriter(sw);
    element.writeTextTo(out, true);
    assertEquals(element.getText(), sw.toString());
    assertFalse(out.isClosed());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringWriter(java.io.StringWriter) QName(javax.xml.namespace.QName) InstrumentedWriter(org.apache.axiom.testutils.io.InstrumentedWriter) OMElement(org.apache.axiom.om.OMElement)

Example 60 with OMFactory

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

the class TestCreateOMElementWithDefaultNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = variant.createOMElement(factory, parentSupplier.createParent(factory), "test", "urn:ns", "");
    assertTrue(element.isComplete());
    assertEquals("test", element.getLocalName());
    OMNamespace ns = factory.createOMNamespace("urn:ns", "");
    assertEquals(ns, element.getNamespace());
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    assertTrue(it.hasNext());
    assertEquals(ns, it.next());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMFactory (org.apache.axiom.om.OMFactory)270 OMElement (org.apache.axiom.om.OMElement)202 OMNamespace (org.apache.axiom.om.OMNamespace)101 QName (javax.xml.namespace.QName)71 StringReader (java.io.StringReader)37 OMText (org.apache.axiom.om.OMText)35 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)32 OMAttribute (org.apache.axiom.om.OMAttribute)31 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)26 StringWriter (java.io.StringWriter)18 OMDocument (org.apache.axiom.om.OMDocument)18 DataHandler (javax.activation.DataHandler)14 XMLStreamReader (javax.xml.stream.XMLStreamReader)14 OMNode (org.apache.axiom.om.OMNode)14 OMException (org.apache.axiom.om.OMException)12 DataSource (javax.activation.DataSource)11 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)9 RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)9 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)8 Element (org.w3c.dom.Element)8