Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.thermidor.xml
Class SAXParserBase  view SAXParserBase download SAXParserBase.java

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended bycom.thermidor.xml.SAXParserBase
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public abstract class SAXParserBase
extends org.xml.sax.helpers.DefaultHandler

The SAXParserBase class is a base is provided as a framework for the creation of XML content handlers. The framework captures some of the simplicities of using DOM while maintaing much of the power and efficently of the SAX API. The primary arena for the use of the SAXParserBase as a framework for XML processing is where XML documents have to be converted to in memory models. To put this an other way the XML is really an externalization of an 'object model'

Core to the conception of the SAXParserBase s the SAXEement class. This class in many ways is superficailly similar to the DOM node. On of the recurring issues with SAX programming is the maintence of context while parsing the document. The SAXParserBase does this by maintaining a stack of SAXElements, where each SAXElement instance corresponds to an encountered tag. When a tag is encountered it is pushed on to the stack and passed to the handleStartElement operation. As this context information is maintained on the stack the end elent can be retrieved from the top of the stack when the SAX event is recieved. At this time the element is poped from the stack and passed to the handleEndElement operation. Any PCDATA tat is found that is within the immediate context of the tag is added to the that element. There are a number of rules constraints that apply of the lifecycle of SAXElements as therey are dispatched to the handler operations. In the handleStartElement operation non of the PCDATA for a tag is availbel as the SAXEvent that corresponds to it has not yet been recieved by the SAXParserBase. . Whn the end tag is encounterd all attributes and PCDATA for the tag are availble. This is very different from the basic SAX API and is of considerable utility.

Virtually all content handlers that use the SAXParserBase as their base class follow a similar pattern. The following example illustrates this. It is common that the implementation of a SAXParserBase based content handler consists of two classes, and abstract parser, and its contrete implementation. The abstract parser extends the SAXParserBase to provide a token table and the implementation of the handleStartElement and handleEndElement operations. These two operations are dispathc functions that associate a lookup in the token table with an operation to handle eith the start of end of that element. In many ways each abstract parser is a specialization of the SAX parser paradigm that provides fine grain events for the start and end of tags for specific schemas or DTDs. In an abstract parser it is usual to define start and end events for all of the lements in the DTD or schema although it is not always necessary to provide real implemntations for all events.

For a detailed example of the implementation see the package-summary.html#package_description package documentation

Version:
1.0

Nested Class Summary
static class SAXParserBase.SAXElement
          The purpose of the SAXElement class is to provide an aggregation of the results if the SAX content handler event and a mechanism to manage the context state of tags as they are encountered.
 
Field Summary
private  java.util.LinkedList contextStack
          The stack of SAXelement instances that the SAXParserBase uses to maintain consttext within the event stream from the SAX parser.
private  org.xml.sax.EntityResolver delegateResolver
          The deleate eneity resolve to be used.
protected  org.xml.sax.XMLReader reader
          The reader associated with this ContentHandler, if any.
 
Constructor Summary
protected SAXParserBase()
          Default constructor, sets up a SAXWriter to filter and pretty print parsed XML to System.out if the log level is Priority.DEBUG.
 
Method Summary
private  void appendText(char[] ch, int start, int length)
          This utility operation is used within the SAXParserBAse to append character data to the top element of the stack.
 void characters(char[] ch, int start, int length)
          The characters operation is called by the SAX parsers to pass character data to the content handler.
protected  int depth()
          Return the depth in the parse.
 void endDocument()
          Overide of the endDocument operation in the DefaultHandler
 void endElement(java.lang.String uri, java.lang.String lname, java.lang.String qname)
          Overide of the endElement operation in the DefaultHandler
 void endPrefixMapping(java.lang.String prefix)
          Overide of the endPrefixMapping operation in the DefaultHandler
 void error(org.xml.sax.SAXParseException error)
          Overide of the error operation in the DefaultHandler
 void fatalError(org.xml.sax.SAXParseException fatal)
          Overide of the fatalError operation in the DefaultHandler
 org.xml.sax.XMLReader getReader()
          Get the value of reader.
protected abstract  void handleEndElement(SAXParserBase.SAXElement element)
          The handleEndElement operation is called by the SAXParserBase instance in response to a SAX event indicating that an end tag has been.
protected abstract  void handleStartElement(SAXParserBase.SAXElement element)
          The handleStartElement operation is called by the SAXPArserBase instance in response to a SAX event that indicates that a start tag has been encounterd.
 void ignorableWhitespace(char[] ch, int start, int len)
          Overide of the ignorableWhitespace operation in the DefaultHandler
static java.lang.String noEmptyValue(java.lang.String attribute, java.lang.String toCheck)
          Utility function to manage defined attribute where the value is the empty string.
 void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Overide of the notationDecl_ operation in the DefaultHandler
private  SAXParserBase.SAXElement pop()
          Pop the top SAXelement of the context stack.
 void processingInstruction(java.lang.String target, java.lang.String data)
          Overide of the processingInstruction operation in the DefaultHandler
