org.apache.avalon.framework.configuration

Class DefaultConfiguration

public class DefaultConfiguration extends AbstractConfiguration implements MutableConfiguration, Serializable

This is the default Configuration implementation.

Version: $Id: DefaultConfiguration.java 160878 2005-04-11 08:59:59 -0500 (Mon, 11 Apr 2005) leif $

Author: Avalon Development Team

Field Summary
protected static Configuration[]EMPTY_ARRAY
An empty (length zero) array of configuration objects.
HashMapm_attributes
ArrayListm_children
Stringm_location
Stringm_name
Stringm_namespace
Stringm_prefix
booleanm_readOnly
Stringm_value
Constructor Summary
DefaultConfiguration(Configuration config, boolean deepCopy)
Copy constructor, to create a clone of another configuration.
DefaultConfiguration(Configuration config)
Shallow copy constructor, suitable for craeting a writable clone of a read-only configuration.
DefaultConfiguration(String name)
Create a new DefaultConfiguration instance.
DefaultConfiguration(String name, String location)
Create a new DefaultConfiguration instance.
DefaultConfiguration(String name, String location, String ns, String prefix)
Create a new DefaultConfiguration instance.
Method Summary
voidaddAll(Configuration other, boolean deepCopy)
Add all the attributes, children and value from specified configuration element to current configuration element.
voidaddAll(Configuration other)
Add all the attributes, children and value from specified configuration element to current configuration element.
voidaddAllAttributes(Configuration other)
Add all attributes from specified configuration element to current configuration element.
voidaddAllChildren(Configuration other, boolean deepCopy)
Add all child Configuration objects from specified configuration element to current configuration element.
voidaddAllChildren(Configuration other)
Add all child Configuration objects from specified configuration element to current configuration element.
StringaddAttribute(String name, String value)
Add an attribute to this configuration element, returning its old value or null.
voidaddChild(Configuration configuration)
Add a child Configuration to this configuration element.
voidappendValueData(String value)
Append data to the value of this configuration element.
booleancheck(Object one, Object two)
protected voidcheckWriteable()
heck if this configuration is writeable.
booleanequals(Object other)
Compare if this configuration is equal to another.
StringgetAttribute(String name)
Returns the value of the attribute specified by its name as a String.
String[]getAttributeNames()
Return an array of all attribute names.
ConfigurationgetChild(String name, boolean createNew)
Return the first Configuration object child of this associated with the given name.
intgetChildCount()
Return count of children.
Configuration[]getChildren()
Return an array of Configuration elements containing all node children.
Configuration[]getChildren(String name)
Return an array of Configuration objects children of this associated with the given name.
StringgetLocation()
Returns a description of location of element.
MutableConfigurationgetMutableChild(String name)
MutableConfigurationgetMutableChild(String name, boolean autoCreate)
MutableConfiguration[]getMutableChildren()
MutableConfiguration[]getMutableChildren(String name)
StringgetName()
Returns the name of this configuration element.
StringgetNamespace()
Returns the namespace of this configuration element
protected StringgetPrefix()
Returns the prefix of the namespace
StringgetValue(String defaultValue)
Returns the value of the configuration element as a String.
StringgetValue()
Returns the value of the configuration element as a String.
inthashCode()
Obtaine the hashcode for this configuration.
protected booleanisReadOnly()
Returns true iff this DefaultConfiguration has been made read-only.
voidmakeReadOnly()
Make this configuration read-only.
voidremoveChild(Configuration configuration)
Remove a child Configuration to this configuration element.
voidsetAttribute(String name, String value)
Set the value of the specified attribute to the specified string.
voidsetAttribute(String name, int value)
Set the value of the specified attribute to the specified int.
voidsetAttribute(String name, long value)
Set the value of the specified attribute to the specified long.
voidsetAttribute(String name, boolean value)
Set the value of the specified attribute to the specified boolean.
voidsetAttribute(String name, float value)
Set the value of the specified attribute to the specified float.
voidsetAttribute(String name, double value)
Set the value of the specified attribute to the specified double.
voidsetValue(String value)
Set the value of this Configuration object to the specified string.
voidsetValue(int value)
Set the value of this Configuration object to the specified int.
voidsetValue(long value)
Set the value of this Configuration object to the specified long.
voidsetValue(boolean value)
Set the value of this Configuration object to the specified boolean.
voidsetValue(float value)
Set the value of this Configuration object to the specified float.
voidsetValue(double value)
Set the value of this Configuration object to the specified double.
MutableConfigurationtoMutable(Configuration child)
Convenience function to convert a child to a mutable configuration.

Field Detail

EMPTY_ARRAY

protected static final Configuration[] EMPTY_ARRAY
An empty (length zero) array of configuration objects.

m_attributes

private HashMap m_attributes

m_children

private ArrayList m_children

m_location

private final String m_location

m_name

private final String m_name

m_namespace

private final String m_namespace

m_prefix

private final String m_prefix

m_readOnly

private boolean m_readOnly

m_value

private String m_value

Constructor Detail

DefaultConfiguration

public DefaultConfiguration(Configuration config, boolean deepCopy)
Copy constructor, to create a clone of another configuration. To modify children, use getChild(), removeChild() and addChild().

