Package org.dellroad.stuff.xml
Class AnnotatedXMLEventReader
java.lang.Object
javax.xml.stream.util.EventReaderDelegate
org.dellroad.stuff.xml.AnnotatedXMLEventReader
- All Implemented Interfaces:
Iterator<Object>
,XMLEventReader
XMLEventReader
that reads and removes an initial annotation element from an XML document.
The annotation element, if present, must be the first element inside the top-level document element.
readAnnotationElement()
must be provided by the subclass to determine
whether the first non-top element is the expected annotation element, and read it if so.
Whoever reads from this AnnotatedXMLEventReader
instance class will not see the annotation element.
This class can be used in combination with AnnotatedXMLEventWriter
to transparently annotate XML documents.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionnext()
peek()
protected abstract boolean
readAnnotationElement
(XMLEventReader reader) Determine if the next event from the givenXMLEventReader
is the annotation element, and if so, read it.Methods inherited from class javax.xml.stream.util.EventReaderDelegate
close, getElementText, getParent, getProperty, hasNext, nextTag, remove, setParent
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
AnnotatedXMLEventReader
Constructor.- Parameters:
parent
- parent reader
-
-
Method Details
-
next
- Specified by:
next
in interfaceIterator<Object>
- Overrides:
next
in classEventReaderDelegate
-
peek
- Specified by:
peek
in interfaceXMLEventReader
- Overrides:
peek
in classEventReaderDelegate
- Throws:
XMLStreamException
-
nextEvent
- Specified by:
nextEvent
in interfaceXMLEventReader
- Overrides:
nextEvent
in classEventReaderDelegate
- Throws:
XMLStreamException
-
readAnnotationElement
Determine if the next event from the givenXMLEventReader
is the annotation element, and if so, read it.This method should invoke
reader.peek()
to determine if the next event is the annotationStartElement
; if it's not, this method should not read any events and immediately return false. Otherwise, it should read the annotationStartElement
and all subsequent events up through the matchingEndElement
and return true.- Parameters:
reader
- source from which the rest of the annotation element is to be read- Returns:
- false if the annotation element is not seen, true if seen and fully read
- Throws:
XMLStreamException
- if a parsing error occurs
-