org.exolab.castor.xml
Class BaseSax2EventFromStaxProducer

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

public abstract class BaseSax2EventFromStaxProducer
extends java.lang.Object
implements SAX2EventAndErrorProducer

This provides shared code for Sax2EventFromStaxEventProducer and Sax2EventFromStaxStreamProducer. It consumes StAX events and produces SAX2 events.

Author:
Philipp Erlacher

Constructor Summary
BaseSax2EventFromStaxProducer()
           
 
Method Summary
static SAX2EventAndErrorProducer createSax2EventFromStax(javax.xml.stream.XMLEventReader eventReader)
           
static SAX2EventAndErrorProducer createSax2EventFromStax(javax.xml.stream.XMLStreamReader streamReader)
           
(package private) abstract  void doEndPrefixMapping()
           
(package private) abstract  void doStartPrefixMapping()
          For every declared namespace in the current event getContentHandler().startPrefixMapping() gets invoked.
(package private) abstract  org.xml.sax.Attributes getAttributes()
           
(package private) abstract  char[] getCharacters()
           
 org.xml.sax.ContentHandler getContentHandler()
           
 org.xml.sax.ErrorHandler getErrorHandler()
           
(package private) abstract  javax.xml.stream.Location getLocation()
           
(package private)  java.lang.String getNonEmpty(java.lang.String string)
          If string equals null this returns an empty string, otherwise it returns the string
 java.util.Stack<java.util.List<java.lang.String>> getPrefixes()
           
(package private) abstract  javax.xml.namespace.QName getQName()
           
(package private)  java.lang.String getQName(java.lang.String prefix, java.lang.String localPart)
           
protected  org.xml.sax.Locator getSAXLocator(javax.xml.stream.Location location)
          Gets a Locator to a given Location.
(package private)  void handleCharacters()
          Handles a character event.
(package private)  void handleEndDocument()
          Handles a end document event.
(package private)  void handleEndElement()
          Handles an end element event.
(package private)  int handleEventType(int eventType, int depth)
          This method takes an eventType and invokes a method to handle that event.
(package private)  void handleSpace()
          Handles a space event.
(package private)  void handleStartDocument()
          Invoke handleDocumentLocator() and getContentHandler().startDocument();
(package private)  void handleStartElement()
          Handles a start element event.
(package private)  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,
 void setContentHandler(org.xml.sax.ContentHandler contentHandler)
          Sets the SAX2 ContentHandler to send SAX 2 events to
 void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
          Sets the SAX2 ErrorHandler to send SAX 2 errors to
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.exolab.castor.xml.SAX2EventProducer
start
 

Constructor Detail

BaseSax2EventFromStaxProducer

public BaseSax2EventFromStaxProducer()
Method Detail

createSax2EventFromStax

public static SAX2EventAndErrorProducer createSax2EventFromStax(javax.xml.stream.XMLStreamReader streamReader)

createSax2EventFromStax

public static SAX2EventAndErrorProducer createSax2EventFromStax(javax.xml.stream.XMLEventReader eventReader)

setContentHandler

public void setContentHandler(org.xml.sax.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(org.xml.sax.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 java.util.Stack<java.util.List<java.lang.String>> getPrefixes()

getContentHandler

public org.xml.sax.ContentHandler getContentHandler()

getErrorHandler

public org.xml.sax.ErrorHandler getErrorHandler()

handleEventType

int handleEventType(int eventType,
                    int depth)
              throws org.xml.sax.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:
org.xml.sax.SAXException

handleStartDocument

void handleStartDocument()
                   throws org.xml.sax.SAXException
Invoke handleDocumentLocator() and getContentHandler().startDocument();

Throws:
org.xml.sax.SAXException

handleEndDocument

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

Invoke getContentHandler().endDocument();

Throws:
org.xml.sax.SAXException

handleStartElement

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

Invoke doStartPrefixMapping() and getContentHandler().startElement();

Throws:
org.xml.sax.SAXException

handleEndElement

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

Invoke getContentHandler().endElement() and doEndPrefixMapping();

Throws:
org.xml.sax.SAXException

handleSpace

void handleSpace()
           throws org.xml.sax.SAXException
Handles a space event.

Throws:
org.xml.sax.SAXException

handleCharacters

void handleCharacters()
                throws org.xml.sax.SAXException
Handles a character event.

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

Throws:
org.xml.sax.SAXException

getQName

java.lang.String getQName(java.lang.String prefix,
                          java.lang.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

java.lang.String getNonEmpty(java.lang.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 javax.xml.stream.Location getLocation()
Returns:
a Location

getCharacters

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

doStartPrefixMapping

abstract void doStartPrefixMapping()
                            throws org.xml.sax.SAXException
For every declared namespace in the current event getContentHandler().startPrefixMapping() gets invoked.

Throws:
org.xml.sax.SAXException

doEndPrefixMapping

abstract void doEndPrefixMapping()
                          throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

getAttributes

abstract org.xml.sax.Attributes getAttributes()
Returns:
attributes of the current event

getQName

abstract javax.xml.namespace.QName getQName()
Returns:
QName of the current event

getSAXLocator

protected org.xml.sax.Locator getSAXLocator(javax.xml.stream.Location location)
Gets a Locator to a given Location.

Parameters:
location - A Location
Returns:
A Locator


Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com