org.apache.avalon.framework.configuration

Class DefaultConfigurationBuilder

public class DefaultConfigurationBuilder extends Object

A DefaultConfigurationBuilder builds Configurations from XML, via a SAX2 compliant parser.

XML namespace support is optional, and disabled by default to preserve backwards-compatibility. To enable it, pass the DefaultConfigurationBuilder constructor the flag true, or pass a namespace-enabled XMLReader to the DefaultConfigurationBuilder constructor.

The mapping from XML namespaces to Configuration namespaces is pretty straightforward, with one caveat: attribute namespaces are (deliberately) not supported. Enabling namespace processing has the following effects:

Whitespace handling. Since mixed content is not allowed in the configurations, whitespace is completely discarded in non-leaf nodes. For the leaf nodes the default behavior is to trim the space surrounding the value. This can be changed by specifying xml:space attribute with value of preserve in that case the whitespace is left intact.

Version: $Id: DefaultConfigurationBuilder.java 30977 2004-07-30 03:57:54 -0500 (Fri, 30 Jul 2004) niclas $

Author: Avalon Development Team

Field Summary
SAXConfigurationHandlerm_handler
XMLReaderm_parser
Constructor Summary
DefaultConfigurationBuilder()
Create a Configuration Builder with a default XMLReader that ignores namespaces.
DefaultConfigurationBuilder(boolean enableNamespaces)
Create a Configuration Builder, specifying a flag that determines namespace support.
DefaultConfigurationBuilder(XMLReader parser)
Create a Configuration Builder with your own XMLReader.
Method Summary
Configurationbuild(InputStream inputStream)
Build a configuration object using an InputStream.
Configurationbuild(InputStream inputStream, String systemId)
Build a configuration object using an InputStream; supplying a systemId to make messages about all kinds of errors more meaningfull.
Configurationbuild(String uri)
Build a configuration object using an URI
Configurationbuild(InputSource input)
Build a configuration object using an XML InputSource object
ConfigurationbuildFromFile(String filename)
Build a configuration object from a file using a filename.
ConfigurationbuildFromFile(File file)
Build a configuration object from a file using a File object.
protected SAXConfigurationHandlergetHandler()
Get a SAXConfigurationHandler for your configuration reading.
voidsetEntityResolver(EntityResolver resolver)
Sets the EntityResolver to be used by parser.
voidsetParser(XMLReader parser)
Internally sets up the XMLReader

Field Detail

m_handler

private SAXConfigurationHandler m_handler

m_parser

private XMLReader m_parser

Constructor Detail

DefaultConfigurationBuilder

public DefaultConfigurationBuilder()
Create a Configuration Builder with a default XMLReader that ignores namespaces. In order to enable namespaces, use either the constructor that has a boolean or that allows you to pass in your own namespace-enabled XMLReader.

DefaultConfigurationBuilder

public DefaultConfigurationBuilder(boolean enableNamespaces)
Create a Configuration Builder, specifying a flag that determines namespace support.

Parameters: enableNamespaces If true, a namespace-aware SAXParser is used. If false, the default JAXP SAXParser (without namespace support) is used.

Since: 4.1

DefaultConfigurationBuilder

public DefaultConfigurationBuilder(XMLReader parser)
Create a Configuration Builder with your own XMLReader.

Parameters: parser an XMLReader

Method Detail

build

public Configuration build(InputStream inputStream)
Build a configuration object using an InputStream.

Parameters: inputStream an InputStream value

Returns: a Configuration object

Throws: SAXException if a parsing error occurs IOException if an I/O error occurs ConfigurationException if an error occurs

build

public Configuration build(InputStream inputStream, String systemId)
Build a configuration object using an InputStream; supplying a systemId to make messages about all kinds of errors more meaningfull.

Parameters: inputStream an InputStream value systemId the systemId to set on the intermediate sax inputSource

Returns: a Configuration object

Throws: SAXException if a parsing error occurs IOException if an I/O error occurs ConfigurationException if an error occurs

build

public Configuration build(String uri)
Build a configuration object using an URI

Parameters: uri a String value

Returns: a Configuration object

Throws: SAXException if a parsing error occurs IOException if an I/O error occurs ConfigurationException if an error occurs

build

public Configuration build(InputSource input)
Build a configuration object using an XML InputSource object

Parameters: input an InputSource value

Returns: a Configuration object

Throws: SAXException if a parsing error occurs IOException if an I/O error occurs ConfigurationException if an error occurs

buildFromFile

public Configuration buildFromFile(String filename)
Build a configuration object from a file using a filename.

Parameters: filename name of the file

Returns: a Configuration object

Throws: SAXException if a parsing error occurs IOException if an I/O error occurs ConfigurationException if an error occurs

buildFromFile

public Configuration buildFromFile(File file)
Build a configuration object from a file using a File object.

Parameters: file a File object

Returns: a Configuration object

Throws: SAXException if a parsing error occurs IOException if an I/O error occurs ConfigurationException if an error occurs

getHandler

protected SAXConfigurationHandler getHandler()
Get a SAXConfigurationHandler for your configuration reading.

Returns: a SAXConfigurationHandler

setEntityResolver

public void setEntityResolver(EntityResolver resolver)
Sets the EntityResolver to be used by parser. Useful when dealing with xml files that reference external entities.

Parameters: resolver implementation of EntityResolver

setParser

private void setParser(XMLReader parser)
Internally sets up the XMLReader