Top Description Fields Constructors Methods
org.apache.avalon.framework.configuration

public Class DefaultConfigurationBuilder

extends Object
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, javax.xml.parsers.SAXParser, .SAXParserFactory, org.xml.sax.EntityResolver, .InputSource, .SAXException, .XMLReader

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(boolean) constructor the flag true, or pass a namespace-enabled XMLReader to the DefaultConfigurationBuilder(XMLReader) 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.

Author
Avalon Development Team
Version
$Id: DefaultConfigurationBuilder.java 506231 2007-02-12 02:36:54Z crossley $

Field Summary

Modifier and TypeField and Description
private SAXConfigurationHandler
private XMLReader

Constructor Summary

AccessConstructor and Description
public
DefaultConfigurationBuilder()

Create a Configuration Builder with a default XMLReader that ignores namespaces.

public
DefaultConfigurationBuilder(final boolean
If true, a namespace-aware SAXParser is used. If false, the default JAXP SAXParser (without namespace support) is used.
enableNamespaces
)

Create a Configuration Builder, specifying a flag that determines namespace support.

public
DefaultConfigurationBuilder(XMLReader
an XMLReader
parser
)

Create a Configuration Builder with your own XMLReader.

Method Summary

Modifier and TypeMethod and Description
public Configuration

Returns:

a Configuration object
build
(final InputStream
an InputStream value
inputStream
)

Build a configuration object using an InputStream.

public Configuration

Returns:

a Configuration object
build
(final InputStream
an InputStream value
inputStream
,
final String
the systemId to set on the intermediate sax inputSource
systemId
)

Build a configuration object using an InputStream; supplying a systemId to make messages about all kinds of errors more meaningfull.

public Configuration

Returns:

a Configuration object
build
(final String
a String value
uri
)

Build a configuration object using an URI

public Configuration

Returns:

a Configuration object
build
(final InputSource
an InputSource value
input
)

Build a configuration object using an XML InputSource object

public Configuration

Returns:

a Configuration object
buildFromFile
(final String
name of the file
filename
)

Build a configuration object from a file using a filename.

public Configuration

Returns:

a Configuration object
buildFromFile
(final File
a File object
file
)

Build a configuration object from a file using a File object.

protected SAXConfigurationHandler

Returns:

a SAXConfigurationHandler
getHandler
()

Get a SAXConfigurationHandler for your configuration reading.

public void
setEntityResolver(final EntityResolver
implementation of EntityResolver
resolver
)

Sets the EntityResolver to be used by parser.

private void
setParser(XMLReader parser)

Internally sets up the XMLReader

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

m_handlerback to summary
private SAXConfigurationHandler m_handler
m_parserback to summary
private XMLReader m_parser

Constructor Detail

DefaultConfigurationBuilderback to summary
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.

DefaultConfigurationBuilderback to summary
public DefaultConfigurationBuilder(final boolean enableNamespaces)

Create a Configuration Builder, specifying a flag that determines namespace support.

Parameters
enableNamespaces:boolean

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

Since
4.1
DefaultConfigurationBuilderback to summary
public DefaultConfigurationBuilder(XMLReader parser)

Create a Configuration Builder with your own XMLReader.

Parameters
parser:XMLReader

an XMLReader

Method Detail

buildback to summary
public Configuration build(final InputStream inputStream) throws SAXException, IOException, ConfigurationException

Build a configuration object using an InputStream.

Parameters
inputStream:InputStream

an InputStream value

Returns:Configuration

a Configuration object

Exceptions
SAXException:
if a parsing error occurs
IOException:
if an I/O error occurs
ConfigurationException:
if an error occurs
buildback to summary
public Configuration build(final InputStream inputStream, final String systemId) throws SAXException, IOException, ConfigurationException

Build a configuration object using an InputStream; supplying a systemId to make messages about all kinds of errors more meaningfull.

Parameters
inputStream:InputStream

an InputStream value

systemId:String

the systemId to set on the intermediate sax inputSource

Returns:Configuration

a Configuration object

Exceptions
SAXException:
if a parsing error occurs
IOException:
if an I/O error occurs
ConfigurationException:
if an error occurs
buildback to summary
public Configuration build(final String uri) throws SAXException, IOException, ConfigurationException

Build a configuration object using an URI

Parameters
uri:String

a String value

Returns:Configuration

a Configuration object

Exceptions
SAXException:
if a parsing error occurs
IOException:
if an I/O error occurs
ConfigurationException:
if an error occurs
buildback to summary
public Configuration build(final InputSource input) throws SAXException, IOException, ConfigurationException

Build a configuration object using an XML InputSource object

Parameters
input:InputSource

an InputSource value

Returns:Configuration

a Configuration object

Exceptions
SAXException:
if a parsing error occurs
IOException:
if an I/O error occurs
ConfigurationException:
if an error occurs
buildFromFileback to summary
public Configuration buildFromFile(final String filename) throws SAXException, IOException, ConfigurationException

Build a configuration object from a file using a filename.

Parameters
filename:String

name of the file

Returns:Configuration

a Configuration object

Exceptions
SAXException:
if a parsing error occurs
IOException:
if an I/O error occurs
ConfigurationException:
if an error occurs
buildFromFileback to summary
public Configuration buildFromFile(final File file) throws SAXException, IOException, ConfigurationException

Build a configuration object from a file using a File object.

Parameters
file:File

a File object

Returns:Configuration

a Configuration object

Exceptions
SAXException:
if a parsing error occurs
IOException:
if an I/O error occurs
ConfigurationException:
if an error occurs
getHandlerback to summary
protected SAXConfigurationHandler getHandler()

Get a SAXConfigurationHandler for your configuration reading.

Returns:SAXConfigurationHandler

a SAXConfigurationHandler

setEntityResolverback to summary
public void setEntityResolver(final EntityResolver resolver)

Sets the EntityResolver to be used by parser. Useful when dealing with xml files that reference external entities.

Parameters
resolver:EntityResolver

implementation of EntityResolver

setParserback to summary
private void setParser(XMLReader parser)

Internally sets up the XMLReader