Parameters: config the Configuration to copy deepCopy true will cause clones of the children to be added, false will add the original instances and is thus faster.

Throws: ConfigurationException if an error occurs when copying

DefaultConfiguration

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

Parameters: config the Configuration to copy

Throws: ConfigurationException if an error occurs when copying

DefaultConfiguration

public DefaultConfiguration(String name)
Create a new DefaultConfiguration instance.

Parameters: name a String value

DefaultConfiguration

public DefaultConfiguration(String name, String location)
Create a new DefaultConfiguration instance.

Parameters: name a String value location a String value

DefaultConfiguration

public DefaultConfiguration(String name, String location, String ns, String prefix)
Create a new DefaultConfiguration instance.

Parameters: name config node name location Builder-specific locator string ns Namespace string (typically a URI). Should not be null; use "" if no namespace. prefix 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

addAll

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

Parameters: other the Configuration element deepCopy 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.

addAll

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

Parameters: other the Configuration element

addAllAttributes

public void addAllAttributes(Configuration other)
Add all attributes from specified configuration element to current configuration element.

Parameters: other the Configuration element

addAllChildren

public void addAllChildren(Configuration other, boolean deepCopy)
Add all child Configuration objects from specified configuration element to current configuration element.

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

addAllChildren

public void addAllChildren(Configuration other)
Add all child Configuration objects from specified configuration element to current configuration element.

Parameters: other the other Configuration value

addAttribute

public String addAttribute(String name, String value)

Deprecated: Use setAttribute() instead

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

Parameters: name a String value value a String value

Returns: a String value

addChild

public void addChild(Configuration configuration)
Add a child Configuration to this configuration element.

Parameters: configuration a Configuration value

appendValueData

public void appendValueData(String value)

Deprecated: Use setValue() instead

Append data to the value of this configuration element.

Parameters: value a String value

check

private boolean check(Object one, Object two)

checkWriteable

protected final void checkWriteable()
heck if this configuration is writeable.

Throws: IllegalStateException if this configuration s read-only

equals

public boolean equals(Object other)
Compare if this configuration is equal to another.

Parameters: other The other configuration

Returns: true if they are the same.

getAttribute

public String getAttribute(String name)
Returns the value of the attribute specified by its name as a String.

Parameters: name a String value

Returns: a String value

Throws: ConfigurationException If the attribute is not present.

getAttributeNames

public String[] getAttributeNames()
Return an array of all attribute names.

Returns: a String[] value

getChild

public Configuration getChild(String name, boolean createNew)
Return the first Configuration object child of this associated with the given name.

Parameters: name a String value createNew a boolean value

Returns: a Configuration value

getChildCount

public int getChildCount()
Return count of children.

Returns: an int value

getChildren

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

Returns: The child nodes with name

getChildren

public Configuration[] getChildren(String name)
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 The name of the required children Configuration.

Returns: a Configuration[] value

getLocation

public String getLocation()
Returns a description of location of element.

Returns: a String value

getMutableChild

public MutableConfiguration getMutableChild(String name)

getMutableChild

public MutableConfiguration getMutableChild(String name, boolean autoCreate)

getMutableChildren

public MutableConfiguration[] getMutableChildren()

getMutableChildren

public MutableConfiguration[] getMutableChildren(String name)

getName

public String getName()
Returns the name of this configuration element.

Returns: a String value

getNamespace

public String getNamespace()
Returns the namespace of this configuration element

Returns: a String value

Throws: ConfigurationException if an error occurs

Since: 4.1

getPrefix

protected String getPrefix()
Returns the prefix of the namespace

Returns: a String value

Throws: ConfigurationException if prefix is not present (null).

Since: 4.1

getValue

public String getValue(String defaultValue)
Returns the value of the configuration element as a String.

Parameters: defaultValue the default value to return if value malformed or empty

Returns: a String value

getValue

public String getValue()
Returns the value of the configuration element as a String.

Returns: a String value

Throws: ConfigurationException If the value is not present.

hashCode

public int hashCode()
Obtaine the hashcode for this configuration.

Returns: the hashcode.

isReadOnly

protected final boolean isReadOnly()
Returns true iff this DefaultConfiguration has been made read-only.

makeReadOnly

public void makeReadOnly()
Make this configuration read-only.

removeChild

public void removeChild(Configuration configuration)
Remove a child Configuration to this configuration element.

Parameters: configuration a Configuration value

setAttribute

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

Parameters: name name of the attribute to set value a String value

setAttribute

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

Parameters: name name of the attribute to set value an int value

setAttribute

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

Parameters: name name of the attribute to set value an long value

setAttribute

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

Parameters: name name of the attribute to set value an boolean value

setAttribute

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

Parameters: name name of the attribute to set value an float value

setAttribute

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

Parameters: name name of the attribute to set value an double value

setValue

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

Parameters: value a String value

setValue

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

Parameters: value a int value

setValue

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

Parameters: value a long value

setValue

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

Parameters: value a boolean value

setValue

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

Parameters: value a float value

setValue

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

Parameters: value a double value

toMutable

private MutableConfiguration toMutable(Configuration child)
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.