org.jabber.jabberbeans.sax
Class PacketSubHandler

java.lang.Object
  |
  +--org.jabber.jabberbeans.sax.SubHandler
        |
        +--org.jabber.jabberbeans.sax.PacketSubHandler
All Implemented Interfaces:
DocumentHandler
Direct Known Subclasses:
InfoQueryHandler, MessageHandler, PresenceHandler, RouteHandler, XDB12Handler, XDBHandler

public abstract class PacketSubHandler
extends SubHandler

PacketSubHandler, which provides a framework to subclass for handling base packet types.


Field Summary
protected  PacketBuilder builder
          Builder class for packet types
protected  java.lang.StringBuffer elementChars
          Buffer for holding characters between elements.
 
Constructor Summary
PacketSubHandler()
          Construct a new PacketSubHandler class.Derived in subclasses.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Report data characters seen by parser.
protected  void handleEndElement(java.lang.String name)
          This is an exact copy of the end element in the main handler
protected  void handleStartElement(java.lang.String name, AttributeList attributes)
          This is an exact copy of the start element in the main handler.
protected  void packetEndElement(java.lang.String name)
          handleEndElement is a wrapper to let a class derived from this class handle custom element types.
protected  boolean packetStartElement(java.lang.String name, AttributeList attributes)
          packetStartElement is a method for handling additional element types not defined in the base packet type.
protected  void packetStartHandler(java.lang.String name, AttributeList attributes)
          packetStartHandler is overloaded by subclasses to initialize additional attributes.
protected  void receiveChildData(SubHandler subhandler, java.lang.Object data)
          called when a child object returns data (via its stopHandler() method)
protected  void startHandler(java.lang.String name, AttributeList attributes)
          startHandler is called on the first element handled by the class.
protected  java.lang.Object stopHandler(java.lang.String name)
          called as the handler is losing scope, to return any data it has created based on the XML it has been fed.
 
Methods inherited from class org.jabber.jabberbeans.sax.SubHandler
endDocument, endElement, getHandlerFactory, getSubCount, graftParent, graftSubHandler, ignorableWhitespace, processingInstruction, setChildSubHandler, setDocumentLocator, setHandlerFactory, setParent, setParser, startDocument, startElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

builder

protected PacketBuilder builder
Builder class for packet types


elementChars

protected java.lang.StringBuffer elementChars
Buffer for holding characters between elements. The only reason a stringbuffer is used is that most parsers will divide character() events by entities. i.e. "I can't make it tonite 'ok?'" would result in: "I can" , "'" , "t make it tonight " , "'" , "ok?" , "'"

Constructor Detail

PacketSubHandler

public PacketSubHandler()
Construct a new PacketSubHandler class.Derived in subclasses.

Method Detail

handleStartElement

protected final void handleStartElement(java.lang.String name,
                                        AttributeList attributes)
                                 throws SAXException
This is an exact copy of the start element in the main handler.

Overrides:
handleStartElement in class SubHandler
Parameters:
name - string that holds the element name
attributes - AttributeList of attributes going with this element
Throws:
SAXException - thrown on error (unexpected element)

packetStartElement

protected boolean packetStartElement(java.lang.String name,
                                     AttributeList attributes)
                              throws SAXException
packetStartElement is a method for handling additional element types not defined in the base packet type. It is addElement after being filtered.

Returns:
a boolean value of false if the tag should be referred to the extension factory. Basically a 'handled' bit.
Throws:
SAXException - if an error occurs

startHandler

protected final void startHandler(java.lang.String name,
                                  AttributeList attributes)
                           throws SAXException
startHandler is called on the first element handled by the class. This implementation sets up the builder, clears the element character cache, and parsers attributes to pull in the base attribute data.

Overrides:
startHandler in class SubHandler
Parameters:
name - element name
attributes - list of attributes
SAXException

packetStartHandler

protected void packetStartHandler(java.lang.String name,
                                  AttributeList attributes)
packetStartHandler is overloaded by subclasses to initialize additional attributes.

Parameters:
name - a String value
attributes - an AttributeList value

characters

public final void characters(char[] ch,
                             int start,
                             int length)
                      throws SAXException
Report data characters seen by parser. This implementation appends the data to the end of a StringBuffer

Specified by:
characters in interface DocumentHandler
Overrides:
characters in class SubHandler
Parameters:
ch - character array
start - offset into character array
length - lenght of characters to pull from array
Throws:
SAXException - thrown on error

handleEndElement

protected final void handleEndElement(java.lang.String name)
                               throws SAXException
This is an exact copy of the end element in the main handler

Overrides:
handleEndElement in class SubHandler
Parameters:
name - string holding the element name
Throws:
SAXException - thrown on error

packetEndElement

protected void packetEndElement(java.lang.String name)
                         throws SAXException
handleEndElement is a wrapper to let a class derived from this class handle custom element types.

Parameters:
name - a String value holding the element name
Throws:
SAXException - if an error occurs

stopHandler

protected final java.lang.Object stopHandler(java.lang.String name)
                                      throws SAXException
called as the handler is losing scope, to return any data it has created based on the XML it has been fed.

Overrides:
stopHandler in class SubHandler
Parameters:
name - element name
Returns:
Object with whatever relevant data. It is assumed that the parent will know what subclass the child data is in
Throws:
SAXException - in the event of XML parsing errors, or errors detected in the building process for creating the child data.

receiveChildData

protected final void receiveChildData(SubHandler subhandler,
                                      java.lang.Object data)
called when a child object returns data (via its stopHandler() method)

Overrides:
receiveChildData in class SubHandler
Parameters:
subhandler - SubHandler which is returning data
data - Object being returned (parent is assumed to know how to subclass because it created the child)