"</wrap1>" +
"</root>";
XMLStreamReader xmlStreamReader =
StAXUtils.createXMLStreamReader(new StringReader(xml));
StAXOMBuilder b = new StAXOMBuilder(xmlStreamReader);
OMElement documentElement = b.getDocumentElement();
OMElement wrap2Element =
documentElement.getFirstElement().
getFirstElement().
getFirstElement();
OMElement elt = OMAbstractFactory.getOMFactory().createOMElement(
"testName", "urn:testNs", "ns1"
);
elt.addChild(wrap2Element);
XMLStreamReader reader = wrap2Element.getXMLStreamReaderWithoutCaching();
// Make sure the reader is an OMStAXWrapper
if (reader instanceof OMXMLStreamReaderEx) {
OMXMLStreamReaderEx wrapper = (OMXMLStreamReaderEx) reader;
assertTrue(!wrapper.isClosed());
wrapper.releaseParserOnClose(true);
}
int count = 0;
while (reader.hasNext()) {
reader.next();
count ++;
}
// 4 events are produced: START_DOCUMENT, START_ELEMENT, END_ELEMENT and END_DOCUMENT
assertEquals(4, count);
// Make sure that the wrapper can be closed without failing
reader.close();
reader.close(); // This should be a noop since the parser is closed.
// Closing the parser should also close the parser on the builder (since they are the same)
assertTrue(b.isClosed());
b.close(); // This should be a noop since the parser is closed
// Calling getProperty after a close should return null, not an exception
assertTrue(reader.getProperty("dummyProperty") == null);
// Calling builder.getReaderProperty should return null, not an exception
assertTrue(b.getReaderProperty("dummyProperty") == null);
}