org.cyberneko.pull.util
Class BufferedPullConfiguration

java.lang.Object
  extended byorg.cyberneko.pull.util.BufferedPullConfiguration
All Implemented Interfaces:
org.apache.xerces.xni.parser.XMLComponentManager, org.apache.xerces.xni.parser.XMLParserConfiguration, org.apache.xerces.xni.parser.XMLPullParserConfiguration

public class BufferedPullConfiguration
extends java.lang.Object
implements org.apache.xerces.xni.parser.XMLPullParserConfiguration

An implementation of an XNI XMLPullParserConfiguration that buffers the events so that one and only callback is performed for each call to parse(boolean):boolean. In addition, this class can be used to turn any XNI parser configuration, even it doesn't implement XMLPullParserConfiguration, into a fully buffered, pull parser configuration.

Note: There is a performance hit to buffering the underlying XNI events. While the difference is negligible for small documents, it becomes more pronounced as the document size increases.

Version:
$Id: BufferedPullConfiguration.java,v 1.2 2003/01/28 20:00:30 andyc Exp $
Author:
Andy Clark
See Also:
EventCollector, EventDispatcher

Field Summary
protected  org.apache.xerces.xni.parser.XMLParserConfiguration fConfiguration
          Parser configuration.
protected  org.apache.xerces.xni.XMLDocumentHandler fDocumentHandler
          Document handler.
protected  EventCollector fEventCollector
          Event collector.
protected  EventDispatcher fEventDispatcher
          Event dispatcher.
protected  org.apache.xerces.xni.parser.XMLInputSource fInputSource
          Input source.
protected  org.apache.xerces.xni.parser.XMLPullParserConfiguration fPullConfiguration
          Pull parser configuration.
 
Constructor Summary
BufferedPullConfiguration(org.apache.xerces.xni.parser.XMLParserConfiguration config)
          Constructs a buffered pull parser from the specified configuration.
 
Method Summary
 void addRecognizedFeatures(java.lang.String[] featureIds)
          Allows a parser to add parser specific features to be recognized and managed by the parser configuration.
 void addRecognizedProperties(java.lang.String[] propertyIds)
          Allows a parser to add parser specific properties to be recognized and managed by the parser configuration.
 void cleanup()
          If the application decides to terminate parsing before the xml document is fully parsed, the application should call this method to free any resource allocated during parsing.
 org.apache.xerces.xni.XMLDocumentHandler getDocumentHandler()
          Returns the registered document handler.
 org.apache.xerces.xni.XMLDTDContentModelHandler getDTDContentModelHandler()
          Returns the registered DTD content model handler.
 org.apache.xerces.xni.XMLDTDHandler getDTDHandler()
          Returns the registered DTD handler.
 org.apache.xerces.xni.parser.XMLEntityResolver getEntityResolver()
          Returns the registered entity resolver.
 org.apache.xerces.xni.parser.XMLErrorHandler getErrorHandler()
          Returns the registered error handler.
 boolean getFeature(java.lang.String featureId)
          Returns the state of a feature.
 java.util.Locale getLocale()
          Returns the locale.
 java.lang.Object getProperty(java.lang.String propertyId)
          Returns the value of a property.
 boolean parse(boolean complete)
          Parses the document in a pull parsing fashion.
 void parse(org.apache.xerces.xni.parser.XMLInputSource inputSource)
          Parse an XML document.
protected  void reset()
           
 void setDocumentHandler(org.apache.xerces.xni.XMLDocumentHandler documentHandler)
          Sets the document handler to receive information about the document.
 void setDTDContentModelHandler(org.apache.xerces.xni.XMLDTDContentModelHandler dtdContentModelHandler)
          Sets the DTD content model handler.
 void setDTDHandler(org.apache.xerces.xni.XMLDTDHandler dtdHandler)
          Sets the DTD handler.
 void setEntityResolver(org.apache.xerces.xni.parser.XMLEntityResolver entityResolver)
          Sets the entity resolver.
 void setErrorHandler(org.apache.xerces.xni.parser.XMLErrorHandler errorHandler)
          Sets the error handler.
 void setFeature(java.lang.String featureId, boolean state)
          Sets the state of a feature.
 void setInputSource(org.apache.xerces.xni.parser.XMLInputSource inputSource)
          Sets the input source for the document to parse.
 void setLocale(java.util.Locale locale)
          Set the locale to use for messages.
 void setProperty(java.lang.String propertyId, java.lang.Object value)
          Sets the value of a property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fConfiguration

