org.dellroad.stuff.xml
Class AnnotatedXMLEventWriter

java.lang.Object
  extended by org.dellroad.stuff.xml.AnnotatedXMLEventWriter
All Implemented Interfaces:
XMLEventConsumer, XMLEventWriter
Direct Known Subclasses:
UpdatesXMLEventWriter

public abstract class AnnotatedXMLEventWriter
extends Object
implements XMLEventWriter

XMLEventWriter that adds an extra annotation element to an XML document as it is written. The annotation element will be added as the first element inside the top-level document element.

This class can be used in combination with AnnotatedXMLEventReader to transparently annotate XML documents.

See Also:
AnnotatedXMLEventReader

Field Summary
protected  XMLEventFactory xmlEventFactory
           
 
Constructor Summary
AnnotatedXMLEventWriter(XMLEventWriter inner)
           
 
Method Summary
 void add(XMLEvent event)
           
 void add(XMLEventReader reader)
           
protected abstract  void addAnnotationElement()
          Add the annotation element.
 void close()
           
 void flush()
           
 NamespaceContext getNamespaceContext()
           
 String getPrefix(String uri)
           
protected  String getTrailingSpace()
          Get the whitespace found between the opening document tag and the first non-space child.
 void setDefaultNamespace(String uri)
           
 void setNamespaceContext(NamespaceContext context)
           
 void setPrefix(String prefix, String uri)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlEventFactory

protected final XMLEventFactory xmlEventFactory
Constructor Detail

AnnotatedXMLEventWriter

public AnnotatedXMLEventWriter(XMLEventWriter inner)
Method Detail

add

public void add(XMLEvent event)
         throws XMLStreamException
Specified by:
add in interface XMLEventConsumer
Specified by:
add in interface XMLEventWriter
Throws:
XMLStreamException

add

public void add(XMLEventReader reader)
         throws XMLStreamException
Specified by:
add in interface XMLEventWriter
Throws:
XMLStreamException

flush

public void flush()
           throws XMLStreamException
Specified by:
flush in interface XMLEventWriter
Throws:
XMLStreamException

close

public void close()
           throws XMLStreamException
Specified by:
close in interface XMLEventWriter
Throws:
XMLStreamException

getPrefix

public String getPrefix(String uri)
                 throws XMLStreamException
Specified by:
getPrefix in interface XMLEventWriter
Throws:
XMLStreamException

setPrefix

public void setPrefix(String prefix,
                      String uri)
               throws XMLStreamException
Specified by:
setPrefix in interface XMLEventWriter
Throws:
XMLStreamException

setDefaultNamespace

public void setDefaultNamespace(String uri)
                         throws XMLStreamException
Specified by:
setDefaultNamespace in interface XMLEventWriter
Throws:
XMLStreamException

setNamespaceContext

public void setNamespaceContext(NamespaceContext context)
                         throws XMLStreamException
Specified by:
setNamespaceContext in interface XMLEventWriter
Throws:
XMLStreamException

getNamespaceContext

public NamespaceContext getNamespaceContext()
Specified by:
getNamespaceContext in interface XMLEventWriter

getTrailingSpace

protected String getTrailingSpace()
Get the whitespace found between the opening document tag and the first non-space child.


addAnnotationElement

protected abstract void addAnnotationElement()
                                      throws XMLStreamException
Add the annotation element.

This method should add() the StartElement for the annotation element, followed by any nested content, and then lastly the EndElement for the annotation element.

Throws:
XMLStreamException