Search in sources :

Example 16 with PullOMDataSource

use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource 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 17 with PullOMDataSource

use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource 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 18 with PullOMDataSource

use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource 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 19 with PullOMDataSource

use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource 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 20 with PullOMDataSource

use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.

the class TestGetAttribute method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<root attr='value'/>"), "root", null);
    OMAttribute attr = element.getAttribute(new QName("attr"));
    assertThat(attr).isNotNull();
    assertThat(attr.getLocalName()).isEqualTo("attr");
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) QName(javax.xml.namespace.QName) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)29 OMFactory (org.apache.axiom.om.OMFactory)26 OMElement (org.apache.axiom.om.OMElement)18 OMNamespace (org.apache.axiom.om.OMNamespace)16 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)14 StringWriter (java.io.StringWriter)13 QName (javax.xml.namespace.QName)4 OMAttribute (org.apache.axiom.om.OMAttribute)3 OMDataSource (org.apache.axiom.om.OMDataSource)3 StringReader (java.io.StringReader)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 OMNode (org.apache.axiom.om.OMNode)2 AbstractPullOMDataSource (org.apache.axiom.om.ds.AbstractPullOMDataSource)2 OMContainer (org.apache.axiom.om.OMContainer)1 AbstractPushOMDataSource (org.apache.axiom.om.ds.AbstractPushOMDataSource)1 XML (org.apache.axiom.ts.dimension.serialization.XML)1 PushOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PushOMDataSource)1 InputSource (org.xml.sax.InputSource)1