Search in sources :

Example 86 with OMFactory

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

the class TestAddChildWithParent method runTest.

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

Example 87 with OMFactory

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

the class TestChildReDeclaringGrandParentsDefaultNSWithPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory fac = metaFactory.getOMFactory();
    OMElement elem = fac.createOMElement("RequestSecurityToken", fac.createOMNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust", ""));
    fac.createOMElement(new QName("TokenType"), elem).setText("test");
    fac.createOMElement(new QName("RequestType"), elem).setText("test1");
    OMElement entElem = fac.createOMElement(new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "Entropy", "wst"), elem);
    OMElement binSecElem = fac.createOMElement(new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "Binarysecret", "wst"), entElem);
    binSecElem.setText("secret value");
    String xml = elem.toString();
    assertTrue("Binarysecret element should have \'wst\' ns prefix", xml.indexOf("<wst:Binarysecret") != -1);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 88 with OMFactory

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

the class TestFindNamespaceURIWithPrefixUndeclaring method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", null);
    OMElement child = factory.createOMElement("child", null, parent);
    OMNamespace ns = parent.declareNamespace("urn:test", "p");
    child.undeclarePrefix("p");
    assertEquals(ns, parent.findNamespaceURI("p"));
    assertNull(child.findNamespaceURI("p"));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 89 with OMFactory

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

the class TestGetAttributeValueNonExisting method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    element.addAttribute("attr", "value", null);
    assertNull(element.getAttributeValue(new QName("urn:ns", "attr2")));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 90 with OMFactory

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

the class TestDeclareNamespaceWithEmptyPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement(new QName("test"));
    OMNamespace ns = element.declareNamespace("urn:ns", "");
    assertThat(ns.getNamespaceURI()).isEqualTo("urn:ns");
    assertThat(ns.getPrefix()).isEmpty();
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    assertThat(it.hasNext()).isTrue();
    OMNamespace ns2 = it.next();
    assertThat(ns2).isEqualTo(ns);
    assertThat(it.hasNext()).isFalse();
}
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)

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