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

public Class DefaultConfiguration

extends AbstractConfiguration
implements MutableConfiguration, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.avalon.framework.configuration.MutableConfiguration, org.apache.avalon.framework.configuration.Configuration
Imports
java.io.Serializable, java.util.ArrayList, .HashMap

This is the default Configuration implementation.
Author
Avalon Development Team
Version
$Id: DefaultConfiguration.java 506231 2007-02-12 02:36:54Z crossley $

Field Summary

Modifier and TypeField and Description
protected static final Configuration[]
EMPTY_ARRAY

An empty (length zero) array of configuration objects.

private HashMap<K, V>
private ArrayList<E>
private final String
private final String
private final String
private final String
private boolean
private String

Constructor Summary

AccessConstructor and Description
public
DefaultConfiguration(Configuration
the Configuration to copy
config
,
boolean
true will cause clones of the children to be added, false will add the original instances and is thus faster.
deepCopy
)

Copy constructor, to create a clone of another configuration.

public
DefaultConfiguration(Configuration
the Configuration to copy
config
)

Shallow copy constructor, suitable for craeting a writable clone of a read-only configuration.

public
DefaultConfiguration(final String
a String value
name
)

Create a new DefaultConfiguration instance.

public
DefaultConfiguration(final String
a String value
name
,
final String
a String value
location
)

Create a new DefaultConfiguration instance.

public
DefaultConfiguration(final String
config node name
name
,
final String
Builder-specific locator string
location
,
final String
Namespace string (typically a URI). Should not be null; use "" if no namespace.
ns
,
final String
A short string prefixed to element names, associating elements with a longer namespace string. Should not be null; use "" if no namespace.
prefix
)

Create a new DefaultConfiguration instance.

Method Summary

Modifier and TypeMethod and Description
public void
addAll(final Configuration
the Configuration element
other
,
final boolean
true will cause clones of the children to be added, false will add the original instances and is thus faster. throws ConfigurationException If there are any problems cloning the children.
deepCopy
)

Add all the attributes, children and value from specified configuration element to current configuration element.

