Search in sources :

Example 66 with OMElement

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

the class TestMultipleDefaultNS method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory omFactory = metaFactory.getOMFactory();
    OMNamespace defaultNS1 = omFactory.createOMNamespace("http://defaultNS1.org", null);
    OMNamespace defaultNS2 = omFactory.createOMNamespace("http://defaultNS2.org", null);
    OMElement omElementOne = omFactory.createOMElement("DocumentElement", omFactory.createOMNamespace("http://defaultNS1.org", ""));
    OMElement omElementOneChild = omFactory.createOMElement("ChildOne", null, omElementOne);
    OMElement omElementTwo = omFactory.createOMElement("Foo", defaultNS2, omElementOne);
    omElementTwo.declareDefaultNamespace("http://defaultNS2.org");
    OMElement omElementTwoChild = omFactory.createOMElement("ChildOne", null, omElementTwo);
    OMElement omElementThree = omFactory.createOMElement("Bar", defaultNS1, omElementTwo);
    omElementThree.declareDefaultNamespace("http://defaultNS1.org");
    OMNamespace omElementOneChildNS = omElementOneChild.getNamespace();
    OMNamespace omElementTwoChildNS = omElementTwoChild.getNamespace();
    // TODO: LLOM's and DOOM's behaviors are slightly different here; need to check if both are allowed
    assertTrue(omElementOneChildNS == null || "".equals(omElementOneChildNS.getNamespaceURI()));
    assertTrue(omElementTwoChildNS == null || "".equals(omElementTwoChildNS.getNamespaceURI()));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 67 with OMElement

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

the class TestResolveQNameWithDefaultNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<p:root xmlns:p='urn:ns1' xmlns='urn:ns2'/>");
    QName qname = element.resolveQName("test");
    assertEquals("", qname.getPrefix());
    assertEquals("urn:ns2", qname.getNamespaceURI());
    assertEquals("test", qname.getLocalPart());
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 68 with OMElement

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

the class TestGetChildrenWithName3 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace testNamespace = factory.createOMNamespace("http://test.ws.org", "test");
    OMElement documentElement = factory.createOMElement("Employees", testNamespace);
    documentElement.declareNamespace(testNamespace);
    factory.createOMText(documentElement, " ");
    OMElement e = factory.createOMElement("Employee", testNamespace, documentElement);
    e.setText("Apache Developer");
    Iterator<OMElement> childrenIter = documentElement.getChildrenWithName(new QName("http://test.ws.org", "Employee", "test"));
    // should walk past OMText
    OMElement employee = childrenIter.next();
    assertEquals("Employee test was incorrect", employee.getText(), "Apache Developer");
}
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 69 with OMElement

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

the class TestGetChildrenWithName4 method runTest.

@Override
protected void runTest() throws Throwable {
    // Create a document with 2 children, each named "sample" but
    // have different namespaces.
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace a = factory.createOMNamespace(NS_A, "a");
    OMNamespace b = factory.createOMNamespace(NS_B, "b");
    OMElement documentElement = factory.createOMElement("Document", a);
    factory.createOMElement("sample", a, documentElement);
    factory.createOMElement("sample", b, documentElement);
    // Test for fully qualified names
    QName qName = new QName(NS_A, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
    qName = new QName(NS_B, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
    qName = new QName(NS_C, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
    // Test for QName with no namespace.
    // Axiom 1.2.x implemented a legacy behavior where an empty namespace URI was interpreted
    // as a wildcard (see AXIOM-11). In Axiom 1.3.x, the matching is always strict.
    qName = new QName("", "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
    // Now add an unqualified sample element to the documentElement
    factory.createOMElement("sample", null, documentElement);
    // Repeat the tests
    qName = new QName(NS_A, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
    qName = new QName(NS_B, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
    qName = new QName(NS_C, "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
    // Since there actually is an unqualified element child, the most accurate
    // interpretation of getChildrenWithName should be to return this one 
    // child
    qName = new QName("", "sample");
    assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
}
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 70 with OMElement

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

the class TestGetDefaultNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", "urn:ns1", "");
    OMElement child = factory.createOMElement(new QName("urn:ns2", "child", "p"), parent);
    OMNamespace ns = child.getDefaultNamespace();
    assertNotNull(ns);
    assertEquals("", ns.getPrefix());
    assertEquals("urn:ns1", ns.getNamespaceURI());
}
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

OMElement (org.apache.axiom.om.OMElement)414 OMFactory (org.apache.axiom.om.OMFactory)202 OMNamespace (org.apache.axiom.om.OMNamespace)108 QName (javax.xml.namespace.QName)97 StringReader (java.io.StringReader)63 OMNode (org.apache.axiom.om.OMNode)43 OMText (org.apache.axiom.om.OMText)41 XMLStreamReader (javax.xml.stream.XMLStreamReader)37 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)32 OMAttribute (org.apache.axiom.om.OMAttribute)26 StringWriter (java.io.StringWriter)24 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)21 DataHandler (javax.activation.DataHandler)20 OMDocument (org.apache.axiom.om.OMDocument)19 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)18 Element (org.w3c.dom.Element)18 InputStream (java.io.InputStream)16 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)16 ByteArrayInputStream (java.io.ByteArrayInputStream)13 OMException (org.apache.axiom.om.OMException)13