edu.mit.jverbnet.util.parse
Class LazyForwardingHandler<T>

java.lang.Object
  extended by edu.mit.jverbnet.util.parse.LazyForwardingHandler<T>
All Implemented Interfaces:
IHasParserHandler, ITaggedHandler<T>, org.xml.sax.ContentHandler

public abstract class LazyForwardingHandler<T>
extends java.lang.Object
implements ITaggedHandler<T>

A handler that does not instantiate its backing handler until the backing handler is actually needed. This class is useful for handling potentially infinitely recursive XML structures.

Since:
JVerbnet 1.0.0
Version:
1.2.0
Author:
Mark A. Finlayson

Nested Class Summary
protected  class LazyForwardingHandler.ForwardingTaskList
          This task list keeps track of tasks before the backing handler is instantiated.
 
Constructor Summary
LazyForwardingHandler(IHasParserHandler parent, java.lang.String tag)
          Creates a new lazy forwarding handler with the specified parent and tag.
LazyForwardingHandler(java.lang.String tag)
          Creates a new lazy forwarding handler that uses the specified tag.
LazyForwardingHandler(org.xml.sax.XMLReader parser, org.xml.sax.ContentHandler parent, java.lang.String tag)
          Creates a new lazy forwarding handler with the specified parser, parent and tag.
LazyForwardingHandler(org.xml.sax.XMLReader parser, java.lang.String tag)
          Creates a new lazy forwarding handler with the specified parser and tag.
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void clear()
          Clears the state of the handler.
protected abstract  ITaggedHandler<T> createBackingHandler()
          Subclasses should implement this method to create the backing handler.
 void endDocument()
           
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
           
 void endPrefixMapping(java.lang.String prefix)
           
 ITaggedHandler<T> getBackingHandler()
          Returns the backing handler, instantiating it if necessary.
 T getElement()
          Returns the object representing the data in the parsed tagged block.
 org.xml.sax.ContentHandler getParent()
          Returns the parent of this child handler.
 org.xml.sax.XMLReader getParser()
          Returns the parser for this handler.
 java.lang.String getTag()
          Returns the tag that is handled by this handler.
 java.util.List<ITaggedBlockTaskHandler> getTaggedBlockTasks()
          Returns the list of task handlers that are run when the tagged block is entered and exited.
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void processingInstruction(java.lang.String target, java.lang.String data)
           
 void setDocumentLocator(org.xml.sax.Locator locator)
           
 void setParent(org.xml.sax.ContentHandler parent)
          Sets the parent for this handler.
 void setParser(org.xml.sax.XMLReader parser)
          Sets the parser for this handler; may be set to null
 void skippedEntity(java.lang.String name)
           
 void startDocument()
           
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
           
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LazyForwardingHandler

public LazyForwardingHandler(java.lang.String tag)
Creates a new lazy forwarding handler that uses the specified tag.

Parameters:
tag - the tag for the block that this handler handles; may not be null, empty, or all whitespace.
Throws:
java.lang.NullPointerException - if the specified tag is null
java.lang.IllegalArgumentException - if the specified tag is empty or all whitespace
Since:
JVerbnet 1.0.0

LazyForwardingHandler

public LazyForwardingHandler(org.xml.sax.XMLReader parser,
                             java.lang.String tag)
Creates a new lazy forwarding handler with the specified parser and tag.

Parameters:
parser - the parser for this handler; may be null
tag - the tag for the block that this handler handles; may not be null, empty, or all whitespace.
Throws:
java.lang.NullPointerException - if the specified tag is null
java.lang.IllegalArgumentException - if the specified tag is empty or all whitespace
Since:
JVerbnet 1.0.0

LazyForwardingHandler

public LazyForwardingHandler(IHasParserHandler parent,
                             java.lang.String tag)
Creates a new lazy forwarding handler with the specified parent and tag.

Parameters:
parent - this handler's parent; may be null
tag - the tag for the block that this handler handles; may not be null, empty, or all whitespace.
Throws:
java.lang.NullPointerException - if the specified tag is null
java.lang.IllegalArgumentException - if the specified tag is empty or all whitespace
Since:
JVerbnet 1.0.0

LazyForwardingHandler

public LazyForwardingHandler(org.xml.sax.XMLReader parser,
                             org.xml.sax.ContentHandler parent,
                             java.lang.String tag)
Creates a new lazy forwarding handler with the specified parser, parent and tag.

Parameters:
parser - the parser for this handler; may be null
parent - this handler's parent; may be null
tag - the tag for the block that this handler handles; may not be null, empty, or all whitespace.
Throws:
java.lang.NullPointerException - if the specified tag is null
java.lang.IllegalArgumentException - if the specified tag is empty or all whitespace
Since:
JVerbnet 1.0.0
Method Detail

getBackingHandler

public final ITaggedHandler<T> getBackingHandler()
Returns the backing handler, instantiating it if necessary. This method is thread safe.

Returns:
the backing handler
Since:
JVerbnet 1.0.0

createBackingHandler

protected abstract ITaggedHandler<T> createBackingHandler()
Subclasses should implement this method to create the backing handler. The backing handler should have the same tag as the forwarding handler.

Returns:
a new instance of the backing handler
Since:
JVerbnet 1.0.0

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler

getParser

public org.xml.sax.XMLReader getParser()
Description copied from interface: IHasParserHandler
Returns the parser for this handler. May return null.

Specified by:
getParser in interface IHasParserHandler
Returns:
the possibly null parser for this handler

setParser

public void setParser(org.xml.sax.XMLReader parser)
Description copied from interface: IHasParserHandler
Sets the parser for this handler; may be set to null

Specified by:
setParser in interface IHasParserHandler
Parameters:
parser - the new parser for this handler; may be null

getTag

public java.lang.String getTag()
Description copied from interface: ITaggedHandler
Returns the tag that is handled by this handler. Will never be null or empty, and will be trimmed of leading and trailing whitespace.

Specified by:
getTag in interface ITaggedHandler<T>
Returns:
the non-null, non-empty, trimmed tag that is handled by this handler

getParent

public org.xml.sax.ContentHandler getParent()
Description copied from interface: ITaggedHandler
Returns the parent of this child handler. If the handler has no parent, will return null.

Specified by:
getParent in interface ITaggedHandler<T>
Returns:
the possibly null parent of this child handler

setParent

public void setParent(org.xml.sax.ContentHandler parent)
Description copied from interface: ITaggedHandler
Sets the parent for this handler. The new parent may be null

Specified by:
setParent in interface ITaggedHandler<T>
Parameters:
parent - the new parent for the handler; may be null

getTaggedBlockTasks

public java.util.List<ITaggedBlockTaskHandler> getTaggedBlockTasks()
Description copied from interface: ITaggedHandler
Returns the list of task handlers that are run when the tagged block is entered and exited. The list may be modified. Tasks are run in order.

Specified by:
getTaggedBlockTasks in interface ITaggedHandler<T>
Returns:
the list of tasks to be run when entering and exiting the tagged block

clear

public void clear()
Description copied from interface: ITaggedHandler
Clears the state of the handler. This method should be called before control of the parser is passed to this handler.

Specified by:
clear in interface ITaggedHandler<T>

getElement

public T getElement()
Description copied from interface: ITaggedHandler
Returns the object representing the data in the parsed tagged block.

Specified by:
getElement in interface ITaggedHandler<T>
Returns:
the object representing the data in the parsed tagged block

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Specified by:
startDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Specified by:
endDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Specified by:
endElement in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Specified by:
characters in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException


Copyright © 2012 ${project.organization.name}. All Rights Reserved.