|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jabber.jabberbeans.sax.SubHandler
Subhandlers are registered with the main document handler to handle all data within an element with a specific name.
The basic idea is that a subhandler is built 'around' an element, so that handing a particular type of packet in jabber is the responsibility of different objects. For instance, PresenceHandler, MessageHandler, IQHandler.
The handler is constructed with the attribute list of the element, and is stopped (via stopHandler) when the element is closed. In between these two events, we get all the subelements and characters in the stream.
Field Summary | |
private HandlerFactory |
handlerFactory
handlerFactory, passed from parent |
private SubHandler |
parent
parent SubHandler, which we return to after endHandler |
private Parser |
parser
SAX parser being used, passed from parent |
private byte |
subCount
internal counter for doing start/endHandler methods. |
Constructor Summary | |
SubHandler()
Creates a new SubHandler instance. |
Method Summary | |
void |
characters(char[] ch,
int start,
int length)
This is an exact copy of the characters function in the main handler |
void |
endDocument()
do-nothing implementation |
void |
endElement(java.lang.String name)
This is an exact copy of the end element in the main handler |
HandlerFactory |
getHandlerFactory()
getHandlerFactory is used to get the
HandlerFactory used to look up elements and namespace
extension handlers. |
protected byte |
getSubCount()
getSubCount returns the element level (the number of tags
deep the parser is in within the SubHandler, not globally) |
protected void |
graftParent(java.lang.String name)
graftParent is yet another ugly hack in the graft
series, which allows for XMLStreamHeader to be interpreted as
a packet instead of a new level. |
protected void |
graftSubHandler(SubHandler subHandler,
java.lang.String name,
AttributeList attributes)
graftSubHandler is ssimilar to setChildSubHandler,
except in that we are not specifying a handler for child tags, but
actually one for the current sub-level. |
protected void |
handleEndElement(java.lang.String name)
handleEndElement is overloaded by the new class to
provide logic to handle element code. |
protected void |
handleStartElement(java.lang.String name,
AttributeList attributes)
handleStartElement is overloaded by the new class to
provide logic to handle the element code. |
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Receive notification of ignorable whitespace in element content. |
void |
processingInstruction(java.lang.String target,
java.lang.String data)
do-nothing implementation |
protected void |
receiveChildData(SubHandler subHandler,
java.lang.Object o)
receiveChildData is called when a child handler exits,
returning control to this code. |
protected void |
setChildSubHandler(SubHandler subHandler,
java.lang.String name,
AttributeList attributes)
setChildSubHandler is called to hook up a new subHandler
to take over parsing the data stream, for instance in the case of
a new Extension handler. |
void |
setDocumentLocator(Locator locator)
do-nothing implementation |
void |
setHandlerFactory(HandlerFactory hf)
setHandlerFactory is used to set the
HandlerFactory used to look up elements and namespace
extension handlers. |
void |
setParent(SubHandler handler)
setParent is used to set the parent object (from
the parent) |
void |
setParser(Parser newParser)
setParser is used to set the SAX parser from the parent |
void |
startDocument()
do-nothing implementation |
void |
startElement(java.lang.String name,
AttributeList attributes)
This is an exact copy of the start element in the main handler. |
protected void |
startHandler(java.lang.String name,
AttributeList attributes)
Gets called when the underlying engine decides to pass an entity and all sub-entities off to your subhandler. |
protected java.lang.Object |
stopHandler(java.lang.String name)
Stophandler is the same as end element, except that it is called saying that the subhandler is no longer in scope. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private byte subCount
private Parser parser
private SubHandler parent
private HandlerFactory handlerFactory
Constructor Detail |
public SubHandler()
SubHandler
instance.Method Detail |
public final void startDocument() throws SAXException
public final void endDocument() throws SAXException
public final void processingInstruction(java.lang.String target, java.lang.String data) throws SAXException
target
- The processing instruction target.data
- The processing instruction data, or null if
none was supplied.public final void setDocumentLocator(Locator locator)
locator
- An object that can return the location of
any SAX document event.Locator
public final void startElement(java.lang.String name, AttributeList attributes) throws SAXException
name
- string that holds the element nameattributes
- AttributeList of attributes going with this elementpublic final void endElement(java.lang.String name) throws SAXException
name
- string holding the element namepublic void characters(char[] ch, int start, int length) throws SAXException
ch
- character string detectedstart
- start positionlength
- length of stringpublic void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
Validating Parsers must use this method to report each chunk of ignorable whitespace (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.
SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.
The application must not attempt to read from the array outside of the specified range.
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.DocumentHandler.characters(char[], int, int)
protected void startHandler(java.lang.String name, AttributeList attributes) throws SAXException
Upon seeing the element that this subhandler handles, we call this constructor, passing in the attributes.
name
- name of the element which we are handling.attributes
- list of attributes on this elementprotected void handleStartElement(java.lang.String name, AttributeList attributes) throws SAXException
handleStartElement
is overloaded by the new class to
provide logic to handle the element code.name
- a String
valueattributes
- an AttributeList
valueprotected void handleEndElement(java.lang.String name) throws SAXException
handleEndElement
is overloaded by the new class to
provide logic to handle element code.name
- a String
valueprotected java.lang.Object stopHandler(java.lang.String name) throws SAXException
Object
- a value being returned to the parent - the parent is
meant to interpret this result.protected void receiveChildData(SubHandler subHandler, java.lang.Object o) throws SAXException
receiveChildData
is called when a child handler exits,
returning control to this code. The now-defunct handler along with the
data object are both returned.subHandler
- a SubHandler
valueo
- an Object
valuepublic final void setParser(Parser newParser)
setParser
is used to set the SAX parser from the parentnewParser
- a Parser
valuepublic final void setParent(SubHandler handler)
setParent
is used to set the parent object (from
the parent)handler
- SubHandler
which is this object's parentpublic final void setHandlerFactory(HandlerFactory hf)
setHandlerFactory
is used to set the
HandlerFactory used to look up elements and namespace
extension handlers. This is set from the parentehf
- HandlerFactory
public final HandlerFactory getHandlerFactory()
getHandlerFactory
is used to get the
HandlerFactory used to look up elements and namespace
extension handlers.HandlerFactory
protected final byte getSubCount()
getSubCount
returns the element level (the number of tags
deep the parser is in within the SubHandler, not globally)byte
valueprotected final void setChildSubHandler(SubHandler subHandler, java.lang.String name, AttributeList attributes) throws SAXException
setChildSubHandler
is called to hook up a new subHandler
to take over parsing the data stream, for instance in the case of
a new Extension handler.subHandler
- a SubHandler
valuename
- a String
valueattributes
- an AttributeList
valueprotected final void graftSubHandler(SubHandler subHandler, java.lang.String name, AttributeList attributes) throws SAXException
graftSubHandler
is ssimilar to setChildSubHandler,
except in that we are not specifying a handler for child tags, but
actually one for the current sub-level.
The startHandler will be passed no parameters - do not try to
use them.
When the subhandler finishes, you can write a method to receive
the child data, then call endElement yourself (with an appropriate
name for your own code) to exit the calling handler.subHandler
- a SubHandler
valuename
- a String
valueattributes
- an AttributeList
valueprotected final void graftParent(java.lang.String name) throws SAXException
graftParent
is yet another ugly hack in the graft
series, which allows for XMLStreamHeader to be interpreted as
a packet instead of a new level. Without incrementing the parent's
count, the whole thing will go to the wrong level once the
parent exits, basically crashing the parser tree. Ugh.
TODO: if XMLStreamDocumentHandler either parsed the headers itself
or was the parent of the current XMLStreamDocumentHandler, this
ugly hackedness would go away.name
- Name as would be passed to endElement if this was
the end of a packet (same as the name attrib in
a corresponding startElement)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |