Delay calling writeStartElement() 82/79582/7
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 16 Jan 2019 16:29:52 +0000 (17:29 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 18 Jan 2019 10:40:41 +0000 (11:40 +0100)
commit262e81a79d1a124f8f5c6a747d8408fabe0b9048
treed32820167193d3bf1d02912b146dd48fe0448c2c
parentd97a9c34f320924468dea668fa8191b3ad10706d
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>
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/SchemaAwareXMLStreamNormalizedNodeStreamWriter.java
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/SchemaAwareXMLStreamWriterUtils.java
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/SchemalessXMLStreamNormalizedNodeStreamWriter.java
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/SchemalessXMLStreamWriterUtils.java
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/StreamWriterFacade.java [new file with mode: 0644]
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/ValueWriter.java [new file with mode: 0644]
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XMLStreamNormalizedNodeStreamWriter.java
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XMLStreamWriterUtils.java
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlStreamUtilsTest.java