Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.2.8
-
None
-
None
Description
OMNode declares a set of serialize and serializeAndConsume methods taking an OutputStream or a Writer as argument. This is conceptually wrong because these methods only make sense for OMElements, not for other OMNodes.
Note that any attempt to call these methods on anything else than an OMElement will fail. Consider for example the following code:
OMFactory factory = OMAbstractFactory.getOMFactory();
OMText text = factory.createOMText("This is a test");
text.serialize(System.out);
It will fail with the following exception:
Exception in thread "main" javax.xml.stream.XMLStreamException: Trying to write END_DOCUMENT when document has no root (ie. trying to output empty document).
at com.ctc.wstx.sw.BaseStreamWriter.throwOutputError(BaseStreamWriter.java:1473)
at com.ctc.wstx.sw.BaseStreamWriter.reportNwfStructure(BaseStreamWriter.java:1502)
at com.ctc.wstx.sw.BaseStreamWriter.finishDocument(BaseStreamWriter.java:1663)
at com.ctc.wstx.sw.BaseStreamWriter.close(BaseStreamWriter.java:288)
at org.apache.axiom.om.impl.llom.OMNodeImpl.serialize(OMNodeImpl.java:333)
at Test.main(Test.java:14)
The serialize and serializeAndConsume methods declared by OMNode should be moved to the right interface, which would be either OMElement or OMContainer. The latter choice would be justified by the fact that all these methods make sense for OMDocument as well and some of them are already declared in OMDocument.