Class BaseSax2EventFromStaxProducer

java.lang.Object
org.exolab.castor.xml.BaseSax2EventFromStaxProducer
All Implemented Interfaces:
SAX2EventAndErrorProducer, SAX2EventProducer
Direct Known Subclasses:
Sax2EventFromStaxEventProducer, Sax2EventFromStaxStreamProducer

public abstract class BaseSax2EventFromStaxProducer extends Object implements SAX2EventAndErrorProducer
This provides shared code for Sax2EventFromStaxEventProducer and Sax2EventFromStaxStreamProducer. It consumes StAX events and produces SAX2 events.
Author:
Philipp Erlacher
  • Constructor Details

    • BaseSax2EventFromStaxProducer

      public BaseSax2EventFromStaxProducer()
  • Method Details

    • createSax2EventFromStax

      public static SAX2EventAndErrorProducer createSax2EventFromStax(XMLStreamReader streamReader)
    • createSax2EventFromStax

      public static SAX2EventAndErrorProducer createSax2EventFromStax(XMLEventReader eventReader)
    • setContentHandler

      public void setContentHandler(ContentHandler contentHandler)
      Description copied from interface: SAX2EventProducer
      Sets the SAX2 ContentHandler to send SAX 2 events to
      Specified by:
      setContentHandler in interface SAX2EventProducer
    • setErrorHandler

      public void setErrorHandler(ErrorHandler errorHandler)
      Description copied from interface: SAX2EventAndErrorProducer
      Sets the SAX2 ErrorHandler to send SAX 2 errors to
      Specified by:
      setErrorHandler in interface SAX2EventAndErrorProducer
    • getPrefixes

      public Stack<List<String>> getPrefixes()
    • getContentHandler

      public ContentHandler getContentHandler()
    • getErrorHandler

      public ErrorHandler getErrorHandler()
    • handleEventType

      int handleEventType(int eventType, int depth) throws SAXException
      This method takes an eventType and invokes a method to handle that event.

      It also takes information about the depth of the read element. Maybe depth changes due to handling that event.

      Parameters:
      eventType - The event type
      depth - The current depth of the element
      Returns:
      depth The updated depth
      Throws:
      SAXException
    • handleStartDocument

      void handleStartDocument() throws SAXException
      Invoke handleDocumentLocator() and {@link getContentHandler().startDocument()};
      Throws:
      SAXException
    • handleEndDocument

      void handleEndDocument() throws SAXException
      Handles a end document event.

      Invoke {@link getContentHandler().endDocument()};

      Throws:
      SAXException
    • handleStartElement

      void handleStartElement() throws SAXException
      Handles a start element event.

      Invoke doStartPrefixMapping() and {@link getContentHandler().startElement()};

      Throws:
      SAXException
    • handleEndElement

      void handleEndElement() throws SAXException
      Handles an end element event.

      Invoke {@link getContentHandler().endElement()} and doEndPrefixMapping();

      Throws:
      SAXException
    • handleSpace

      void handleSpace() throws SAXException
      Handles a space event.
      Throws:
      SAXException
    • handleCharacters

      void handleCharacters() throws SAXException
      Handles a character event.

      If chars is ignorable whitespace {@link getContentHandler().ignorableWhitespace will be called. Otherwise {@link getContentHandler().characters()} will be called with characters(char[], 0, length)

      Throws:
      SAXException
    • getQName

      String getQName(String prefix, String localPart)
      Parameters:
      prefix -
      localPart -
      Returns:
      qName. If prefix length >=1 then it's like prefix:localPart, otherwise it's just the localPart
    • isIgnorableWhitespace

      boolean isIgnorableWhitespace(char[] chars, int start, int length)
      If a chars without leading and trailing whitespaces would be empty, this method returns true, otherwise false,
      Parameters:
      chars -
      start - the offset
      length -
      Returns:
    • getNonEmpty

      String getNonEmpty(String string)
      If string equals null this returns an empty string, otherwise it returns the string
      Parameters:
      string - the string to check
      Returns:
      a string. If string equals null this returns an empty string, otherwise it returns the string
    • getLocation

      abstract Location getLocation()
      Returns:
      a Location
    • getCharacters

      abstract char[] getCharacters()
      Returns:
      characters of the current event.
    • doStartPrefixMapping

      abstract void doStartPrefixMapping() throws SAXException
      For every declared namespace in the current event {@link getContentHandler().startPrefixMapping()} gets invoked.
      Throws:
      SAXException
    • doEndPrefixMapping

      abstract void doEndPrefixMapping() throws SAXException
      Throws:
      SAXException
    • getAttributes

      abstract Attributes getAttributes()
      Returns:
      attributes of the current event
    • getQName

      abstract QName getQName()
      Returns:
      QName of the current event
    • getSAXLocator

      protected Locator getSAXLocator(Location location)
      Gets a Locator to a given Location.
      Parameters:
      location - A Location
      Returns:
      A Locator