org.apache.avalon.framework.configuration
Class DefaultConfiguration

java.lang.Object
  extended byorg.apache.avalon.framework.configuration.AbstractConfiguration
      extended byorg.apache.avalon.framework.configuration.DefaultConfiguration
All Implemented Interfaces:
Configuration, MutableConfiguration, java.io.Serializable

public class DefaultConfiguration
extends AbstractConfiguration
implements MutableConfiguration, java.io.Serializable

This is the default Configuration implementation.

Version:
$Id: DefaultConfiguration.java 160878 2005-04-11 13:59:59Z leif $
Author:
Avalon Development Team
See Also:
Serialized Form

Field Summary
protected static Configuration[] EMPTY_ARRAY
          An empty (length zero) array of configuration objects.
 
Constructor Summary
DefaultConfiguration(Configuration config)
          Shallow copy constructor, suitable for craeting a writable clone of a read-only configuration.
DefaultConfiguration(Configuration config, boolean deepCopy)
          Copy constructor, to create a clone of another configuration.
DefaultConfiguration(java.lang.String name)
          Create a new DefaultConfiguration instance.
DefaultConfiguration(java.lang.String name, java.lang.String location)
          Create a new DefaultConfiguration instance.
DefaultConfiguration(java.lang.String name, java.lang.String location, java.lang.String ns, java.lang.String prefix)
          Create a new DefaultConfiguration instance.
 
Method Summary
 void addAll(Configuration other)
          Add all the attributes, children and value from specified configuration element to current configuration element.
 void addAll(Configuration other, boolean deepCopy)
          Add all the attributes, children and value from specified configuration element to current configuration element.
 void addAllAttributes(Configuration other)
          Add all attributes from specified configuration element to current configuration element.
 void addAllChildren(Configuration other)
          Add all child Configuration objects from specified configuration element to current configuration element.
 void addAllChildren(Configuration other, boolean deepCopy)
          Add all child Configuration objects from specified configuration element to current configuration element.
 java.lang.String addAttribute(java.lang.String name, java.lang.String value)
          Deprecated. Use setAttribute() instead
 void addChild(Configuration configuration)
          Add a child Configuration to this configuration element.
 void appendValueData(java.lang.String value)
          Deprecated. Use setValue() instead
protected  void checkWriteable()
          heck if this configuration is writeable.
 boolean equals(java.lang.Object other)
          Compare if this configuration is equal to another.
 java.lang.String getAttribute(java.lang.String name)
          Returns the value of the attribute specified by its name as a String.
 java.lang.String[] getAttributeNames()
          Return an array of all attribute names.
 Configuration getChild(java.lang.String name, boolean createNew)
          Return the first Configuration object child of this associated with the given name.
 int getChildCount()
          Return count of children.
 Configuration[] getChildren()
          Return an array of Configuration elements containing all node children.
 Configuration[] getChildren(java.lang.String name)
          Return an array of Configuration objects children of this associated with the given name.
 java.lang.String getLocation()
          Returns a description of location of element.
 MutableConfiguration getMutableChild(java.lang.String name)
          Equivalent to getMutableChild( name, true )
 MutableConfiguration getMutableChild(java.lang.String name, boolean autoCreate)
          Gets a child node of this configuration.
 MutableConfiguration[] getMutableChildren()
          Returns an array of mutable children.
 MutableConfiguration[] getMutableChildren(java.lang.String name)
          Returns an array of mutable children with the given name.
 java.lang.String getName()
          Returns the name of this configuration element.
 java.lang.String getNamespace()
          Returns the namespace of this configuration element
protected  java.lang.String getPrefix()
          Returns the prefix of the namespace
 java.lang.String getValue()
          Returns the value of the configuration element as a String.
 java.lang.String getValue(java.lang.String defaultValue)
          Returns the value of the configuration element as a String.
 int hashCode()
          Obtaine the hashcode for this configuration.
