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

Quick Search    Search Deep

jbreport.core
Class DefaultXMLParseHandler  view DefaultXMLParseHandler download DefaultXMLParseHandler.java

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended byjbreport.core.DefaultXMLParseHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, XMLHandler

public class DefaultXMLParseHandler
extends org.xml.sax.helpers.DefaultHandler
implements XMLHandler

This is the default xml parser handling class. It is registered with the actual sax parser, and will receive the appropriate callbacks.

It should not know about concrete implementations of reporting elements, it should just make the appropriate calls to the ReportElementFactory instance.

The sequence of events when traversing the parse tree is the following.

  1. On startElement, see if the top node in the stack knows how to deal with its own children,
    • [it does] then pass the element type, attributes and cdata to the top stack node while still in this node.
    • [it does not] then try to create the appropriate class using the ReportElementFactory instance.
  2. Initialise the element with the type and attributes
  3. Collect any cdata before the endElement method
  4. On endElement, pass the cdata to the element, call end() on the element, endChild() on the parent, and pop the element off the stack.

Version:
$Revision: 1.1 $

Field Summary
private static java.util.ResourceBundle bundle
          The bundle of resources that provide default settings to the parser, and also determine which parser will be used.
private  java.lang.StringBuffer cdata
          The current cdata that exists for this element
private  jbreport.ReportElementFactory factory
          The factory instance that will create the concrete element instances.
private static org.xml.sax.XMLReader reader
          The current XML parser.
private  jbreport.util.Stack stack
          The stack that is used to determine the current state of parsing.
 
Constructor Summary
private DefaultXMLParseHandler()
           
 
Method Summary
 void characters(char[] ch, int start, int length)
          Receive notification of character data inside an element.
private static org.xml.sax.XMLReader createNewReader()
          This will create a new reader.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String rawName)
          Receive notification of the end of an element.
private  void handleErrorDuringParse(jbreport.ReportException e, java.lang.String msg)
          This method will handle all report errors that occur during parsing in a consistent fashion.
private static void initializeReader()
          This will check if a reader already exists, if not, it will create one.
static void parseXML(org.xml.sax.InputSource input)
          Parse the xml which is read in through the given InputSource instance.
static void parseXML(java.lang.String systemId)
          Parse the xml which is contained by the given systemId.
 jbreport.ReportElement peekElement()
          Peek at the top element on the stack
 jbreport.ReportElement peekElement(int pos)
          Peek at the element at the given position relative to the top of the stack.
 jbreport.ReportElement popElement()
          Pop the top element off the stack
 void pushElement(jbreport.ReportElement elem)
          Push the given element onto the stack
 boolean stackEmpty()
          Is the stack of XMLParsingElement's empty?
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String rawName, org.xml.sax.Attributes attributes)
          Receive notification of the start of an element.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bundle

private static java.util.ResourceBundle bundle
The bundle of resources that provide default settings to the parser, and also determine which parser will be used.


reader

private static org.xml.sax.XMLReader reader
The current XML parser. Should we recognize it, an attempt will be made to re-use rather than re-create it.


stack

private jbreport.util.Stack stack
The stack that is used to determine the current state of parsing. It should be noted here that every xml element should have a mapping, or that its parent should implement the appropriate handling interface.


factory

private jbreport.ReportElementFactory factory
The factory instance that will create the concrete element instances.


cdata

private java.lang.StringBuffer cdata
The current cdata that exists for this element

Constructor Detail

DefaultXMLParseHandler

private DefaultXMLParseHandler()
                        throws jbreport.ReportException
Method Detail

parseXML

public static void parseXML(org.xml.sax.InputSource input)
                     throws jbreport.ReportException
Parse the xml which is read in through the given InputSource instance.


parseXML

public static void parseXML(java.lang.String systemId)
                     throws jbreport.ReportException
Parse the xml which is contained by the given systemId.


startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String rawName,
                         org.xml.sax.Attributes attributes)
Description copied from class: org.xml.sax.helpers.DefaultHandler
Receive notification of the start of an element.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).

Specified by:
startElement in interface org.xml.sax.ContentHandler

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String rawName)
Description copied from class: org.xml.sax.helpers.DefaultHandler
Receive notification of the end of an element.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file).

Specified by:
endElement in interface org.xml.sax.ContentHandler

characters

public void characters(char[] ch,
                       int start,
                       int length)
Description copied from class: org.xml.sax.helpers.DefaultHandler
Receive notification of character data inside an element.

By default, do nothing. Application writers may override this method to take specific actions for each chunk of character data (such as adding the data to a node or buffer, or printing it to a file).

Specified by:
characters in interface org.xml.sax.ContentHandler

pushElement

public void pushElement(jbreport.ReportElement elem)
Description copied from interface: XMLHandler
Push the given element onto the stack

Specified by:
pushElement in interface XMLHandler

peekElement

public jbreport.ReportElement peekElement()
Description copied from interface: XMLHandler
Peek at the top element on the stack

Specified by:
peekElement in interface XMLHandler

peekElement

public jbreport.ReportElement peekElement(int pos)
Description copied from interface: XMLHandler
Peek at the element at the given position relative to the top of the stack. Thus, peekElement(0) is the same as peekElement . peekElement(1) will return the next from last element on the stack, etc.

Specified by:
peekElement in interface XMLHandler

popElement

public jbreport.ReportElement popElement()
Description copied from interface: XMLHandler
Pop the top element off the stack

Specified by:
popElement in interface XMLHandler

stackEmpty

public boolean stackEmpty()
Description copied from interface: XMLHandler
Is the stack of XMLParsingElement's empty?

Specified by:
stackEmpty in interface XMLHandler

initializeReader

private static void initializeReader()
                              throws jbreport.ReportException
This will check if a reader already exists, if not, it will create one. Should the reader already exist, then check to see if we recognize it. If so then try to reset it, otherwise just create a new one.


createNewReader

private static org.xml.sax.XMLReader createNewReader()
                                              throws jbreport.ReportException
This will create a new reader. It should not modify the reader attribute of the class.


handleErrorDuringParse

private void handleErrorDuringParse(jbreport.ReportException e,
                                    java.lang.String msg)
This method will handle all report errors that occur during parsing in a consistent fashion.