Class Stax2EventReaderAdapter

  • All Implemented Interfaces:
    java.util.Iterator<java.lang.Object>, javax.xml.stream.XMLEventReader, XMLEventReader2

    public class Stax2EventReaderAdapter
    extends java.lang.Object
    implements XMLEventReader2
    This adapter implements parts of XMLEventReader2, the extended stream reader defined by Stax2 extension, by wrapping a vanilla Stax 1.0 XMLEventReader implementation.

    Note: the implementation may be incomplete as-is, since not all features needed are necessarily accessible via basic Stax 1.0 interface. As such, two main use cases for this wrapper are:

    • Serve as convenient base class for a complete implementation, which can use native accessors provided by the wrapped Stax implementation
    • To be used for tasks that make limited use of Stax2 API, such that missing parts are not needed
    Author:
    Tatu Saloranta
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.xml.stream.XMLEventReader mReader  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Stax2EventReaderAdapter​(javax.xml.stream.XMLEventReader er)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      java.lang.String getElementText()  
      java.lang.Object getProperty​(java.lang.String name)  
      boolean hasNext()  
      boolean hasNextEvent()
      Method that is similar to XMLEventReader.hasNext(), except that it can throw a XMLStreamException.
      boolean isPropertySupported​(java.lang.String name)
      Method similar to XMLInputFactory.isPropertySupported(java.lang.String), used to determine whether a property is supported by the Reader instance.
      java.lang.Object next()  
      javax.xml.stream.events.XMLEvent nextEvent()  
      javax.xml.stream.events.XMLEvent nextTag()  
      javax.xml.stream.events.XMLEvent peek()  
      void remove()
      Note: only here because we implement Iterator interface.
      boolean setProperty​(java.lang.String name, java.lang.Object value)
      Method that can be used to set per-reader properties; a subset of properties one can set via matching XMLInputFactory2 instance.
      static XMLEventReader2 wrapIfNecessary​(javax.xml.stream.XMLEventReader er)
      Method that should be used to add dynamic support for XMLEventReader2.
      • 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
    • Field Detail

      • mReader

        protected final javax.xml.stream.XMLEventReader mReader
    • Constructor Detail

      • Stax2EventReaderAdapter

        protected Stax2EventReaderAdapter​(javax.xml.stream.XMLEventReader er)
    • Method Detail

      • wrapIfNecessary

        public static XMLEventReader2 wrapIfNecessary​(javax.xml.stream.XMLEventReader er)
        Method that should be used to add dynamic support for XMLEventReader2. Method will check whether the stream reader passed happens to be a XMLEventReader2; and if it is, return it properly cast. If not, it will create necessary wrapper.
      • close

        public void close()
                   throws javax.xml.stream.XMLStreamException
        Specified by:
        close in interface javax.xml.stream.XMLEventReader
        Throws:
        javax.xml.stream.XMLStreamException
      • getElementText

        public java.lang.String getElementText()
                                        throws javax.xml.stream.XMLStreamException
        Specified by:
        getElementText in interface javax.xml.stream.XMLEventReader
        Throws:
        javax.xml.stream.XMLStreamException
      • getProperty

        public java.lang.Object getProperty​(java.lang.String name)
        Specified by:
        getProperty in interface javax.xml.stream.XMLEventReader
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<java.lang.Object>
        Specified by:
        hasNext in interface javax.xml.stream.XMLEventReader
      • nextEvent

        public javax.xml.stream.events.XMLEvent nextEvent()
                                                   throws javax.xml.stream.XMLStreamException
        Specified by:
        nextEvent in interface javax.xml.stream.XMLEventReader
        Throws:
        javax.xml.stream.XMLStreamException
      • next

        public java.lang.Object next()
        Specified by:
        next in interface java.util.Iterator<java.lang.Object>
      • nextTag

        public javax.xml.stream.events.XMLEvent nextTag()
                                                 throws javax.xml.stream.XMLStreamException
        Specified by:
        nextTag in interface javax.xml.stream.XMLEventReader
        Throws:
        javax.xml.stream.XMLStreamException
      • peek

        public javax.xml.stream.events.XMLEvent peek()
                                              throws javax.xml.stream.XMLStreamException
        Specified by:
        peek in interface javax.xml.stream.XMLEventReader
        Throws:
        javax.xml.stream.XMLStreamException
      • remove

        public void remove()
        Note: only here because we implement Iterator interface.
        Specified by:
        remove in interface java.util.Iterator<java.lang.Object>
      • hasNextEvent

        public boolean hasNextEvent()
                             throws javax.xml.stream.XMLStreamException
        Description copied from interface: XMLEventReader2
        Method that is similar to XMLEventReader.hasNext(), except that it can throw a XMLStreamException. This is important distinction, since the underlying stream reader is NOT allowed to throw such an exception when its hasNext() gets called; but the underlying parser may well need to advance the input stream and in doing so may encounter an exception. This exception should be propagated to the caller, as it may signal a problem with the input stream or xml content.
        Specified by:
        hasNextEvent in interface XMLEventReader2
        Throws:
        javax.xml.stream.XMLStreamException
      • isPropertySupported

        public boolean isPropertySupported​(java.lang.String name)
        Description copied from interface: XMLEventReader2
        Method similar to XMLInputFactory.isPropertySupported(java.lang.String), used to determine whether a property is supported by the Reader instance. This means that this method may return false for some properties that the input factory does support: specifically, it should only return true if the value is mutable on per-instance basis. False means that either the property is not recognized, or is not mutable via reader instance.
        Specified by:
        isPropertySupported in interface XMLEventReader2
      • setProperty

        public boolean setProperty​(java.lang.String name,
                                   java.lang.Object value)
        Description copied from interface: XMLEventReader2
        Method that can be used to set per-reader properties; a subset of properties one can set via matching XMLInputFactory2 instance. Exactly which methods are mutable is implementation specific.
        Specified by:
        setProperty in interface XMLEventReader2
        Parameters:
        name - Name of the property to set
        value - Value to set property to.
        Returns:
        True, if the specified property was succesfully set to specified value; false if its value was not changed