Search in sources :

Example 81 with OMFactory

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

the class TestAddAttributeWithExistingNamespaceDeclarationInScope method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement root = factory.createOMElement(new QName("test"));
    OMNamespace ns = factory.createOMNamespace("urn:ns", "p");
    root.declareNamespace(ns);
    OMElement child = factory.createOMElement(new QName("test"), root);
    strategy.addAttribute(child, "test", ns, "test");
    Iterator<OMNamespace> it = child.getAllDeclaredNamespaces();
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 82 with OMFactory

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

the class TestAddChild method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    OMText text = factory.createOMText("test");
    element.addChild(text);
    assertSame(element, text.getParent());
    assertSame(text, element.getFirstOMChild());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 83 with OMFactory

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

the class TestAddChild2 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    String localName = "TestLocalName";
    String childLocalName = "TestChildLocalName";
    String namespace = "http://ws.apache.org/axis2/ns";
    String prefix = "axis2";
    OMElement elem = factory.createOMElement(localName, namespace, prefix);
    OMElement childElem = factory.createOMElement(childLocalName, namespace, prefix);
    elem.addChild(childElem);
    Iterator<OMElement> it = elem.getChildrenWithName(new QName(namespace, childLocalName));
    int count = 0;
    while (it.hasNext()) {
        OMElement child = it.next();
        assertEquals("Child local name mismatch", childLocalName, child.getLocalName());
        assertEquals("Child namespace mismatch", namespace, child.getNamespace().getNamespaceURI());
        count++;
    }
    assertEquals("In correct number of children", 1, count);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 84 with OMFactory

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

the class TestGetChildElementsConcurrentModification method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", null);
    factory.createOMElement("child1", null, parent);
    factory.createOMElement("child2", null, parent);
    factory.createOMElement("child3", null, parent);
    Iterator<OMElement> it = parent.getChildElements();
    it.next();
    OMElement child2 = it.next();
    child2.detach();
    try {
        it.next();
        fail("Expected ConcurrentModificationException");
    } catch (ConcurrentModificationException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) ConcurrentModificationException(java.util.ConcurrentModificationException) OMElement(org.apache.axiom.om.OMElement)

Example 85 with OMFactory

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

the class TestAddChildDiscarded method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><a/><b/></root>")).getDocumentElement();
    // Partially build the parent
    parent.getFirstOMChild();
    parent.discard();
    try {
        parent.addChild(factory.createOMElement("c", null));
        fail("Expected NodeUnavailableException");
    } catch (NodeUnavailableException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringReader(java.io.StringReader) NodeUnavailableException(org.apache.axiom.om.NodeUnavailableException) 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