protected org.apache.xerces.xni.parser.XMLParserConfiguration fConfiguration
Parser configuration.


fPullConfiguration

protected org.apache.xerces.xni.parser.XMLPullParserConfiguration fPullConfiguration
Pull parser configuration.


fInputSource

protected org.apache.xerces.xni.parser.XMLInputSource fInputSource
Input source.


fDocumentHandler

protected org.apache.xerces.xni.XMLDocumentHandler fDocumentHandler
Document handler.


fEventCollector

protected EventCollector fEventCollector
Event collector.


fEventDispatcher

protected EventDispatcher fEventDispatcher
Event dispatcher.

Constructor Detail

BufferedPullConfiguration

public BufferedPullConfiguration(org.apache.xerces.xni.parser.XMLParserConfiguration config)
Constructs a buffered pull parser from the specified configuration.

Method Detail

setInputSource

public void setInputSource(org.apache.xerces.xni.parser.XMLInputSource inputSource)
                    throws org.apache.xerces.xni.parser.XMLConfigurationException,
                           java.io.IOException
Sets the input source for the document to parse.

Specified by:
setInputSource in interface org.apache.xerces.xni.parser.XMLPullParserConfiguration
Parameters:
inputSource - The document's input source.
Throws:
org.apache.xerces.xni.parser.XMLConfigurationException - Thrown if there is a configuration error when initializing the parser.
java.io.IOException - Thrown on I/O error.
See Also:
parse(boolean)

parse

public boolean parse(boolean complete)
              throws org.apache.xerces.xni.XNIException,
                     java.io.IOException
Parses the document in a pull parsing fashion.

Specified by:
parse in interface org.apache.xerces.xni.parser.XMLPullParserConfiguration
Parameters:
complete - True if the pull parser should parse the remaining document completely.
Throws:
org.apache.xerces.xni.XNIException - Any XNI exception, possibly wrapping another exception.
java.io.IOException - An IO exception from the parser, possibly from a byte stream or character stream supplied by the parser.
See Also:
setInputSource(org.apache.xerces.xni.parser.XMLInputSource)

cleanup

public void cleanup()
If the application decides to terminate parsing before the xml document is fully parsed, the application should call this method to free any resource allocated during parsing. For example, close all opened streams.

Specified by:
cleanup in interface org.apache.xerces.xni.parser.XMLPullParserConfiguration

parse

public void parse(org.apache.xerces.xni.parser.XMLInputSource inputSource)
           throws org.apache.xerces.xni.XNIException,
                  java.io.IOException
Parse an XML document.

The parser can use this method to instruct this configuration to begin parsing an XML document from any valid input source (a character stream, a byte stream, or a URI).

Parsers may not invoke this method while a parse is in progress. Once a parse is complete, the parser may then parse another XML document.

This method is synchronous: it will not return until parsing has ended. If a client application wants to terminate parsing early, it should throw an exception.

When this method returns, all characters streams and byte streams opened by the parser are closed.

Specified by:
parse in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Throws:
org.apache.xerces.xni.XNIException - Any XNI exception, possibly wrapping another exception.
java.io.IOException - An IO exception from the parser, possibly from a byte stream or character stream supplied by the parser.

addRecognizedFeatures

public void addRecognizedFeatures(java.lang.String[] featureIds)
Allows a parser to add parser specific features to be recognized and managed by the parser configuration.

Specified by:
addRecognizedFeatures in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
featureIds - An array of the additional feature identifiers to be recognized.

setFeature

public void setFeature(java.lang.String featureId,
                       boolean state)
                throws org.apache.xerces.xni.parser.XMLConfigurationException
Sets the state of a feature. This method is called by the parser and gets propagated to components in this parser configuration.

Specified by:
setFeature in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
featureId - The feature identifier.
state - The state of the feature.
Throws:
org.apache.xerces.xni.parser.XMLConfigurationException - Thrown if there is a configuration error.

getFeature

