Package org.exolab.castor.xml
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 java.lang.Object implements SAX2EventAndErrorProducer
This provides shared code forSax2EventFromStaxEventProducer
andSax2EventFromStaxStreamProducer
. It consumes StAX events and produces SAX2 events.- Author:
- Philipp Erlacher
-
-
Constructor Summary
Constructors Constructor Description BaseSax2EventFromStaxProducer()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 {@link 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 stringjava.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 aLocator
to a givenLocation
.(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()
InvokehandleDocumentLocator()
and {@link 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 tovoid
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
-
-
-
-
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 interfaceSAX2EventProducer
-
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 interfaceSAX2EventAndErrorProducer
-
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 typedepth
- The current depth of the element- Returns:
- depth The updated depth
- Throws:
org.xml.sax.SAXException
-
handleStartDocument
void handleStartDocument() throws org.xml.sax.SAXException
InvokehandleDocumentLocator()
and {@link getContentHandler().startDocument()};- Throws:
org.xml.sax.SAXException
-
handleEndDocument
void handleEndDocument() throws org.xml.sax.SAXException
Handles a end document event.Invoke {@link getContentHandler().endDocument()};
- Throws:
org.xml.sax.SAXException
-
handleStartElement
void handleStartElement() throws org.xml.sax.SAXException
Handles a start element event.Invoke
doStartPrefixMapping()
and {@link getContentHandler().startElement()};- Throws:
org.xml.sax.SAXException
-
handleEndElement
void handleEndElement() throws org.xml.sax.SAXException
Handles an end element event.Invoke {@link 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 {@link 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 offsetlength
-- 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 {@link 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 aLocator
to a givenLocation
.- Parameters:
location
- ALocation
- Returns:
- A
Locator
-
-