|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | 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.
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 |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SubHandler()
SubHandler
instance.
Method Detail |
public final void startDocument() throws SAXException
startDocument
in interface DocumentHandler
SAXException
- Any SAX exception, possibly
wrapping another exception.public final void endDocument() throws SAXException
endDocument
in interface DocumentHandler
SAXException
- Any SAX exception, possibly
wrapping another exception.public final void processingInstruction(java.lang.String target, java.lang.String data) throws SAXException
processingInstruction
in interface DocumentHandler
target
- The processing instruction target.data
- The processing instruction data, or null if
none was supplied.
SAXException
- Any SAX exception, possibly
wrapping another exception.public final void setDocumentLocator(Locator locator)
setDocumentLocator
in interface DocumentHandler
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
startElement
in interface DocumentHandler
name
- string that holds the element nameattributes
- AttributeList of attributes going with this element
SAXException
- thrown on error (unexpected element)
SAXException
- Any SAX exception, possibly
wrapping another exception.DocumentHandler.endElement(java.lang.String)
,
AttributeList
public final void endElement(java.lang.String name) throws SAXException
endElement
in interface DocumentHandler
name
- string holding the element name
SAXException
- thrown on error
SAXException
- Any SAX exception, possibly
wrapping another exception.public void characters(char[] ch, int start, int length) throws SAXException
characters
in interface DocumentHandler
ch
- character string detectedstart
- start positionlength
- length of string
SAXException
- thrown on error
SAXException
- Any SAX exception, possibly
wrapping another exception.DocumentHandler.ignorableWhitespace(char[], int, int)
,
Locator
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
DocumentHandler
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.
ignorableWhitespace
in interface DocumentHandler
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.
SAXException
- Any SAX exception, possibly
wrapping another exception.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 element
SAXException
protected 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
value
SAXException
- if an error occursprotected 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
value
SAXException
- if an error occursprotected java.lang.Object stopHandler(java.lang.String name) throws SAXException
SAXException
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
value
SAXException
- if there is an error in the returned datapublic final void setParser(Parser newParser)
setParser
is used to set the SAX parser from the parent
newParser
- 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 parent
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
value
SAXException
- if an error occursprotected 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
value
SAXException
- if an error occursprotected 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)
SAXException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |