Delay calling writeStartElement()
Java's default XMLStreamWriter is rather bad at emitting self-closing
tags, in that it will not do that unless we explicitly call
writeEmptyElement().
This is rather unfortunate, as there is plenty of cases, where it's
the writer's job to realize the element should be self-closing, for
example in case it carries only attributes -- which we simply have
no way of driving through XMLStreamWriter.
In order to make this work, we need to delay the call to
writeStartElement() until we see the next event, which can end up
being writeEndElement() -- which is where when we need to use
writeEmptyElement() instead.
Since value serializers can end up emitting namespace declarations
and characters into the stream, we hide the writer behind two classes:
- ValueWriter, which is abstract class strictly for use by serializers
and exposes minimal methods required for them
- StreamWriterFacade, which is the sole implementation of ValueWriter,
which holds methods required by XMLStreamNormalizedNodeStreamWriter
StreamWriterFacade thus has visibility into activity of both call
sites and can make appropriate decisions.
JIRA: YANGTOOLS-927
Change-Id: Ib42d7662d0b9b648132e93bc4ea9fbe012104deb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>