net.sf.stax
Class StringElementHandler

java.lang.Object
  extended by net.sf.stax.StAXContentHandlerBase
      extended by net.sf.stax.StringElementHandler
All Implemented Interfaces:
StAXContentHandler

public class StringElementHandler
extends StAXContentHandlerBase

StAX handler for any element which just contains a string. The boolean value, returned by the endTree(StAXContext) method, is available to a parent handler via its endElement(String, String, String, Object, StAXContext) method.

Ex.

 class MyHandler
     extends StAXContentHandlerBase
 {
     private String stringValue;
     private StringElementHandler stringHandler = new StringElementHandler();

     public void startElement(..., StAXDelegationContext dctx)
     {
         // ...
         dctx.delegate(stringHandler);
     }

     public void endElement(..., Object result, ...)
     {
         this.stringValue = (String) result;
     }
 }
 

This class also supports mixed content models by subclassing and overriding the startChildElement(String, String, String, Attributes, StAXDelegationContext) method. By default, this class throws an exception if it sees a child element.

Version:
$Revision: 1.6 $ $Date: 2006/01/02 20:37:34 $
Author:
Matthew Pocock, Thomas Down, Michael Heuer
See Also:
startChildElement(String, String, String, Attributes, StAXDelegationContext), StAXContentHandlers.getStringElementHandler()

Field Summary
 
Fields inherited from interface net.sf.stax.StAXContentHandler
IGNORE
 
Constructor Summary
StringElementHandler()
           
 
Method Summary
 void characters(char[] ch, int start, int length, StAXContext ctx)
          Receive notification of character data.
 void endElement(String nsURI, String localName, String qName, Object result, StAXContext ctx)
          Receive notification of the end of an element.
 Object endTree(StAXContext ctx)
          Receive notification of the end of a sub-tree of a document.
protected  void startChildElement(String nsURI, String localName, String qName, Attributes attrs, StAXDelegationContext dctx)
          Handle any child elements found.
 void startElement(String nsURI, String localName, String qName, Attributes attrs, StAXDelegationContext dctx)
          Receive notification of the beginning of an element.
 
Methods inherited from class net.sf.stax.StAXContentHandlerBase
endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startPrefixMapping, startTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringElementHandler

public StringElementHandler()
Method Detail

startElement

public final void startElement(String nsURI,
                               String localName,
                               String qName,
                               Attributes attrs,
                               StAXDelegationContext dctx)
                        throws SAXException
Description copied from interface: StAXContentHandler
Receive notification of the beginning of an element.

Specified by:
startElement in interface StAXContentHandler
Overrides:
startElement in class StAXContentHandlerBase
Parameters:
nsURI - namespace URI
localName - local name (without prefix)
qName - qualified XML name (with prefix)
attrs - attributes attached to the element
dctx - StAX delegation context
Throws:
SAXException - any SAX exception, possibly wrapping another exception
See Also:
StAXContentHandler

endElement

public void endElement(String nsURI,
                       String localName,
                       String qName,
                       Object result,
                       StAXContext ctx)
                throws SAXException
Description copied from interface: StAXContentHandler
Receive notification of the end of an element.

Specified by:
endElement in interface StAXContentHandler
Overrides:
endElement in class StAXContentHandlerBase
Parameters:
nsURI - namespace URI
localName - local name (without prefix)
qName - qualified XML name (with prefix)
result - result
ctx - StAX context
Throws:
SAXException - any SAX exception, possibly wrapping another exception
See Also:
StAXContentHandler

startChildElement

protected void startChildElement(String nsURI,
                                 String localName,
                                 String qName,
                                 Attributes attrs,
                                 StAXDelegationContext dctx)
                          throws SAXException
Handle any child elements found. By default, this throws an exception, but it may be overridden to handle mixed content models.

Parameters:
nsURI - namespace URI
localName - local name (without prefix)
qName - qualified XML name (with prefix)
attrs - attributes attached to the element
dctx - StAX delegation context
Throws:
SAXException - any SAX exception, possibly wrapping another exception

characters

public final void characters(char[] ch,
                             int start,
                             int length,
                             StAXContext ctx)
                      throws SAXException
Description copied from interface: StAXContentHandler
Receive notification of character data.

Specified by:
characters in interface StAXContentHandler
Overrides:
characters in class StAXContentHandlerBase
Parameters:
ch - characters from the XML document
start - start position in the array
length - number of characters to read from the array
ctx - StAX context
Throws:
SAXException - any SAX exception, possibly wrapping another exception
See Also:
StAXContentHandler

endTree

public final Object endTree(StAXContext ctx)
                     throws SAXException
Description copied from interface: StAXContentHandler
Receive notification of the end of a sub-tree of a document.

Specified by:
endTree in interface StAXContentHandler
Overrides:
endTree in class StAXContentHandlerBase
Parameters:
ctx - StAX context
Returns:
return value
Throws:
SAXException - any SAX exception, possibly wrapping another exception
See Also:
StAXContentHandler


Copyright (c) 2001-2006 held jointly by the individual authors. Licensed under the GNU Lesser General Public License (LGPL).