Search in sources :

Example 16 with OMFactory

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

the class TestAppendChildIncomplete method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    Document document = (Document) OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><a/><b/></root>")).getDocument();
    Element parent = document.getDocumentElement();
    parent.appendChild(document.createElementNS(null, "c"));
    NodeList children = parent.getChildNodes();
    assertEquals(3, children.getLength());
    assertEquals("a", children.item(0).getLocalName());
    assertEquals("b", children.item(1).getLocalName());
    assertEquals("c", children.item(2).getLocalName());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) StringReader(java.io.StringReader) Document(org.w3c.dom.Document)

Example 17 with OMFactory

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

the class TestInsertBeforeIncomplete method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    Document document = (Document) OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><a/><b/></root>")).getDocument();
    Element parent = document.getDocumentElement();
    parent.insertBefore(document.createElementNS(null, "c"), null);
    NodeList children = parent.getChildNodes();
    assertEquals(3, children.getLength());
    assertEquals("a", children.item(0).getLocalName());
    assertEquals("b", children.item(1).getLocalName());
    assertEquals("c", children.item(2).getLocalName());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) StringReader(java.io.StringReader) Document(org.w3c.dom.Document)

Example 18 with OMFactory

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

the class TestRemoveAttributeNSNamespaceDeclaration method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    element.declareNamespace("urn:test", "ns");
    ((Element) element).removeAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "ns");
    assertFalse(element.getAllDeclaredNamespaces().hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement)

Example 19 with OMFactory

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

the class JAXBTest method test.

@Test
public void test() throws Exception {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    JAXBContext context = JAXBContext.newInstance(DummyBean.class);
    OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, new DummyBean()));
    element.serialize(new ByteArrayOutputStream());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) JAXBContext(javax.xml.bind.JAXBContext) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource) Test(org.junit.Test)

Example 20 with OMFactory

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

the class SetNamespaceTestCase method runTest.

@Override
protected final void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element;
    OMNamedInformationItem node;
    if (context()) {
        // To avoid collisions if prefixInScope is the empty string
        OMNamespace dummyNS = factory.createOMNamespace("__dummy__", "__dummy__");
        OMElement parent = factory.createOMElement("parent", dummyNS);
        element = factory.createOMElement("test", dummyNS, parent);
        if (prefixInScope != null) {
            if (prefixInScope.length() == 0) {
                parent.declareDefaultNamespace(namespaceURI);
            } else {
                parent.declareNamespace(namespaceURI, prefixInScope);
            }
        }
    } else {
        element = null;
    }
    node = node(factory, element);
    OMNamespace ns = namespaceURI == null ? null : factory.createOMNamespace(namespaceURI, prefix);
    try {
        setNamespace(node, ns);
        if (invalid) {
            fail("Expected IllegalArgumentException");
        }
    } catch (IllegalArgumentException ex) {
        if (invalid) {
            return;
        } else {
            throw ex;
        }
    }
    String expectedPrefix;
    if (this.expectedPrefix == null) {
        expectedPrefix = node.getPrefix();
        assertNotNull(expectedPrefix);
        assertFalse(expectedPrefix.length() == 0);
    } else {
        expectedPrefix = this.expectedPrefix;
        if (expectedPrefix.length() == 0) {
            assertNull(node.getPrefix());
        } else {
            assertEquals(expectedPrefix, node.getPrefix());
        }
    }
    if (namespaceURI == null || namespaceURI.length() == 0) {
        assertNull(node.getNamespace());
    } else {
        OMNamespace actualNS = node.getNamespace();
        assertEquals(expectedPrefix, actualNS.getPrefix());
        assertEquals(namespaceURI, actualNS.getNamespaceURI());
    }
    if (namespaceURI == null || namespaceURI.length() == 0) {
        assertNull(node.getNamespaceURI());
    } else {
        assertEquals(namespaceURI, node.getNamespaceURI());
    }
    QName qname = node.getQName();
    assertEquals(expectedPrefix, qname.getPrefix());
    assertEquals(namespaceURI == null ? "" : namespaceURI, qname.getNamespaceURI());
    if (element != null) {
        Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
        if (expectNSDecl) {
            assertTrue(it.hasNext());
            OMNamespace decl = it.next();
            assertEquals(expectedPrefix, decl.getPrefix());
            assertEquals(namespaceURI == null ? "" : namespaceURI, decl.getNamespaceURI());
        }
        assertFalse(it.hasNext());
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamedInformationItem(org.apache.axiom.om.OMNamedInformationItem) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMFactory (org.apache.axiom.om.OMFactory)254 OMElement (org.apache.axiom.om.OMElement)189 OMNamespace (org.apache.axiom.om.OMNamespace)94 QName (javax.xml.namespace.QName)62 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 XMLStreamReader (javax.xml.stream.XMLStreamReader)14 OMNode (org.apache.axiom.om.OMNode)14 DataHandler (javax.activation.DataHandler)12 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