Search in sources :

Example 66 with OMFactory

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

the class TestSerialization method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory fac = metaFactory.getOMFactory();
    OMNamespace nsParent = createNamespace(fac, parent);
    OMNamespace nsChildren = createNamespace(fac, children);
    OMElement personElem = fac.createOMElement("person", nsParent);
    OMElement nameElem = fac.createOMElement("name", nsChildren);
    nameElem.setText("John");
    OMElement ageElem = fac.createOMElement("age", nsChildren);
    ageElem.setText("34");
    OMElement weightElem = fac.createOMElement("weight", nsChildren);
    weightElem.setText("50");
    //Add children to the person element
    personElem.addChild(nameElem);
    personElem.addChild(ageElem);
    personElem.addChild(weightElem);
    assertEquals(expected, personElem.toString());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 67 with OMFactory

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

the class TestCreateOMAttributeWithInvalidNamespace2 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("urn:test", "");
    try {
        factory.createOMAttribute("attr", ns, "value");
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
        assertEquals("Cannot create an unprefixed attribute with a namespace", ex.getMessage());
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace)

Example 68 with OMFactory

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

the class TestCreateOMElementWithNonDefaultNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = variant.createOMElement(factory, parentSupplier.createParent(factory), "test", "urn:ns", "ns");
    assertTrue(element.isComplete());
    assertEquals("test", element.getLocalName());
    OMNamespace ns = factory.createOMNamespace("urn:ns", "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)

Example 69 with OMFactory

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

the class TestCreateOMElementWithoutNamespaceNullPrefix method runTest.

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

Example 70 with OMFactory

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

the class TestCreateOMEntityReferenceWithNullParent method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMEntityReference entref = factory.createOMEntityReference(null, "testref");
    assertNull(entref.getParent());
    assertEquals("testref", entref.getName());
    assertNull(entref.getReplacementText());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMEntityReference(org.apache.axiom.om.OMEntityReference)

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