Search in sources :

Example 26 with OMSourcedElement

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

the class TestCloseOnComplete method runTest.

@Override
protected void runTest() throws Throwable {
    PullOMDataSource ds = new PullOMDataSource("<root><a/></root>");
    OMSourcedElement element = metaFactory.getOMFactory().createOMElement(ds);
    OMNode child = element.getFirstOMChild();
    assertFalse(element.isComplete());
    assertTrue(ds.hasUnclosedReaders());
    child.getNextOMSibling();
    assertTrue(element.isComplete());
    assertFalse(ds.hasUnclosedReaders());
}
Also used : OMNode(org.apache.axiom.om.OMNode) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 27 with OMSourcedElement

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

the class TestDeclareNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<root xmlns:p='urn:ns1'><child/></root>"), "root", null);
    // Declare a namespace before expansion
    element.declareNamespace("urn:ns2", "p");
    // Force expansion; this should not overwrite the namespace declaration we just added
    assertThat(element.getFirstOMChild()).isNotNull();
    OMNamespace ns = element.findNamespaceURI("p");
    assertThat(ns).isNotNull();
    assertThat(ns.getPrefix()).isEqualTo("p");
    assertThat(ns.getNamespaceURI()).isEqualTo("urn:ns2");
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isSameAs(ns);
    assertThat(it.hasNext()).isFalse();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) OMNamespace(org.apache.axiom.om.OMNamespace) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 28 with OMSourcedElement

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

the class TestDetach method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    String xml1 = "<root><a/><b/></root>";
    String xml2 = "<child><c/><d/></child>";
    OMElement parent = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(xml1)).getDocumentElement();
    PullOMDataSource ds = new PullOMDataSource(xml2);
    OMSourcedElement omse = factory.createOMElement(ds, "child", null);
    parent.getFirstOMChild().insertSiblingBefore(omse);
    expansionStrategy.apply(omse);
    omse.detach();
    assertThat(ds.hasUnclosedReaders()).isEqualTo(expansionStrategy == PARTIAL);
    assertThat(ds.getReaderRequestCount()).isEqualTo(expansionStrategy == DONT_EXPAND ? 0 : 1);
    assertAbout(xml()).that(xml(OMElement.class, parent)).hasSameContentAs(xml1);
    assertAbout(xml()).that(xml(OMElement.class, omse)).hasSameContentAs(xml2);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 29 with OMSourcedElement

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

the class TestGetAllAttributes method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<root attr='value'/>"), "root", null);
    Iterator<OMAttribute> attributes = element.getAllAttributes();
    assertThat(attributes.hasNext()).isTrue();
    OMAttribute attr = attributes.next();
    assertThat(attr.getLocalName()).isEqualTo("attr");
    assertThat(attributes.hasNext()).isFalse();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 30 with OMSourcedElement

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

the class TestExpand method runTest.

@Override
protected void runTest() throws Throwable {
    OMSourcedElement element = TestDocument.DOCUMENT1.createOMSourcedElement(metaFactory.getOMFactory(), false, true);
    element.getAllDeclaredNamespaces();
    assertEquals("Expanded namespace count error", 1, countItems(element.getAllDeclaredNamespaces()));
    assertEquals("Expanded attribute count error", 1, countItems(element.getAllAttributes()));
    assertEquals("Expanded attribute value error", "1", element.getAttributeValue(new QName("books")));
    OMElement child = element.getFirstElement();
    assertEquals("Child element name", "type", child.getLocalName());
    assertEquals("Child element namespace", "http://www.sosnoski.com/uwjws/library", child.getNamespace().getNamespaceURI());
    OMNode next = child.getNextOMSibling();
    assertTrue("Expected child element", next instanceof OMElement);
    next = next.getNextOMSibling();
    assertTrue("Expected child element", next instanceof OMElement);
    child = (OMElement) next;
    assertEquals("Child element name", "book", child.getLocalName());
    assertEquals("Child element namespace", "http://www.sosnoski.com/uwjws/library", child.getNamespace().getNamespaceURI());
    assertEquals("Attribute value error", "xml", child.getAttributeValue(new QName("type")));
}
Also used : OMNode(org.apache.axiom.om.OMNode) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Aggregations

OMSourcedElement (org.apache.axiom.om.OMSourcedElement)44 OMFactory (org.apache.axiom.om.OMFactory)32 OMElement (org.apache.axiom.om.OMElement)16 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)14 QName (javax.xml.namespace.QName)13 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)11 OMNamespace (org.apache.axiom.om.OMNamespace)9 OMDataSource (org.apache.axiom.om.OMDataSource)8 OMNode (org.apache.axiom.om.OMNode)7 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)7 JAXBContext (javax.xml.bind.JAXBContext)6 JAXBOMDataSource (org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)6 XMLStreamReader (javax.xml.stream.XMLStreamReader)5 StringReader (java.io.StringReader)4 OMAttribute (org.apache.axiom.om.OMAttribute)4 DocumentBean (org.apache.axiom.ts.jaxb.beans.DocumentBean)4 DataSource (javax.activation.DataSource)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 BlobOMDataSource (org.apache.axiom.om.ds.BlobOMDataSource)3 WrappedTextNodeOMDataSourceFromDataSource (org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource)3