Search in sources :

Example 61 with OMFactory

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

the class TestCreateOMElementWithGeneratedPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = variant.createOMElement(factory, parentSupplier.createParent(factory), "test", "urn:test", null);
    assertEquals("test", element.getLocalName());
    OMNamespace ns = element.getNamespace();
    assertNotNull(ns);
    assertEquals("urn:test", ns.getNamespaceURI());
    // Axiom auto-generates a prefix here
    assertTrue(ns.getPrefix().length() != 0);
    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 62 with OMFactory

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

the class TestCreateOMElementWithInvalidNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    try {
        variant.createOMElement(factory, parentSupplier.createParent(factory), "test", "", "p");
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory)

Example 63 with OMFactory

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

the class TestCreateOMElementWithNamespaceInScope1 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", "urn:test", "p");
    OMElement child = variant.createOMElement(factory, parent, "child", "urn:test", null);
    assertTrue(child.isComplete());
    assertEquals("child", child.getLocalName());
    OMNamespace ns = factory.createOMNamespace("urn:test", "p");
    assertEquals(ns, child.getNamespace());
    Iterator<OMNamespace> it = child.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 64 with OMFactory

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

the class TestCreateOMElementWithNamespaceInScope2 method runTest.

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

Example 65 with OMFactory

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

the class TestRemoveChildren method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><a>A</a><b>B</b></root>")).getDocumentElement();
    if (complete) {
        element.build();
    }
    OMElement firstChild = (OMElement) element.getFirstOMChild();
    assertEquals(complete, element.isComplete());
    assertEquals(complete, firstChild.isComplete());
    element.removeChildren();
    // We still need to be able to get the content of the child we retrieved before
    // calling removeChildren.
    assertEquals("A", firstChild.getText());
    // Test that the child has been detached correctly.
    assertNull(firstChild.getParent());
    assertNull(firstChild.getPreviousOMSibling());
    assertNull(firstChild.getNextOMSibling());
    // Test that the element is now empty.
    assertNull(element.getFirstOMChild());
    // Check that the element is in a clean state and that we are able to add
    // new children.
    element.addChild(factory.createOMElement("c", null));
    assertAbout(xml()).that(xml(OMElement.class, element)).hasSameContentAs("<root><c/></root>");
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringReader(java.io.StringReader) 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