Search in sources :

Example 31 with OMFactory

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

the class TestIsCompleteAfterAddingIncompleteChild method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement incompleteElement = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<elem>text</elem>")).getDocumentElement(true);
    OMElement root = factory.createOMElement("root", null);
    assertTrue(root.isComplete());
    root.addChild(incompleteElement);
    assertFalse(root.isComplete());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement)

Example 32 with OMFactory

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

the class TestRemoveAttribute method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    OMAttribute attr1 = element.addAttribute("attr1", "value1", null);
    OMAttribute attr2 = element.addAttribute("attr2", "value2", null);
    element.removeAttribute(attr1);
    assertNull(attr1.getOwner());
    Iterator<OMAttribute> it = element.getAllAttributes();
    assertTrue(it.hasNext());
    assertSame(attr2, it.next());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 33 with OMFactory

use of org.apache.axiom.om.OMFactory 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 34 with OMFactory

use of org.apache.axiom.om.OMFactory 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 35 with OMFactory

use of org.apache.axiom.om.OMFactory 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)

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