public boolean getFeature(java.lang.String featureId)
                   throws org.apache.xerces.xni.parser.XMLConfigurationException
Returns the state of a feature.

Specified by:
getFeature in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
featureId - The feature identifier.
Throws:
org.apache.xerces.xni.parser.XMLConfigurationException - Thrown if there is a configuration error.

addRecognizedProperties

public void addRecognizedProperties(java.lang.String[] propertyIds)
Allows a parser to add parser specific properties to be recognized and managed by the parser configuration.

Specified by:
addRecognizedProperties in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
propertyIds - An array of the additional property identifiers to be recognized.

setProperty

public void setProperty(java.lang.String propertyId,
                        java.lang.Object value)
                 throws org.apache.xerces.xni.parser.XMLConfigurationException
Sets the value of a property. This method is called by the parser and gets propagated to components in this parser configuration.

Specified by:
setProperty in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
propertyId - The property identifier.
value - The value of the property.
Throws:
org.apache.xerces.xni.parser.XMLConfigurationException - Thrown if there is a configuration error.

getProperty

public java.lang.Object getProperty(java.lang.String propertyId)
                             throws org.apache.xerces.xni.parser.XMLConfigurationException
Returns the value of a property.

Specified by:
getProperty in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
propertyId - The property identifier.
Throws:
org.apache.xerces.xni.parser.XMLConfigurationException - Thrown if there is a configuration error.

setErrorHandler

public void setErrorHandler(org.apache.xerces.xni.parser.XMLErrorHandler errorHandler)
Sets the error handler.

Specified by:
setErrorHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
errorHandler - The error resolver.

getErrorHandler

public org.apache.xerces.xni.parser.XMLErrorHandler getErrorHandler()
Returns the registered error handler.

Specified by:
getErrorHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration

setDocumentHandler

public void setDocumentHandler(org.apache.xerces.xni.XMLDocumentHandler documentHandler)
Sets the document handler to receive information about the document.

Specified by:
setDocumentHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
documentHandler - The document handler.

getDocumentHandler

public org.apache.xerces.xni.XMLDocumentHandler getDocumentHandler()
Returns the registered document handler.

Specified by:
getDocumentHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration

setDTDHandler

public void setDTDHandler(org.apache.xerces.xni.XMLDTDHandler dtdHandler)
Sets the DTD handler.

Specified by:
setDTDHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
dtdHandler - The DTD handler.

getDTDHandler

public org.apache.xerces.xni.XMLDTDHandler getDTDHandler()
Returns the registered DTD handler.

Specified by:
getDTDHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration

setDTDContentModelHandler

public void setDTDContentModelHandler(org.apache.xerces.xni.XMLDTDContentModelHandler dtdContentModelHandler)
Sets the DTD content model handler.

Specified by:
setDTDContentModelHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
dtdContentModelHandler - The DTD content model handler.

getDTDContentModelHandler

public org.apache.xerces.xni.XMLDTDContentModelHandler getDTDContentModelHandler()
Returns the registered DTD content model handler.

Specified by:
getDTDContentModelHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration

setEntityResolver

public void setEntityResolver(org.apache.xerces.xni.parser.XMLEntityResolver entityResolver)
Sets the entity resolver.

Specified by:
setEntityResolver in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
entityResolver - The new entity resolver.

getEntityResolver

public org.apache.xerces.xni.parser.XMLEntityResolver getEntityResolver()
Returns the registered entity resolver.

Specified by:
getEntityResolver in interface org.apache.xerces.xni.parser.XMLParserConfiguration

setLocale

public void setLocale(java.util.Locale locale)
               throws org.apache.xerces.xni.XNIException
Set the locale to use for messages.

Specified by:
setLocale in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
locale - The locale object to use for localization of messages.
Throws:
org.apache.xerces.xni.XNIException - Thrown if the parser does not support the specified locale.

getLocale

public java.util.Locale getLocale()
Returns the locale.

Specified by:
getLocale in interface org.apache.xerces.xni.parser.XMLParserConfiguration

reset

protected void reset()
              throws org.apache.xerces.xni.parser.XMLConfigurationException
Throws:
org.apache.xerces.xni.parser.XMLConfigurationException


(C) Copyright 2002-2004, Andy Clark. All rights reserved.