protected  boolean isReadOnly()
          Returns true iff this DefaultConfiguration has been made read-only.
 void makeReadOnly()
          Make this configuration read-only.
 void removeChild(Configuration configuration)
          Remove a child Configuration to this configuration element.
 void setAttribute(java.lang.String name, boolean value)
          Set the value of the specified attribute to the specified boolean.
 void setAttribute(java.lang.String name, double value)
          Set the value of the specified attribute to the specified double.
 void setAttribute(java.lang.String name, float value)
          Set the value of the specified attribute to the specified float.
 void setAttribute(java.lang.String name, int value)
          Set the value of the specified attribute to the specified int.
 void setAttribute(java.lang.String name, long value)
          Set the value of the specified attribute to the specified long.
 void setAttribute(java.lang.String name, java.lang.String value)
          Set the value of the specified attribute to the specified string.
 void setValue(boolean value)
          Set the value of this Configuration object to the specified boolean.
 void setValue(double value)
          Set the value of this Configuration object to the specified double.
 void setValue(float value)
          Set the value of this Configuration object to the specified float.
 void setValue(int value)
          Set the value of this Configuration object to the specified int.
 void setValue(long value)
          Set the value of this Configuration object to the specified long.
 void setValue(java.lang.String value)
          Set the value of this Configuration object to the specified string.
 
Methods inherited from class org.apache.avalon.framework.configuration.AbstractConfiguration
getAttribute, getAttributeAsBoolean, getAttributeAsBoolean, getAttributeAsDouble, getAttributeAsDouble, getAttributeAsFloat, getAttributeAsFloat, getAttributeAsInteger, getAttributeAsInteger, getAttributeAsLong, getAttributeAsLong, getChild, getValueAsBoolean, getValueAsBoolean, getValueAsDouble, getValueAsDouble, getValueAsFloat, getValueAsFloat, getValueAsInteger, getValueAsInteger, getValueAsLong, getValueAsLong, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.avalon.framework.configuration.Configuration
getAttribute, getAttributeAsBoolean, getAttributeAsBoolean, getAttributeAsDouble, getAttributeAsDouble, getAttributeAsFloat, getAttributeAsFloat, getAttributeAsInteger, getAttributeAsInteger, getAttributeAsLong, getAttributeAsLong, getChild, getValueAsBoolean, getValueAsBoolean, getValueAsDouble, getValueAsDouble, getValueAsFloat, getValueAsFloat, getValueAsInteger, getValueAsInteger, getValueAsLong, getValueAsLong
 

Field Detail

EMPTY_ARRAY

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

Constructor Detail

DefaultConfiguration

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 - 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)
                     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 - the Configuration to copy
Throws:
ConfigurationException - if an error occurs when copying

DefaultConfiguration

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

Parameters:
name - a String value

DefaultConfiguration

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

Parameters:
name - a String value
location - a String value

DefaultConfiguration

