Class StAXEventAllocatorBase

  • All Implemented Interfaces:
    javax.xml.stream.util.XMLEventAllocator

    public class StAXEventAllocatorBase
    extends java.lang.Object
    implements javax.xml.stream.util.XMLEventAllocator
    allows a user to register a way to allocate events given an XMLStreamReader. The XMLEventAllocator can be set on an XMLInputFactory using the property "javax.xml.stream.allocator"

    This base class uses EventFactory to create events as recommended in the JavaDoc of XMLEventAllocator. However, creating new object per each event reduces performance. The implementation of EventReader therefore will set the Allocator to StAXEventAllocator which implements the Allocate methods without creating new objects.

    The spec for the first Allocate method states that it must NOT modify the state of the Reader while the second MAY. For consistency, both Allocate methods in this implementation will NOT modify the state.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) javax.xml.stream.XMLEventFactory factory  
    • Constructor Summary

      Constructors 
      Constructor Description
      StAXEventAllocatorBase()
      Creates a new instance of XMLEventAllocator
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addAttributes​(StartElementEvent event, javax.xml.stream.XMLStreamReader streamReader)  
      protected void addNamespaces​(EndElementEvent event, javax.xml.stream.XMLStreamReader streamReader)  
      protected void addNamespaces​(StartElementEvent event, javax.xml.stream.XMLStreamReader streamReader)  
      javax.xml.stream.events.XMLEvent allocate​(javax.xml.stream.XMLStreamReader streamReader)
      This method allocates an event given the current state of the XMLStreamReader.
      void allocate​(javax.xml.stream.XMLStreamReader streamReader, javax.xml.stream.util.XMLEventConsumer consumer)
      This method allocates an event or set of events given the current state of the XMLStreamReader and adds the event or set of events to the consumer that was passed in.
      (package private) javax.xml.stream.events.XMLEvent getXMLEvent​(javax.xml.stream.XMLStreamReader reader)  
      javax.xml.stream.util.XMLEventAllocator newInstance()
      This method creates an instance of the XMLEventAllocator.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • factory

        javax.xml.stream.XMLEventFactory factory
    • Constructor Detail

      • StAXEventAllocatorBase

        public StAXEventAllocatorBase()
        Creates a new instance of XMLEventAllocator
    • Method Detail

      • newInstance

        public javax.xml.stream.util.XMLEventAllocator newInstance()
        This method creates an instance of the XMLEventAllocator. This allows the XMLInputFactory to allocate a new instance per reader.
        Specified by:
        newInstance in interface javax.xml.stream.util.XMLEventAllocator
      • allocate

        public javax.xml.stream.events.XMLEvent allocate​(javax.xml.stream.XMLStreamReader streamReader)
                                                  throws javax.xml.stream.XMLStreamException
        This method allocates an event given the current state of the XMLStreamReader. If this XMLEventAllocator does not have a one-to-one mapping between reader state and events this method will return null.
        Specified by:
        allocate in interface javax.xml.stream.util.XMLEventAllocator
        Parameters:
        streamReader - The XMLStreamReader to allocate from
        Returns:
        the event corresponding to the current reader state
        Throws:
        javax.xml.stream.XMLStreamException
      • allocate

        public void allocate​(javax.xml.stream.XMLStreamReader streamReader,
                             javax.xml.stream.util.XMLEventConsumer consumer)
                      throws javax.xml.stream.XMLStreamException
        This method allocates an event or set of events given the current state of the XMLStreamReader and adds the event or set of events to the consumer that was passed in.
        Specified by:
        allocate in interface javax.xml.stream.util.XMLEventAllocator
        Parameters:
        streamReader - The XMLStreamReader to allocate from
        consumer - The XMLEventConsumer to add to.
        Throws:
        javax.xml.stream.XMLStreamException
      • getXMLEvent

        javax.xml.stream.events.XMLEvent getXMLEvent​(javax.xml.stream.XMLStreamReader reader)
      • addAttributes

        protected void addAttributes​(StartElementEvent event,
                                     javax.xml.stream.XMLStreamReader streamReader)
      • addNamespaces

        protected void addNamespaces​(StartElementEvent event,
                                     javax.xml.stream.XMLStreamReader streamReader)
      • addNamespaces

        protected void addNamespaces​(EndElementEvent event,
                                     javax.xml.stream.XMLStreamReader streamReader)