Search in sources :

Example 6 with PullOMDataSource

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

the class TestAddAttribute method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<root attr='orgvalue'><child/></root>"), "root", null);
    // Add an attribute before expansion
    OMAttribute attr = strategy.addAttribute(element, "attr", null, "newvalue");
    // Force expansion; this should not overwrite the attribute we just added
    assertThat(element.getFirstOMChild()).isNotNull();
    OMAttribute attr2 = element.getAttribute(new QName("attr"));
    assertThat(attr2).isSameAs(attr);
    assertThat(attr2.getAttributeValue()).isEqualTo("newvalue");
    Iterator<OMAttribute> it = element.getAllAttributes();
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isSameAs(attr);
    assertThat(it.hasNext()).isFalse();
}
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)

Example 7 with PullOMDataSource

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

the class TestComplete method runTest.

@Override
protected void runTest() throws Throwable {
    // Build a root element and child OMSE
    OMFactory f = metaFactory.getOMFactory();
    OMNamespace ns = f.createOMNamespace("http://www.sosnoski.com/uwjws/library", "");
    OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
    OMElement child = f.createOMElement(new PullOMDataSource(TestDocument.DOCUMENT1.getContent()), "library", ns);
    OMElement root = f.createOMElement("root", rootNS);
    // Trigger expansion of the child OMSE
    // This will cause the child to be partially parsed (i.e. incomplete)
    child.getFirstOMChild();
    // Add the child OMSE to the root.
    root.addChild(child);
    // Normally adding an incomplete child to a parent will 
    // cause the parent to be marked as incomplete.
    // But OMSE's are self-contained...therefore the root
    // should still be complete
    assertTrue(!child.isComplete());
    assertTrue(root.isComplete());
    // Now repeat the test, but this time trigger the 
    // partial parsing of the child after adding it to the root.
    child = f.createOMElement(new PullOMDataSource(TestDocument.DOCUMENT1.getContent()), "library", ns);
    root = f.createOMElement("root", rootNS);
    root.addChild(child);
    // causes partial parsing...i.e. incomplete child
    child.getFirstOMChild();
    assertTrue(!child.isComplete());
    assertTrue(root.isComplete());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) OMElement(org.apache.axiom.om.OMElement)

Example 8 with PullOMDataSource

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

the class TestDiscard method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", null);
    OMElement child1 = factory.createOMElement("child1", null, parent);
    PullOMDataSource ds = new PullOMDataSource("<root><a/><b/></root>");
    OMSourcedElement omse = factory.createOMElement(ds, "root", null);
    parent.addChild(omse);
    OMElement child2 = factory.createOMElement("child2", null, parent);
    expansionStrategy.apply(omse);
    omse.discard();
    assertThat(child1.getNextOMSibling()).isSameAs(child2);
    assertThat(ds.hasUnclosedReaders()).isFalse();
    assertThat(ds.getReaderRequestCount()).isEqualTo(expansionStrategy == DONT_EXPAND ? 0 : 1);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 9 with PullOMDataSource

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

the class TestDocument method createOMSourcedElement.

OMSourcedElement createOMSourcedElement(OMFactory factory, boolean push, boolean destructive) {
    OMNamespace ns = factory.createOMNamespace(qname.getNamespaceURI(), qname.getPrefix());
    OMDataSource ds;
    if (push) {
        ds = new PushOMDataSource(factory, getContent(), destructive);
    } else {
        ds = new PullOMDataSource(getContent(), destructive);
    }
    return factory.createOMElement(ds, qname.getLocalPart(), ns);
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) PushOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PushOMDataSource) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) PushOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PushOMDataSource) OMDataSource(org.apache.axiom.om.OMDataSource)

Example 10 with PullOMDataSource

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

the class TestName2QualifiedPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory f = metaFactory.getOMFactory();
    // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
    OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
    OMNamespace ns = f.createOMNamespace("http://www.sosnoski.com/uwjws/library", "");
    OMElement element = f.createOMElement(new PullOMDataSource(TestDocument.DOCUMENT2.getContent()), "library", ns);
    OMElement root = f.createOMElement("root", rootNS);
    root.addChild(element);
    // Test getting the namespace, localpart and prefix.  This should used not result in expansion
    assertTrue(element.getLocalName().equals("library"));
    assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
    assertTrue(element.getNamespace().getPrefix().equals(""));
    // Serialize and consume.  This should not cause expansion and currently won't update
    // the name of the element.
    StringWriter writer = new StringWriter();
    root.serializeAndConsume(writer);
    String result = writer.toString();
    assertTrue(element.getLocalName().equals("library"));
    assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
    assertTrue(element.getNamespace().getPrefix().equals(""));
    assertTrue(result.indexOf("xmlns=") < // Make sure that the serialized string does not contain default prefix declaration
    0);
    assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) StringWriter(java.io.StringWriter) OMElement(org.apache.axiom.om.OMElement)

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