public DefaultConfiguration(java.lang.String name,
                            java.lang.String location,
                            java.lang.String ns,
                            java.lang.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

getName

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

Specified by:
getName in interface Configuration
Returns:
a String value

getNamespace

public java.lang.String getNamespace()
                              throws ConfigurationException
Returns the namespace of this configuration element

Specified by:
getNamespace in interface Configuration
Returns:
a String value
Throws:
ConfigurationException - if an error occurs
Since:
4.1

getPrefix

protected java.lang.String getPrefix()
                              throws ConfigurationException
Returns the prefix of the namespace

Specified by:
getPrefix in class AbstractConfiguration
Returns:
a String value
Throws:
ConfigurationException - if prefix is not present (null).
Since:
4.1

getLocation

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

Specified by:
getLocation in interface Configuration
Returns:
a String value

getValue

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

Specified by:
getValue in interface Configuration
Overrides:
getValue in class AbstractConfiguration
Parameters:
defaultValue - the default value to return if value malformed or empty
Returns:
a String value

getValue

public java.lang.String getValue()
                          throws ConfigurationException
Returns the value of the configuration element as a String.

Specified by:
getValue in interface Configuration
Returns:
a String value
Throws:
ConfigurationException - If the value is not present.

getAttributeNames

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

Specified by:
getAttributeNames in interface Configuration
Returns:
a String[] value

getChildren

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

Specified by:
getChildren in interface Configuration
Returns:
The child nodes with name

getAttribute

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

Specified by:
getAttribute in interface Configuration
Parameters:
name - a String value
Returns:
a String value
Throws:
ConfigurationException - If the attribute is not present.

getChild

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

Specified by:
getChild in interface Configuration
Overrides:
getChild in class AbstractConfiguration
Parameters:
name - a String value
createNew - a boolean value
Returns:
a Configuration value

getChildren

public Configuration[] getChildren(java.lang.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.

Specified by:
getChildren in interface Configuration
Parameters:
name - The name of the required children Configuration.
Returns:
a Configuration[] value

appendValueData

public void appendValueData(java.lang.String value)
Deprecated. Use setValue() instead

Append data to the value of this configuration element.

Parameters:
value - a String value

setValue

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

Specified by:
setValue in interface MutableConfiguration
Parameters:
value - a String value

setValue

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

Specified by:
setValue in interface MutableConfiguration
Parameters:
value - a int value

setValue

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

Specified by:
setValue in interface MutableConfiguration
Parameters:
value - a long value

setValue

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

Specified by:
setValue in interface MutableConfiguration
Parameters:
value - a boolean value

setValue

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

Specified by:
setValue in interface MutableConfiguration
Parameters:
value - a float value

setValue

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

Specified by:
setValue in interface MutableConfiguration
Parameters:
value - a double value

setAttribute

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

Specified by:
setAttribute in interface MutableConfiguration
Parameters:
name - name of the attribute to set
value - a String value

setAttribute

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

Specified by:
setAttribute in interface MutableConfiguration
Parameters:
name - name of the attribute to set
value - an int value

setAttribute

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

Specified by:
setAttribute in interface MutableConfiguration
Parameters:
name - name of the attribute to set
value - an long value

setAttribute

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

Specified by:
setAttribute in interface MutableConfiguration
Parameters:
name - name of the attribute to set
value - an boolean value

setAttribute

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

Specified by:
setAttribute in interface MutableConfiguration
Parameters:
name - name of the attribute to set
value - an float value

setAttribute

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

Specified by:
setAttribute in interface MutableConfiguration
Parameters:
name - name of the attribute to set
value - an double value

addAttribute

public java.lang.String addAttribute(java.lang.String name,
                                     java.lang.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.

Specified by:
addChild in interface MutableConfiguration
Parameters:
configuration - a Configuration value

addAll

public void addAll(Configuration other,
                   boolean deepCopy)
            throws ConfigurationException
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.
Throws:
ConfigurationException

addAll

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

Specified by:
addAll in interface MutableConfiguration
Parameters:
other - the Configuration element

addAllAttributes

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

Specified by:
addAllAttributes in interface MutableConfiguration
Parameters:
other - the Configuration element

addAllChildren

public void addAllChildren(Configuration other,
                           boolean deepCopy)
                    throws ConfigurationException
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.
Throws:
ConfigurationException

addAllChildren

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

Specified by:
addAllChildren in interface MutableConfiguration
Parameters:
other - the other Configuration value

removeChild

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

Specified by:
removeChild in interface MutableConfiguration
Parameters:
configuration - a Configuration value

getChildCount

public int getChildCount()
Return count of children.

Returns:
an int value

makeReadOnly

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


checkWriteable

protected final void checkWriteable()
                             throws java.lang.IllegalStateException
heck if this configuration is writeable.

Throws:
java.lang.IllegalStateException - if this configuration s read-only

isReadOnly

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


getMutableChild

public MutableConfiguration getMutableChild(java.lang.String name)
                                     throws ConfigurationException
Description copied from interface: MutableConfiguration
Equivalent to getMutableChild( name, true )

Specified by:
getMutableChild in interface MutableConfiguration
Throws:
ConfigurationException

getMutableChild

public MutableConfiguration getMutableChild(java.lang.String name,
                                            boolean autoCreate)
                                     throws ConfigurationException
Description copied from interface: MutableConfiguration
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.

Specified by:
getMutableChild in interface MutableConfiguration
Parameters:
name - the name of the child.
autoCreate - set to true to create the child node if it doesn't exist.
Returns:
the child MutableConfiguration, or null if autoCreate was false and no child by the given name existed.
Throws:
ConfigurationException - if an error occurrs.

getMutableChildren

public MutableConfiguration[] getMutableChildren()
                                          throws ConfigurationException
Description copied from interface: MutableConfiguration
Returns an array of mutable children. Immutable children are converted just as for getMutableChild.

Specified by:
getMutableChildren in interface MutableConfiguration
Throws:
ConfigurationException - if an error occurrs.

getMutableChildren

public MutableConfiguration[] getMutableChildren(java.lang.String name)
                                          throws ConfigurationException
Description copied from interface: MutableConfiguration
Returns an array of mutable children with the given name. Immutable children are converted just as for getMutableChild.

Specified by:
getMutableChildren in interface MutableConfiguration
Throws:
ConfigurationException - if an error occurrs.

equals

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

Parameters:
other - The other configuration
Returns:
true if they are the same.

hashCode

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

Returns:
the hashcode.


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.