Class DefaultConfiguration
java.lang.Object
org.apache.avalon.framework.configuration.AbstractConfiguration
org.apache.avalon.framework.configuration.DefaultConfiguration
- All Implemented Interfaces:
Serializable, org.apache.avalon.framework.configuration.Configuration, MutableConfiguration
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
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.apache.avalon.framework.configuration.Configuration[]An empty (length zero) array of configuration objects.private HashMapprivate ArrayListprivate final Stringprivate final Stringprivate final Stringprivate final Stringprivate booleanprivate String -
Constructor Summary
ConstructorsConstructorDescriptionDefaultConfiguration(String name) Create a newDefaultConfigurationinstance.DefaultConfiguration(String name, String location) Create a newDefaultConfigurationinstance.DefaultConfiguration(String name, String location, String ns, String prefix) Create a newDefaultConfigurationinstance.DefaultConfiguration(org.apache.avalon.framework.configuration.Configuration config) Shallow copy constructor, suitable for craeting a writable clone of a read-only configuration.DefaultConfiguration(org.apache.avalon.framework.configuration.Configuration config, boolean deepCopy) Copy constructor, to create a clone of another configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAll(org.apache.avalon.framework.configuration.Configuration other) Add all the attributes, children and value from specified configuration element to current configuration element.voidaddAll(org.apache.avalon.framework.configuration.Configuration other, boolean deepCopy) Add all the attributes, children and value from specified configuration element to current configuration element.voidaddAllAttributes(org.apache.avalon.framework.configuration.Configuration other) Add all attributes from specified configuration element to current configuration element.voidaddAllChildren(org.apache.avalon.framework.configuration.Configuration other) Add all childConfigurationobjects from specified configuration element to current configuration element.voidaddAllChildren(org.apache.avalon.framework.configuration.Configuration other, boolean deepCopy) Add all childConfigurationobjects from specified configuration element to current configuration element.addAttribute(String name, String value) Deprecated.Use setAttribute() insteadvoidaddChild(org.apache.avalon.framework.configuration.Configuration configuration) Add a childConfigurationto this configuration element.voidappendValueData(String value) Deprecated.Use setValue() insteadprivate booleanprotected final voidheck if this configuration is writeable.booleanCompare if this configuration is equal to another.getAttribute(String name) Returns the value of the attribute specified by its name as aString.String[]Return an array of all attribute names.org.apache.avalon.framework.configuration.ConfigurationReturn the firstConfigurationobject child of this associated with the given name.intReturn count of children.org.apache.avalon.framework.configuration.Configuration[]Return an array ofConfigurationelements containing all node children.org.apache.avalon.framework.configuration.Configuration[]getChildren(String name) Return an array ofConfigurationobjects children of this associated with the given name.Returns a description of location of element.getMutableChild(String name) Equivalent togetMutableChild( name, true )getMutableChild(String name, boolean autoCreate) Gets a child node of this configuration.Returns an array of mutable children.getMutableChildren(String name) Returns an array of mutable children with the given name.getName()Returns the name of this configuration element.Returns the namespace of this configuration elementprotected StringReturns the prefix of the namespacegetValue()Returns the value of the configuration element as aString.Returns the value of the configuration element as aString.inthashCode()Obtaine the hashcode for this configuration.protected final booleanReturns true iff this DefaultConfiguration has been made read-only.voidMake this configuration read-only.voidremoveChild(org.apache.avalon.framework.configuration.Configuration configuration) Remove a childConfigurationto this configuration element.voidsetAttribute(String name, boolean value) Set the value of the specified attribute to the specified boolean.voidsetAttribute(String name, double value) Set the value of the specified attribute to the specified double.voidsetAttribute(String name, float value) Set the value of the specified attribute to the specified float.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, String value) Set the value of the specified attribute to the specified string.voidsetValue(boolean value) Set the value of thisConfigurationobject to the specified boolean.voidsetValue(double value) Set the value of thisConfigurationobject to the specified double.voidsetValue(float value) Set the value of thisConfigurationobject to the specified float.voidsetValue(int value) Set the value of thisConfigurationobject to the specified int.voidsetValue(long value) Set the value of thisConfigurationobject to the specified long.voidSet the value of thisConfigurationobject to the specified string.private MutableConfigurationtoMutable(org.apache.avalon.framework.configuration.Configuration child) Convenience function to convert a child to a mutable configuration.Methods inherited from class AbstractConfiguration
getAttribute, getAttributeAsBoolean, getAttributeAsBoolean, getAttributeAsDouble, getAttributeAsDouble, getAttributeAsFloat, getAttributeAsFloat, getAttributeAsInteger, getAttributeAsInteger, getAttributeAsLong, getAttributeAsLong, getChild, getValueAsBoolean, getValueAsBoolean, getValueAsDouble, getValueAsDouble, getValueAsFloat, getValueAsFloat, getValueAsInteger, getValueAsInteger, getValueAsLong, getValueAsLong, toStringMethods 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 Details
-
EMPTY_ARRAY
protected static final org.apache.avalon.framework.configuration.Configuration[] EMPTY_ARRAYAn empty (length zero) array of configuration objects. -
m_name
-
m_location
-
m_namespace
-
m_prefix
-
m_attributes
-
m_children
-
m_value
-
m_readOnly
private boolean m_readOnly
-
-
Constructor Details
-
DefaultConfiguration
public DefaultConfiguration(org.apache.avalon.framework.configuration.Configuration config, boolean deepCopy) throws org.apache.avalon.framework.configuration.ConfigurationException Copy constructor, to create a clone of another configuration. To modify children, usegetChild(),removeChild()andaddChild().- Parameters:
config- theConfigurationto copydeepCopy- true will cause clones of the children to be added, false will add the original instances and is thus faster.- Throws:
org.apache.avalon.framework.configuration.ConfigurationException- if an error occurs when copying
-
DefaultConfiguration
public DefaultConfiguration(org.apache.avalon.framework.configuration.Configuration config) throws org.apache.avalon.framework.configuration.ConfigurationException Shallow copy constructor, suitable for craeting a writable clone of a read-only configuration. To modify children, usegetChild(),removeChild()andaddChild().- Parameters:
config- theConfigurationto copy- Throws:
org.apache.avalon.framework.configuration.ConfigurationException- if an error occurs when copying
-
DefaultConfiguration
Create a newDefaultConfigurationinstance.- Parameters:
name- aStringvalue
-
DefaultConfiguration
-
DefaultConfiguration
Create a newDefaultConfigurationinstance.- Parameters:
name- config node namelocation- Builder-specific locator stringns- 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 Details
-
getName
Returns the name of this configuration element.- Specified by:
getNamein interfaceorg.apache.avalon.framework.configuration.Configuration- Returns:
- a
Stringvalue
-
getNamespace
public String getNamespace() throws org.apache.avalon.framework.configuration.ConfigurationExceptionReturns the namespace of this configuration element- Specified by:
getNamespacein interfaceorg.apache.avalon.framework.configuration.Configuration- Returns:
- a
Stringvalue - Throws:
org.apache.avalon.framework.configuration.ConfigurationException- if an error occurs- Since:
- 4.1
-
getPrefix
protected String getPrefix() throws org.apache.avalon.framework.configuration.ConfigurationExceptionReturns the prefix of the namespace- Specified by:
getPrefixin classAbstractConfiguration- Returns:
- a
Stringvalue - Throws:
org.apache.avalon.framework.configuration.ConfigurationException- if prefix is not present (null).- Since:
- 4.1
-
getLocation
Returns a description of location of element.- Specified by:
getLocationin interfaceorg.apache.avalon.framework.configuration.Configuration- Returns:
- a
Stringvalue
-
getValue
Returns the value of the configuration element as aString.- Specified by:
getValuein interfaceorg.apache.avalon.framework.configuration.Configuration- Overrides:
getValuein classAbstractConfiguration- Parameters:
defaultValue- the default value to return if value malformed or empty- Returns:
- a
Stringvalue
-
getValue
Returns the value of the configuration element as aString.- Specified by:
getValuein interfaceorg.apache.avalon.framework.configuration.Configuration- Returns:
- a
Stringvalue - Throws:
org.apache.avalon.framework.configuration.ConfigurationException- If the value is not present.
-
getAttributeNames
Return an array of all attribute names.- Specified by:
getAttributeNamesin interfaceorg.apache.avalon.framework.configuration.Configuration- Returns:
- a
String[]value
-
getChildren
public org.apache.avalon.framework.configuration.Configuration[] getChildren()Return an array ofConfigurationelements containing all node children.- Specified by:
getChildrenin interfaceorg.apache.avalon.framework.configuration.Configuration- Returns:
- The child nodes with name
-
getAttribute
public String getAttribute(String name) throws org.apache.avalon.framework.configuration.ConfigurationException Returns the value of the attribute specified by its name as aString.- Specified by:
getAttributein interfaceorg.apache.avalon.framework.configuration.Configuration- Parameters:
name- aStringvalue- Returns:
- a
Stringvalue - Throws:
org.apache.avalon.framework.configuration.ConfigurationException- If the attribute is not present.
-
getChild
public org.apache.avalon.framework.configuration.Configuration getChild(String name, boolean createNew) Return the firstConfigurationobject child of this associated with the given name.- Specified by:
getChildin interfaceorg.apache.avalon.framework.configuration.Configuration- Overrides:
getChildin classAbstractConfiguration- Parameters:
name- aStringvaluecreateNew- abooleanvalue- Returns:
- a
Configurationvalue
-
getChildren
Return an array ofConfigurationobjects children of this associated with the given name.
The returned array may be empty but is nevernull.- Specified by:
getChildrenin interfaceorg.apache.avalon.framework.configuration.Configuration- Parameters:
name- The name of the required childrenConfiguration.- Returns:
- a
Configuration[]value
-
appendValueData
Deprecated.Use setValue() insteadAppend data to the value of this configuration element.- Parameters:
value- aStringvalue
-
setValue
Set the value of thisConfigurationobject to the specified string.- Specified by:
setValuein interfaceMutableConfiguration- Parameters:
value- aStringvalue
-
setValue
public void setValue(int value) Set the value of thisConfigurationobject to the specified int.- Specified by:
setValuein interfaceMutableConfiguration- Parameters:
value- aintvalue
-
setValue
public void setValue(long value) Set the value of thisConfigurationobject to the specified long.- Specified by:
setValuein interfaceMutableConfiguration- Parameters:
value- alongvalue
-
setValue
public void setValue(boolean value) Set the value of thisConfigurationobject to the specified boolean.- Specified by:
setValuein interfaceMutableConfiguration- Parameters:
value- abooleanvalue
-
setValue
public void setValue(float value) Set the value of thisConfigurationobject to the specified float.- Specified by:
setValuein interfaceMutableConfiguration- Parameters:
value- afloatvalue
-
setValue
public void setValue(double value) Set the value of thisConfigurationobject to the specified double.- Specified by:
setValuein interfaceMutableConfiguration- Parameters:
value- adoublevalue
-
setAttribute
Set the value of the specified attribute to the specified string.- Specified by:
setAttributein interfaceMutableConfiguration- Parameters:
name- name of the attribute to setvalue- aStringvalue
-
setAttribute
Set the value of the specified attribute to the specified int.- Specified by:
setAttributein interfaceMutableConfiguration- Parameters:
name- name of the attribute to setvalue- anintvalue
-
setAttribute
Set the value of the specified attribute to the specified long.- Specified by:
setAttributein interfaceMutableConfiguration- Parameters:
name- name of the attribute to setvalue- anlongvalue
-
setAttribute
Set the value of the specified attribute to the specified boolean.- Specified by:
setAttributein interfaceMutableConfiguration- Parameters:
name- name of the attribute to setvalue- anbooleanvalue
-
setAttribute
Set the value of the specified attribute to the specified float.- Specified by:
setAttributein interfaceMutableConfiguration- Parameters:
name- name of the attribute to setvalue- anfloatvalue
-
setAttribute
Set the value of the specified attribute to the specified double.- Specified by:
setAttributein interfaceMutableConfiguration- Parameters:
name- name of the attribute to setvalue- andoublevalue
-
addAttribute
-
addChild
public void addChild(org.apache.avalon.framework.configuration.Configuration configuration) Add a childConfigurationto this configuration element.- Specified by:
addChildin interfaceMutableConfiguration- Parameters:
configuration- aConfigurationvalue
-
addAll
public void addAll(org.apache.avalon.framework.configuration.Configuration other, boolean deepCopy) throws org.apache.avalon.framework.configuration.ConfigurationException Add all the attributes, children and value from specified configuration element to current configuration element.- Parameters:
other- theConfigurationelementdeepCopy- 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:
org.apache.avalon.framework.configuration.ConfigurationException
-
addAll
public void addAll(org.apache.avalon.framework.configuration.Configuration other) Add all the attributes, children and value from specified configuration element to current configuration element.- Specified by:
addAllin interfaceMutableConfiguration- Parameters:
other- theConfigurationelement
-
addAllAttributes
public void addAllAttributes(org.apache.avalon.framework.configuration.Configuration other) Add all attributes from specified configuration element to current configuration element.- Specified by:
addAllAttributesin interfaceMutableConfiguration- Parameters:
other- theConfigurationelement
-
addAllChildren
public void addAllChildren(org.apache.avalon.framework.configuration.Configuration other, boolean deepCopy) throws org.apache.avalon.framework.configuration.ConfigurationException Add all childConfigurationobjects from specified configuration element to current configuration element.- Parameters:
other- the otherConfigurationvalue throws ConfigurationException If there are any problems cloning the children.deepCopy- true will cause clones of the children to be added, false will add the original instances and is thus faster.- Throws:
org.apache.avalon.framework.configuration.ConfigurationException
-
addAllChildren
public void addAllChildren(org.apache.avalon.framework.configuration.Configuration other) Add all childConfigurationobjects from specified configuration element to current configuration element.- Specified by:
addAllChildrenin interfaceMutableConfiguration- Parameters:
other- the otherConfigurationvalue
-
removeChild
public void removeChild(org.apache.avalon.framework.configuration.Configuration configuration) Remove a childConfigurationto this configuration element.- Specified by:
removeChildin interfaceMutableConfiguration- Parameters:
configuration- aConfigurationvalue
-
getChildCount
public int getChildCount()Return count of children.- Returns:
- an
intvalue
-
makeReadOnly
public void makeReadOnly()Make this configuration read-only. -
checkWriteable
heck if this configuration is writeable.- Throws:
IllegalStateException- if this configuration s read-only
-
isReadOnly
protected final boolean isReadOnly()Returns true iff this DefaultConfiguration has been made read-only. -
toMutable
private MutableConfiguration toMutable(org.apache.avalon.framework.configuration.Configuration child) throws org.apache.avalon.framework.configuration.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.- Throws:
org.apache.avalon.framework.configuration.ConfigurationException
-
getMutableChild
public MutableConfiguration getMutableChild(String name) throws org.apache.avalon.framework.configuration.ConfigurationException Description copied from interface:MutableConfigurationEquivalent togetMutableChild( name, true )- Specified by:
getMutableChildin interfaceMutableConfiguration- Throws:
org.apache.avalon.framework.configuration.ConfigurationException
-
getMutableChild
public MutableConfiguration getMutableChild(String name, boolean autoCreate) throws org.apache.avalon.framework.configuration.ConfigurationException Description copied from interface:MutableConfigurationGets 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, andautoCreateistrue, a new mutable child is created and added to this configuration before being returned.- Specified by:
getMutableChildin interfaceMutableConfiguration- 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
nullifautoCreatewas false and no child by the given name existed. - Throws:
org.apache.avalon.framework.configuration.ConfigurationException- if an error occurrs.
-
getMutableChildren
public MutableConfiguration[] getMutableChildren() throws org.apache.avalon.framework.configuration.ConfigurationExceptionDescription copied from interface:MutableConfigurationReturns an array of mutable children. Immutable children are converted just as forgetMutableChild.- Specified by:
getMutableChildrenin interfaceMutableConfiguration- Throws:
org.apache.avalon.framework.configuration.ConfigurationException- if an error occurrs.
-
getMutableChildren
public MutableConfiguration[] getMutableChildren(String name) throws org.apache.avalon.framework.configuration.ConfigurationException Description copied from interface:MutableConfigurationReturns an array of mutable children with the given name. Immutable children are converted just as forgetMutableChild.- Specified by:
getMutableChildrenin interfaceMutableConfiguration- Throws:
org.apache.avalon.framework.configuration.ConfigurationException- if an error occurrs.
-
equals
-
check
-
hashCode
-