org.apache.commons.configuration

Class ConfigurationXMLReader

public abstract class ConfigurationXMLReader extends Object implements XMLReader

A base class for "faked" XMLReader classes that transform a configuration object in a set of SAX parsing events.

This class provides dummy implementations for most of the methods defined in the XMLReader interface that are not used for this special purpose. There will be concrete sub classes that process specific configuration classes.

Version: $Id: ConfigurationXMLReader.java 439648 2006-09-02 20:42:10Z oheger $

Author: Oliver Heger

Field Summary
ContentHandlercontentHandler
Stores the content handler.
static StringDEFAULT_ROOT_NAME
Constant for the default name of the root element.
SAXExceptionexception
Stores an exception that occurred during parsing.
static AttributesEMPTY_ATTRS
An empty attributes object.
protected static StringNS_URI
Constant for the namespace URI.
StringrootName
Stores the name for the root element.
Constructor Summary
protected ConfigurationXMLReader()
Creates a new instance of ConfigurationXMLReader.
Method Summary
protected voidfireCharacters(String text)
Fires a SAX characters event.
protected voidfireElementEnd(String name)
Fires a SAX element end event.
protected voidfireElementStart(String name, Attributes attribs)
Fires a SAX element start event.
ContentHandlergetContentHandler()
Returns the actually set content handler.
DTDHandlergetDTDHandler()
Returns the DTD handler.
EntityResolvergetEntityResolver()
Returns the entity resolver.
ErrorHandlergetErrorHandler()
Returns the error handler.
SAXExceptiongetException()
Returns a reference to an exception that occurred during parsing.
booleangetFeature(String name)
Dummy implementation of the interface method.
abstract ConfigurationgetParsedConfiguration()
Returns a reference to the configuration that is parsed by this object.
ObjectgetProperty(String name)
Dummy implementation of the interface method.
StringgetRootName()
Returns the name to be used for the root element.
voidparse(String systemId)
Parses the acutal configuration object.
voidparse(InputSource input)
Parses the acutal configuration object.
protected voidparseConfiguration()
Parses the configuration object and generates SAX events.
protected abstract voidprocessKeys()
Processes all keys stored in the actual configuration.
voidsetContentHandler(ContentHandler handler)
Sets the content handler.
voidsetDTDHandler(DTDHandler handler)
Sets the DTD handler.
voidsetEntityResolver(EntityResolver resolver)
Sets the entity resolver.
voidsetErrorHandler(ErrorHandler handler)
Sets the error handler.
voidsetFeature(String name, boolean value)
Dummy implementation of the interface method.
voidsetProperty(String name, Object value)
Dummy implementation of the interface method.
voidsetRootName(String string)
Sets the name for the root element.

Field Detail

contentHandler

private ContentHandler contentHandler
Stores the content handler.

DEFAULT_ROOT_NAME

private static final String DEFAULT_ROOT_NAME
Constant for the default name of the root element.

exception

private SAXException exception
Stores an exception that occurred during parsing.

EMPTY_ATTRS

private static final Attributes EMPTY_ATTRS
An empty attributes object.

NS_URI

protected static final String NS_URI
Constant for the namespace URI.

rootName

private String rootName
Stores the name for the root element.

Constructor Detail

ConfigurationXMLReader

protected ConfigurationXMLReader()
Creates a new instance of ConfigurationXMLReader.

Method Detail

fireCharacters

protected void fireCharacters(String text)
Fires a SAX characters event.

Parameters: text the text

fireElementEnd

protected void fireElementEnd(String name)
Fires a SAX element end event.

Parameters: name the name of the affected element

fireElementStart

protected void fireElementStart(String name, Attributes attribs)
Fires a SAX element start event.

Parameters: name the name of the actual element attribs the attributes of this element (can be null)

getContentHandler

public ContentHandler getContentHandler()
Returns the actually set content handler.

Returns: the content handler

getDTDHandler

public DTDHandler getDTDHandler()
Returns the DTD handler. This class does not support DTD handlers, so this method always returns null.

Returns: the DTD handler

getEntityResolver

public EntityResolver getEntityResolver()
Returns the entity resolver. This class does not support an entity resolver, so this method always returns null.

Returns: the entity resolver

getErrorHandler

public ErrorHandler getErrorHandler()
Returns the error handler. This class does not support an error handler, so this method always returns null.

Returns: the error handler

getException

public SAXException getException()
Returns a reference to an exception that occurred during parsing.

Returns: a SAXExcpetion or null if none occurred

getFeature

public boolean getFeature(String name)
Dummy implementation of the interface method.

Parameters: name the name of the feature

Returns: always false (no features are supported)

getParsedConfiguration

public abstract Configuration getParsedConfiguration()
Returns a reference to the configuration that is parsed by this object.

Returns: the parsed configuration

getProperty

public Object getProperty(String name)
Dummy implementation of the interface method. No properties are supported, so this method always returns null.

Parameters: name the name of the requested property

Returns: the property value

getRootName

public String getRootName()
Returns the name to be used for the root element.

Returns: the name for the root element

parse

public void parse(String systemId)
Parses the acutal configuration object. The passed system ID will be ignored.

Parameters: systemId the system ID (ignored)

Throws: IOException if no configuration was specified SAXException if an error occurs during parsing

parse

public void parse(InputSource input)
Parses the acutal configuration object. The passed input source will be ignored.

Parameters: input the input source (ignored)

Throws: IOException if no configuration was specified SAXException if an error occurs during parsing

parseConfiguration

protected void parseConfiguration()
Parses the configuration object and generates SAX events. This is the main processing method.

Throws: IOException if no configuration has been specified SAXException if an error occurs during parsing

processKeys

protected abstract void processKeys()
Processes all keys stored in the actual configuration. This method is called by parseConfiguration() to start the main parsing process. parseConfiguration() calls the content handler's startDocument() and endElement() methods and cares for exception handling. The remaining actions are left to this method that must be implemented in a concrete sub class.

Throws: IOException if an IO error occurs SAXException if a SAX error occurs

setContentHandler

public void setContentHandler(ContentHandler handler)
Sets the content handler. The object specified here will receive SAX events during parsing.

Parameters: handler the content handler

setDTDHandler

public void setDTDHandler(DTDHandler handler)
Sets the DTD handler. The passed value is ignored.

Parameters: handler the handler to be set

setEntityResolver

public void setEntityResolver(EntityResolver resolver)
Sets the entity resolver. The passed value is ignored.

Parameters: resolver the entity resolver

setErrorHandler

public void setErrorHandler(ErrorHandler handler)
Sets the error handler. The passed value is ignored.

Parameters: handler the error handler

setFeature

public void setFeature(String name, boolean value)
Dummy implementation of the interface method.

Parameters: name the name of the feature to be set value the value of the feature

setProperty

public void setProperty(String name, Object value)
Dummy implementation of the interface method. No properties are supported, so a call of this method just has no effect.

Parameters: name the property name value the property value

setRootName

public void setRootName(String string)
Sets the name for the root element.

Parameters: string the name for the root element.