public void
addAll(final Configuration
the Configuration element
other
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.addAll.

Add all the attributes, children and value from specified configuration element to current configuration element.
public void
addAllAttributes(final Configuration
the Configuration element
other
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.addAllAttributes.

Add all attributes from specified configuration element to current configuration element.
public void
addAllChildren(final Configuration
the other Configuration value throws ConfigurationException If there are any problems cloning the children.
other
,
final boolean
true will cause clones of the children to be added, false will add the original instances and is thus faster.
deepCopy
)

Add all child Configuration objects from specified configuration element to current configuration element.

public void
addAllChildren(final Configuration
the other Configuration value
other
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.addAllChildren.

Add all child Configuration objects from specified configuration element to current configuration element.
public String

Returns:

a String value
addAttribute
(final String
a String value
name
,
String
a String value
value
)

Deprecated Use setAttribute() instead
Add an attribute to this configuration element, returning its old value or null.
public void
addChild(final Configuration
a Configuration value
configuration
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.addChild.

Add a child Configuration to this configuration element.
public void
appendValueData(final String
a String value
value
)

Deprecated Use setValue() instead
Append data to the value of this configuration element.
private boolean
check(Object one, Object two)

protected final void
checkWriteable()

heck if this configuration is writeable.

public boolean

Returns:

true if they are the same.
equals
(Object
The other configuration
other
)

Overrides java.lang.Object.equals.

Compare if this configuration is equal to another.
public String

Returns:

a String value
getAttribute
(final String
a String value
name
)

Implements org.apache.avalon.framework.configuration.Configuration.getAttribute.

Returns the value of the attribute specified by its name as a String.
public String[]

Returns:

a String[] value
getAttributeNames
()

Implements org.apache.avalon.framework.configuration.Configuration.getAttributeNames.

Return an array of all attribute names.
public Configuration

Returns:

a Configuration value
getChild
(final String
a String value
name
,
final boolean
a boolean value
createNew
)

Overrides org.apache.avalon.framework.configuration.AbstractConfiguration.getChild.

Implements org.apache.avalon.framework.configuration.Configuration.getChild.

Return the first Configuration object child of this associated with the given name.
public int

Returns:

an int value
getChildCount
()

Return count of children.

public Configuration[]

Returns:

The child nodes with name
getChildren
()

Implements org.apache.avalon.framework.configuration.Configuration.getChildren.

Return an array of Configuration elements containing all node children.
public Configuration[]

Returns:

a Configuration[] value
getChildren
(final String
The name of the required children Configuration.
name
)

Implements org.apache.avalon.framework.configuration.Configuration.getChildren.

Return an array of Configuration objects children of this associated with the given name.
public String

Returns:

a String value
getLocation
()

Implements org.apache.avalon.framework.configuration.Configuration.getLocation.

Returns a description of location of element.
public MutableConfiguration
getMutableChild(final String name)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.getMutableChild.

Equivalent to getMutableChild( name, true )
public MutableConfiguration
getMutableChild(final String
the name of the child.
name
,
boolean
set to true to create the child node if it doesn't exist.
autoCreate
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.getMutableChild.

Gets a child node of this configuration.
public MutableConfiguration[]
public MutableConfiguration[]
getMutableChildren(final String name)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.getMutableChildren.

Returns an array of mutable children with the given name.
public String

Returns:

a String value
getName
()

Implements org.apache.avalon.framework.configuration.Configuration.getName.

Returns the name of this configuration element.
public String

Returns:

a String value
getNamespace
()

Implements org.apache.avalon.framework.configuration.Configuration.getNamespace.

Returns the namespace of this configuration element
protected String

Returns:

a String value
getPrefix
()

Implements abstract org.apache.avalon.framework.configuration.AbstractConfiguration.getPrefix.

Returns the prefix of the namespace
public String

Returns:

a String value
getValue
(final String
the default value to return if value malformed or empty
defaultValue
)

Overrides org.apache.avalon.framework.configuration.AbstractConfiguration.getValue.

Implements org.apache.avalon.framework.configuration.Configuration.getValue.

Returns the value of the configuration element as a String.
public String

Returns:

a String value
getValue
()

Implements org.apache.avalon.framework.configuration.Configuration.getValue.

Returns the value of the configuration element as a String.
public int

Returns:

the hashcode.
hashCode
()

Overrides java.lang.Object.hashCode.

Obtaine the hashcode for this configuration.
protected final boolean
isReadOnly()

Returns true iff this DefaultConfiguration has been made read-only.

public void
makeReadOnly()

Make this configuration read-only.

public void
removeChild(final Configuration
a Configuration value
configuration
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.removeChild.

Remove a child Configuration to this configuration element.
public void
setAttribute(final String
name of the attribute to set
name
,
final String
a String value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified string.
public void
setAttribute(final String
name of the attribute to set
name
,
final int
an int value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified int.
public void
setAttribute(final String
name of the attribute to set
name
,
final long
an long value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified long.
public void
setAttribute(final String
name of the attribute to set
name
,
final boolean
an boolean value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified boolean.
public void
setAttribute(final String
name of the attribute to set
name
,
final float
an float value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified float.
public void
setAttribute(final String
name of the attribute to set
name
,
final double
an double value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified double.
public void
setValue(final String
a String value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified string.
public void
setValue(final int
a int value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified int.
public void
setValue(final long
a long value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified long.
public void
setValue(final boolean
a boolean value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified boolean.
public void
setValue(final float
a float value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified float.
public void
setValue(final double
a double value
value
)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified double.
private MutableConfiguration
toMutable(Configuration child)

Convenience function to convert a child to a mutable configuration.

Inherited from org.apache.avalon.framework.configuration.AbstractConfiguration:
getAttributegetAttributeAsBooleangetAttributeAsBooleangetAttributeAsDoublegetAttributeAsDoublegetAttributeAsFloatgetAttributeAsFloatgetAttributeAsIntegergetAttributeAsIntegergetAttributeAsLonggetAttributeAsLonggetChildgetValueAsBooleangetValueAsBooleangetValueAsDoublegetValueAsDoublegetValueAsFloatgetValueAsFloatgetValueAsIntegergetValueAsIntegergetValueAsLonggetValueAsLongtoString

Field Detail

EMPTY_ARRAYback to summary
protected static final Configuration[] EMPTY_ARRAY

An empty (length zero) array of configuration objects.

m_attributesback to summary
private HashMap<K, V> m_attributes
m_childrenback to summary
private ArrayList<E> m_children
m_locationback to summary
private final String m_location
m_nameback to summary
private final String m_name
m_namespaceback to summary
private final String m_namespace
m_prefixback to summary
private final String m_prefix
m_readOnlyback to summary
private boolean m_readOnly
m_valueback to summary
private String m_value

Constructor Detail

DefaultConfigurationback to summary
public DefaultConfiguration(Configuration config, boolean deepCopy) throws ConfigurationException

Copy constructor, to create a clone of another configuration. To modify children, use getChild(), removeChild() and addChild().

Parameters
config:Configuration

the Configuration to copy

deepCopy:boolean

true will cause clones of the children to be added, false will add the original instances and is thus faster.

Exceptions
ConfigurationException:
if an error occurs when copying
DefaultConfigurationback to summary
public DefaultConfiguration(Configuration config) throws ConfigurationException

Shallow copy constructor, suitable for craeting a writable clone of a read-only configuration. To modify children, use getChild(), removeChild() and addChild().

Parameters
config:Configuration

the Configuration to copy

Exceptions
ConfigurationException:
if an error occurs when copying
DefaultConfigurationback to summary
public DefaultConfiguration(final String name)

Create a new DefaultConfiguration instance.

Parameters
name:String

a String value

DefaultConfigurationback to summary
public DefaultConfiguration(final String name, final String location)

Create a new DefaultConfiguration instance.

Parameters
name:String

a String value

location:String

a String value

DefaultConfigurationback to summary
public DefaultConfiguration(final String name, final String location, final String ns, final String prefix)

Create a new DefaultConfiguration instance.

Parameters
name:String

config node name

location:String

Builder-specific locator string

ns:String

Namespace string (typically a URI). Should not be null; use "" if no namespace.

prefix:String

A short string prefixed to element names, associating elements with a longer namespace string. Should not be null; use "" if no namespace.

Since
4.1

Method Detail

addAllback to summary
public void addAll(final Configuration other, final boolean deepCopy) throws ConfigurationException

Add all the attributes, children and value from specified configuration element to current configuration element.

Parameters
other:Configuration

the Configuration element

deepCopy:boolean

true will cause clones of the children to be added, false will add the original instances and is thus faster. throws ConfigurationException If there are any problems cloning the children.

addAllback to summary
public void addAll(final Configuration other)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.addAll.

Add all the attributes, children and value from specified configuration element to current configuration element.

Parameters
other:Configuration

the Configuration element

addAllAttributesback to summary
public void addAllAttributes(final Configuration other)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.addAllAttributes.

Add all attributes from specified configuration element to current configuration element.

Parameters
other:Configuration

the Configuration element

addAllChildrenback to summary
public void addAllChildren(final Configuration other, final boolean deepCopy) throws ConfigurationException

Add all child Configuration objects from specified configuration element to current configuration element.

Parameters
other:Configuration

the other Configuration value throws ConfigurationException If there are any problems cloning the children.

deepCopy:boolean

true will cause clones of the children to be added, false will add the original instances and is thus faster.

addAllChildrenback to summary
public void addAllChildren(final Configuration other)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.addAllChildren.

Add all child Configuration objects from specified configuration element to current configuration element.

Parameters
other:Configuration

the other Configuration value

addAttributeback to summary
public String addAttribute(final String name, String value)

Deprecated

Use setAttribute() instead

Add an attribute to this configuration element, returning its old value or null.

Parameters
name:String

a String value

value:String

a String value

Returns:String

a String value

addChildback to summary
public void addChild(final Configuration configuration)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.addChild.

Add a child Configuration to this configuration element.

Parameters
configuration:Configuration

a Configuration value

appendValueDataback to summary
public void appendValueData(final String value)

Deprecated

Use setValue() instead

Append data to the value of this configuration element.

Parameters
value:String

a String value

checkback to summary
private boolean check(Object one, Object two)
checkWriteableback to summary
protected final void checkWriteable() throws IllegalStateException

heck if this configuration is writeable.

Exceptions
IllegalStateException:
if this configuration s read-only
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Compare if this configuration is equal to another.

Parameters
other:Object

The other configuration

Returns:boolean

true if they are the same.

getAttributeback to summary
public String getAttribute(final String name) throws ConfigurationException

Implements org.apache.avalon.framework.configuration.Configuration.getAttribute.

Returns the value of the attribute specified by its name as a String.

Parameters
name:String

a String value

Returns:String

a String value

Exceptions
ConfigurationException:
If the attribute is not present.
getAttributeNamesback to summary
public String[] getAttributeNames()

Implements org.apache.avalon.framework.configuration.Configuration.getAttributeNames.

Return an array of all attribute names.

Returns:String[]

a String[] value

getChildback to summary
public Configuration getChild(final String name, final boolean createNew)

Overrides org.apache.avalon.framework.configuration.AbstractConfiguration.getChild.

Implements org.apache.avalon.framework.configuration.Configuration.getChild.

Return the first Configuration object child of this associated with the given name.

Parameters
name:String

a String value

createNew:boolean

a boolean value

Returns:Configuration

a Configuration value

getChildCountback to summary
public int getChildCount()

Return count of children.

Returns:int

an int value

getChildrenback to summary
public Configuration[] getChildren()

Implements org.apache.avalon.framework.configuration.Configuration.getChildren.

Return an array of Configuration elements containing all node children.

Returns:Configuration[]

The child nodes with name

getChildrenback to summary
public Configuration[] getChildren(final String name)

Implements org.apache.avalon.framework.configuration.Configuration.getChildren.

Return an array of Configuration objects children of this associated with the given name.
The returned array may be empty but is never null.

Parameters
name:String

The name of the required children Configuration.

Returns:Configuration[]

a Configuration[] value

getLocationback to summary
public String getLocation()

Implements org.apache.avalon.framework.configuration.Configuration.getLocation.

Returns a description of location of element.

Returns:String

a String value

getMutableChildback to summary
public MutableConfiguration getMutableChild(final String name) throws ConfigurationException

Implements org.apache.avalon.framework.configuration.MutableConfiguration.getMutableChild.

Doc from org.apache.avalon.framework.configuration.MutableConfiguration.getMutableChild.

Equivalent to getMutableChild( name, true )

getMutableChildback to summary
public MutableConfiguration getMutableChild(final String name, boolean autoCreate) throws ConfigurationException

Implements org.apache.avalon.framework.configuration.MutableConfiguration.getMutableChild.

Doc from org.apache.avalon.framework.configuration.MutableConfiguration.getMutableChild.

Gets a child node of this configuration. If a mutable child with the given name exists, it is returned. If an immutable child with the given name exists, it is converted into a mutable child and returned. In this case, the immutable child will be replaced with the mutable child in this configuration (that is, it will be as if the child node always had been mutable). If no child with the given name exists, and autoCreate is true, a new mutable child is created and added to this configuration before being returned.

Parameters
name:String

the name of the child.

autoCreate:boolean

set to true to create the child node if it doesn't exist.

Returns:MutableConfiguration

the child MutableConfiguration, or null if autoCreate was false and no child by the given name existed.

Exceptions
ConfigurationException:
if an error occurrs.
getMutableChildrenback to summary
public MutableConfiguration[] getMutableChildren() throws ConfigurationException

Implements org.apache.avalon.framework.configuration.MutableConfiguration.getMutableChildren.

Doc from org.apache.avalon.framework.configuration.MutableConfiguration.getMutableChildren.

Returns an array of mutable children. Immutable children are converted just as for getMutableChild.

Exceptions
ConfigurationException:
if an error occurrs.
getMutableChildrenback to summary
public MutableConfiguration[] getMutableChildren(final String name) throws ConfigurationException

Implements org.apache.avalon.framework.configuration.MutableConfiguration.getMutableChildren.

Doc from org.apache.avalon.framework.configuration.MutableConfiguration.getMutableChildren.

Returns an array of mutable children with the given name. Immutable children are converted just as for getMutableChild.

Exceptions
ConfigurationException:
if an error occurrs.
getNameback to summary
public String getName()

Implements org.apache.avalon.framework.configuration.Configuration.getName.

Returns the name of this configuration element.

Returns:String

a String value

getNamespaceback to summary
public String getNamespace() throws ConfigurationException

Implements org.apache.avalon.framework.configuration.Configuration.getNamespace.

Returns the namespace of this configuration element

Returns:String

a String value

Exceptions
ConfigurationException:
if an error occurs
Since
4.1
getPrefixback to summary
protected String getPrefix() throws ConfigurationException

Implements abstract org.apache.avalon.framework.configuration.AbstractConfiguration.getPrefix.

Returns the prefix of the namespace

Returns:String

a String value

Exceptions
ConfigurationException:
if prefix is not present (null).
Since
4.1
getValueback to summary
public String getValue(final String defaultValue)

Overrides org.apache.avalon.framework.configuration.AbstractConfiguration.getValue.

Implements org.apache.avalon.framework.configuration.Configuration.getValue.

Returns the value of the configuration element as a String.

Parameters
defaultValue:String

the default value to return if value malformed or empty

Returns:String

a String value

getValueback to summary
public String getValue() throws ConfigurationException

Implements org.apache.avalon.framework.configuration.Configuration.getValue.

Returns the value of the configuration element as a String.

Returns:String

a String value

Exceptions
ConfigurationException:
If the value is not present.
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Obtaine the hashcode for this configuration.

Returns:int

the hashcode.

isReadOnlyback to summary
protected final boolean isReadOnly()

Returns true iff this DefaultConfiguration has been made read-only.

makeReadOnlyback to summary
public void makeReadOnly()

Make this configuration read-only.

removeChildback to summary
public void removeChild(final Configuration configuration)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.removeChild.

Remove a child Configuration to this configuration element.

Parameters
configuration:Configuration

a Configuration value

setAttributeback to summary
public void setAttribute(final String name, final String value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified string.

Parameters
name:String

name of the attribute to set

value:String

a String value

setAttributeback to summary
public void setAttribute(final String name, final int value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified int.

Parameters
name:String

name of the attribute to set

value:int

an int value

setAttributeback to summary
public void setAttribute(final String name, final long value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified long.

Parameters
name:String

name of the attribute to set

value:long

an long value

setAttributeback to summary
public void setAttribute(final String name, final boolean value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified boolean.

Parameters
name:String

name of the attribute to set

value:boolean

an boolean value

setAttributeback to summary
public void setAttribute(final String name, final float value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified float.

Parameters
name:String

name of the attribute to set

value:float

an float value

setAttributeback to summary
public void setAttribute(final String name, final double value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setAttribute.

Set the value of the specified attribute to the specified double.

Parameters
name:String

name of the attribute to set

value:double

an double value

setValueback to summary
public void setValue(final String value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified string.

Parameters
value:String

a String value

setValueback to summary
public void setValue(final int value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified int.

Parameters
value:int

a int value

setValueback to summary
public void setValue(final long value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified long.

Parameters
value:long

a long value

setValueback to summary
public void setValue(final boolean value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified boolean.

Parameters
value:boolean

a boolean value

setValueback to summary
public void setValue(final float value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified float.

Parameters
value:float

a float value

setValueback to summary
public void setValue(final double value)

Implements org.apache.avalon.framework.configuration.MutableConfiguration.setValue.

Set the value of this Configuration object to the specified double.

Parameters
value:double

a double value

toMutableback to summary
private MutableConfiguration toMutable(Configuration child) throws ConfigurationException

Convenience function to convert a child to a mutable configuration. If the child is-a MutableConfiguration, and it isn't a read-only DefaultConfiguration (which isn't really mutable), the child is cast to MutableConfiguration and returned. If not, the child is replaced in the m_children array with a new writable DefaultConfiguration that is a shallow copy of the child, and the new child is returned.