GXPARSE hosted by SourceForge.net Logo

ca.gorman.xml.parse.sax
Class XMLParser<T extends Global>

java.lang.Object
  extended by ca.gorman.xml.parse.sax.XMLParser<T>
All Implemented Interfaces:
Parser<T>

public abstract class XMLParser<T extends Global>
extends Object
implements Parser<T>

A Parser to support the Listener interface for parsing XML documents. Uses SAXAdapter to support the Listener interface.


Constructor Summary
protected XMLParser(SAXParser saxParser)
           Construct on an instance of javax.xml.parsers.SAXParser.
protected XMLParser(SAXParserFactory factory)
           Construct on an instance of javax.xml.parsers.SAXParserFactory.
protected XMLParser(XMLReader xmlReader)
           Construct directly on an instance of org.xml.sax.XMLReader.
 
Method Summary
 Element getCurrentElement()
           Get the element that is on top of the element stack.
 Element[] getElementStack()
           Get the element stack as an array.
 boolean getFeature(String name)
           Look up the state of a feature.
 T getGlobal()
           Get the instance of Global, if one was provided to the Parser.
 Listener<Parser<T>> getListener()
           Get Listener.
 Location getLocation()
           Get information about the current location of the Parser in the input stream.
 Object getProperty(String name)
           Look up the state of a property.
 boolean isParsing(QName qName)
           Indicate whether a particular element is currently being parsed.
static
<T extends Global>
XMLParser<T>
newInstance(SAXParserFactory factory)
           Create an XMLParser.
 void parse(Input input)
           Parse a document, without making an instance of Global accessible to all Listener methods.
 void parse(Input input, T global)
           Parse a document, making an instance of Global accessible to all Listener methods.
 void setFeature(String name, boolean value)
           Set the state of a feature.
 void setListener(Listener<Parser<T>> listener)
           Set Listener.
 void setProperty(String name, Object value)
           Set the state of a property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLParser

protected XMLParser(XMLReader xmlReader)

Construct directly on an instance of org.xml.sax.XMLReader. A Listener must be installed by setListener.

Throws:
NullPointerException - if xmlReader is null

XMLParser

protected XMLParser(SAXParser saxParser)
             throws SAXException

Construct on an instance of javax.xml.parsers.SAXParser. A Listener must be installed by setListener.

Throws:
NullPointerException - if saxParser is null
SAXException

XMLParser

protected XMLParser(SAXParserFactory factory)
             throws ParserConfigurationException,
                    SAXException

Construct on an instance of javax.xml.parsers.SAXParserFactory. A Listener must be installed by setListener.

Throws:
NullPointerException - if factory is null
ParserConfigurationException
SAXException
Method Detail

newInstance

public static <T extends Global> XMLParser<T> newInstance(SAXParserFactory factory)
                                               throws ParserConfigurationException,
                                                      SAXException

Create an XMLParser.

A Listener must be installed by setListener.

Throws:
ParserConfigurationException
SAXException

getFeature

public boolean getFeature(String name)
                   throws SAXNotRecognizedException,
                          SAXNotSupportedException

Look up the state of a feature.

Delegates to org.xml.sax.XMLReader.getFeature.

Throws:
SAXNotRecognizedException
SAXNotSupportedException

setFeature

public void setFeature(String name,
                       boolean value)
                throws SAXNotRecognizedException,
                       SAXNotSupportedException

Set the state of a feature.

Delegates to org.xml.sax.XMLReader.setFeature(String). // @see org.xml.sax.XMLReader.setFeature(String)

Throws:
SAXNotRecognizedException
SAXNotSupportedException

getProperty

public Object getProperty(String name)
                   throws SAXNotRecognizedException,
                          SAXNotSupportedException

Look up the state of a property.

Delegates to org.xml.sax.XMLReader.getProperty(String). // @see org.xml.sax.XMLReader.getFeature(String)

Throws:
SAXNotRecognizedException
SAXNotSupportedException

setProperty

public void setProperty(String name,
                        Object value)
                 throws SAXNotRecognizedException,
                        SAXNotSupportedException

Set the state of a property.

Delegates to org.xml.sax.XMLReader.setProperty(String). // @see org.xml.sax.XMLReader.setProperty(String)

Throws:
SAXNotRecognizedException
SAXNotSupportedException

parse

public void parse(Input input)
           throws ListenerException,
                  ParseException,
                  IOException
Description copied from interface: Parser

Parse a document, without making an instance of Global accessible to all Listener methods.

Specified by:
parse in interface Parser<T extends Global>
Parameters:
input - an Input that has been initialized to identify a source for an XML document
Throws:
ListenerException - if the Listener throws ListenerException
ParseException - if any component of the Parser throws an exception
IOException - if the Parser throws IOException while reading input or the Listener throws IOException while writing output.

getGlobal

public T getGlobal()
Description copied from interface: Parser

Get the instance of Global, if one was provided to the Parser.

Specified by:
getGlobal in interface Parser<T extends Global>
Returns:
global an instance Global, or null.

parse

public void parse(Input input,
                  T global)
           throws ListenerException,
                  ParseException,
                  IOException
Description copied from interface: Parser

Parse a document, making an instance of Global accessible to all Listener methods.

Specified by:
parse in interface Parser<T extends Global>
Parameters:
input - an Input that has been initialized to identify a source for an XML document
global - an instance Global, or null.
Throws:
ListenerException - if the Listener throws ListenerException
ParseException - if any component of the Parser throws an exception
IOException - if the Parser throws IOException while reading input or the Listener throws IOException while writing output.

getListener

public Listener<Parser<T>> getListener()
Description copied from interface: Parser

Get Listener.

Specified by:
getListener in interface Parser<T extends Global>

setListener

public void setListener(Listener<Parser<T>> listener)
Description copied from interface: Parser

Set Listener.

Specified by:
setListener in interface Parser<T extends Global>
Parameters:
listener - that will receive information from the parser.

getCurrentElement

public Element getCurrentElement()
Description copied from interface: Parser

Get the element that is on top of the element stack.

Specified by:
getCurrentElement in interface Parser<T extends Global>
Returns:
the innermost element being parsed, or null if there are no elements currently on the element stack

getElementStack

public Element[] getElementStack()
Description copied from interface: Parser

Get the element stack as an array.

Specified by:
getElementStack in interface Parser<T extends Global>
Returns:
an array of the zero or more elements currently being parsed, beginning with the outermost (document) element and ending with the innermost element

isParsing

public boolean isParsing(QName qName)
Description copied from interface: Parser

Indicate whether a particular element is currently being parsed.

Specified by:
isParsing in interface Parser<T extends Global>
Returns:
true if the named element is currently being parsed, false otherwise

getLocation

public Location getLocation()
Description copied from interface: Parser

Get information about the current location of the Parser in the input stream. The information is valid only during the invocation of a Listener method.

Specified by:
getLocation in interface Parser<T extends Global>
Returns:
a Location when the parser is active, null when the parser is not active

GXPARSE download

GXPARSE Generic XML Stream Parser API and supporting tools.   Release $Name: gxparse-sf-alpha-2_0 $
Copyright 2003-2004 Ian E. Gorman
Released under GNU Lesser General Public License