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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionnext()peek()protected abstract booleanreadAnnotationElement(XMLEventReader reader) Determine if the next event from the givenXMLEventReaderis the annotation element, and if so, read it.Methods inherited from class javax.xml.stream.util.EventReaderDelegate
close, getElementText, getParent, getProperty, hasNext, nextTag, remove, setParentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
AnnotatedXMLEventReader
Constructor.- Parameters:
parent- parent reader
-
-
Method Details
-
next
- Specified by:
nextin interfaceIterator<Object>- Overrides:
nextin classEventReaderDelegate
-
peek
- Specified by:
peekin interfaceXMLEventReader- Overrides:
peekin classEventReaderDelegate- Throws:
XMLStreamException
-
nextEvent
- Specified by:
nextEventin interfaceXMLEventReader- Overrides:
nextEventin classEventReaderDelegate- Throws:
XMLStreamException
-
readAnnotationElement
Determine if the next event from the givenXMLEventReaderis 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 annotationStartElementand all subsequent events up through the matchingEndElementand 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
-