private  void push(SAXParserBase.SAXElement element)
          Push the specified SAXElement instance onto the top of the context stack.
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          The reolveEntity operation overrides that resolveEntity operation on DefaultHandler.
 void setDelegateEntityResolver(org.xml.sax.EntityResolver er)
          Set the delegate enityt resolver that will be used to resolve entities
 void setDocumentLocator(org.xml.sax.Locator locator)
          Overide of the setDocumentLocator operation in the DefaultHandler
 void setReader(org.xml.sax.XMLReader v)
          Set the value of reader.
 void skippedEntity(java.lang.String name)
          Overide of the skippedEntity operation in the DefaultHandler
 void startDocument()
          Overide of the startDocument operation in the DefaultHandler
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qname, org.xml.sax.Attributes atts)
          Overide of the startElement operation in the DefaultHandler
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Overide of the startPrefixMapping operation in the DefaultHandler
 void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
          Overide of the unparsedEntityDecl operation in the DefaultHandler
 void warning(org.xml.sax.SAXParseException warning)
          Overide of the warning operation in the DefaultHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reader

protected org.xml.sax.XMLReader reader
The reader associated with this ContentHandler, if any. Used for chaining XMLFilters.


contextStack

private java.util.LinkedList contextStack
The stack of SAXelement instances that the SAXParserBase uses to maintain consttext within the event stream from the SAX parser.


delegateResolver

private org.xml.sax.EntityResolver delegateResolver
The deleate eneity resolve to be used. Optional.

Constructor Detail

SAXParserBase

protected SAXParserBase()
Default constructor, sets up a SAXWriter to filter and pretty print parsed XML to System.out if the log level is Priority.DEBUG.

Method Detail

getReader

public org.xml.sax.XMLReader getReader()
Get the value of reader.


setReader

public void setReader(org.xml.sax.XMLReader v)
Set the value of reader.


depth

protected int depth()
Return the depth in the parse.


appendText

private void appendText(char[] ch,
                        int start,
                        int length)
                 throws java.util.NoSuchElementException
This utility operation is used within the SAXParserBAse to append character data to the top element of the stack.


pop

private SAXParserBase.SAXElement pop()
                              throws java.util.NoSuchElementException
Pop the top SAXelement of the context stack.


push

private void push(SAXParserBase.SAXElement element)
Push the specified SAXElement instance onto the top of the context stack.


setDelegateEntityResolver

public void setDelegateEntityResolver(org.xml.sax.EntityResolver er)
Set the delegate enityt resolver that will be used to resolve entities


resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
                                      throws org.xml.sax.SAXException
The reolveEntity operation overrides that resolveEntity operation on DefaultHandler. The implementation of the operation delegates the delegateEntityResolver if one is defined otherwise it delegates to the super class implemetation of the operation.


notationDecl

public void notationDecl(java.lang.String name,
                         java.lang.String publicId,
                         java.lang.String systemId)
                  throws org.xml.sax.SAXException
Overide of the notationDecl_ operation in the DefaultHandler


unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId,
                               java.lang.String notationName)
                        throws org.xml.sax.SAXException
Overide of the unparsedEntityDecl operation in the DefaultHandler


setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Overide of the setDocumentLocator operation in the DefaultHandler


startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Overide of the startDocument operation in the DefaultHandler


endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Overide of the endDocument operation in the DefaultHandler


startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Overide of the startPrefixMapping operation in the DefaultHandler


endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
Overide of the endPrefixMapping operation in the DefaultHandler


startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qname,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Overide of the startElement operation in the DefaultHandler


endElement

public void endElement(java.lang.String uri,
                       java.lang.String lname,
                       java.lang.String qname)
                throws org.xml.sax.SAXException
Overide of the endElement operation in the DefaultHandler


characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
The characters operation is called by the SAX parsers to pass character data to the content handler. In this case the operation appends the test to the SAXElement that represents the current parsing context.


ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int len)
                         throws org.xml.sax.SAXException
Overide of the ignorableWhitespace operation in the DefaultHandler


processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Overide of the processingInstruction operation in the DefaultHandler


skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Overide of the skippedEntity operation in the DefaultHandler


warning

public void warning(org.xml.sax.SAXParseException warning)
             throws org.xml.sax.SAXException
Overide of the warning operation in the DefaultHandler


error

public void error(org.xml.sax.SAXParseException error)
           throws org.xml.sax.SAXException
Overide of the error operation in the DefaultHandler


fatalError

public void fatalError(org.xml.sax.SAXParseException fatal)
                throws org.xml.sax.SAXException
Overide of the fatalError operation in the DefaultHandler


handleStartElement

protected abstract void handleStartElement(SAXParserBase.SAXElement element)
                                    throws org.xml.sax.SAXException
The handleStartElement operation is called by the SAXPArserBase instance in response to a SAX event that indicates that a start tag has been encounterd. The SAXParserBase instance will have constructed a SAXElement instance that encapsulates the start state of the element and pushed it onto the context stack prior to passing it to this operation. It should be remembered that any PCDATA content associated with a tag will not be available until the end tag has been reached. This operation should be implemented by a conrete parser instance.


handleEndElement

protected abstract void handleEndElement(SAXParserBase.SAXElement element)
                                  throws org.xml.sax.SAXException
The handleEndElement operation is called by the SAXParserBase instance in response to a SAX event indicating that an end tag has been. The SAXParserBase instance will have recovered the appropriate SAXElement instance for this tag from its context stack before calling this operation. Then this operation is called all nested tags will have been processed and any PCDATA contained in the tag will be associated with the SAXElement instance for that tag. This operation should be implemented by a concrete instance of the parser.


noEmptyValue

public static java.lang.String noEmptyValue(java.lang.String attribute,
                                            java.lang.String toCheck)
                                     throws EmptyAttributeException
Utility function to manage defined attribute where the value is the empty string.