Class DefaultConfiguration
java.lang.Object
org.apache.avalon.framework.configuration.AbstractConfiguration
org.apache.avalon.framework.configuration.DefaultConfiguration
- All Implemented Interfaces:
Serializable
,Configuration
,MutableConfiguration
public class DefaultConfiguration
extends AbstractConfiguration
implements MutableConfiguration, Serializable
This is the default
Configuration
implementation.- Version:
- CVS $Revision: 1.43 $ $Date: 2004/02/11 14:34:25 $
- Author:
- Avalon Development Team
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Configuration[]
An empty (length zero) array of configuration objects. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultConfiguration
(String name) Create a newDefaultConfiguration
instance.DefaultConfiguration
(String name, String location) Create a newDefaultConfiguration
instance.DefaultConfiguration
(String name, String location, String ns, String prefix) Create a newDefaultConfiguration
instance.DefaultConfiguration
(Configuration config) Shallow copy constructor, suitable for craeting a writable clone of a read-only configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAll
(Configuration other) 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 childConfiguration
objects from specified configuration element to current configuration element.addAttribute
(String name, String value) Deprecated.Use setAttribute() insteadvoid
addChild
(Configuration configuration) Add a childConfiguration
to this configuration element.void
appendValueData
(String value) Deprecated.Use setValue() insteadprotected final void
heck if this configuration is writeable.boolean
Compare 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.Return the firstConfiguration
object child of this associated with the given name.int
Return count of children.Return an array ofConfiguration
elements containing all node children.getChildren
(String name) Return an array ofConfiguration
objects 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 String
Returns the prefix of the namespacegetValue()
Returns the value of the configuration element as aString
.Returns the value of the configuration element as aString
.int
hashCode()
Obtaine the hashcode for this configuration.protected final boolean
Returns true iff this DefaultConfiguration has been made read-only.void
Make this configuration read-only.void
removeChild
(Configuration configuration) Remove a childConfiguration
to this configuration element.void
setAttribute
(String name, boolean value) Set the value of the specified attribute to the specified boolean.void
setAttribute
(String name, float value) Set the value of the specified attribute to the specified float.void
setAttribute
(String name, int value) Set the value of the specified attribute to the specified int.void
setAttribute
(String name, long value) Set the value of the specified attribute to the specified long.void
setAttribute
(String name, String value) Set the value of the specified attribute to the specified string.void
setValue
(boolean value) Set the value of thisConfiguration
object to the specified boolean.void
setValue
(float value) Set the value of thisConfiguration
object to the specified float.void
setValue
(int value) Set the value of thisConfiguration
object to the specified int.void
setValue
(long value) Set the value of thisConfiguration
object to the specified long.void
Set the value of thisConfiguration
object to the specified string.Methods inherited from class org.apache.avalon.framework.configuration.AbstractConfiguration
getAttribute, getAttributeAsBoolean, getAttributeAsBoolean, getAttributeAsFloat, getAttributeAsFloat, getAttributeAsInteger, getAttributeAsInteger, getAttributeAsLong, getAttributeAsLong, getChild, getValueAsBoolean, getValueAsBoolean, 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, getAttributeAsFloat, getAttributeAsFloat, getAttributeAsInteger, getAttributeAsInteger, getAttributeAsLong, getAttributeAsLong, getChild, getValueAsBoolean, getValueAsBoolean, getValueAsFloat, getValueAsFloat, getValueAsInteger, getValueAsInteger, getValueAsLong, getValueAsLong
-
Field Details
-
EMPTY_ARRAY
An empty (length zero) array of configuration objects.
-
-
Constructor Details
-
DefaultConfiguration
Shallow copy constructor, suitable for craeting a writable clone of a read-only configuration. To modify children, usegetChild()
,removeChild()
andaddChild()
.- Parameters:
config
- theConfiguration
to copy- Throws:
ConfigurationException
- if an error occurs when copying
-
DefaultConfiguration
Create a newDefaultConfiguration
instance.- Parameters:
name
- aString
value
-
DefaultConfiguration
Create a newDefaultConfiguration
instance.- Parameters:
name
- aString
valuelocation
- aString
value
-
DefaultConfiguration
Create a newDefaultConfiguration
instance.- 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:
getName
in interfaceConfiguration
- Returns:
- a
String
value
-
getNamespace
Returns the namespace of this configuration element- Specified by:
getNamespace
in interfaceConfiguration
- Returns:
- a
String
value - Throws:
ConfigurationException
- if an error occurs- Since:
- 4.1
-
getPrefix
Returns the prefix of the namespace- Specified by:
getPrefix
in classAbstractConfiguration
- Returns:
- a
String
value - Throws:
ConfigurationException
- if prefix is not present (null
).- Since:
- 4.1
-
getLocation
Returns a description of location of element.- Specified by:
getLocation
in interfaceConfiguration
- Returns:
- a
String
value
-
getValue
Returns the value of the configuration element as aString
.- Specified by:
getValue
in interfaceConfiguration
- Overrides:
getValue
in classAbstractConfiguration
- Parameters:
defaultValue
- the default value to return if value malformed or empty- Returns:
- a
String
value
-
getValue
Returns the value of the configuration element as aString
.- Specified by:
getValue
in interfaceConfiguration
- Returns:
- a
String
value - Throws:
ConfigurationException
- If the value is not present.
-
getAttributeNames
Return an array of all attribute names.- Specified by:
getAttributeNames
in interfaceConfiguration
- Returns:
- a
String[]
value
-
getChildren
Return an array ofConfiguration
elements containing all node children.- Specified by:
getChildren
in interfaceConfiguration
- Returns:
- The child nodes with name
-
getAttribute
Returns the value of the attribute specified by its name as aString
.- Specified by:
getAttribute
in interfaceConfiguration
- Parameters:
name
- aString
value- Returns:
- a
String
value - Throws:
ConfigurationException
- If the attribute is not present.
-
getChild
Return the firstConfiguration
object child of this associated with the given name.- Specified by:
getChild
in interfaceConfiguration
- Overrides:
getChild
in classAbstractConfiguration
- Parameters:
name
- aString
valuecreateNew
- aboolean
value- Returns:
- a
Configuration
value
-
getChildren
Return an array ofConfiguration
objects children of this associated with the given name.
The returned array may be empty but is nevernull
.- Specified by:
getChildren
in interfaceConfiguration
- 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
- aString
value
-
setValue
Set the value of thisConfiguration
object to the specified string.- Specified by:
setValue
in interfaceMutableConfiguration
- Parameters:
value
- aString
value
-
setValue
public void setValue(int value) Set the value of thisConfiguration
object to the specified int.- Specified by:
setValue
in interfaceMutableConfiguration
- Parameters:
value
- aint
value
-
setValue
public void setValue(long value) Set the value of thisConfiguration
object to the specified long.- Specified by:
setValue
in interfaceMutableConfiguration
- Parameters:
value
- along
value
-
setValue
public void setValue(boolean value) Set the value of thisConfiguration
object to the specified boolean.- Specified by:
setValue
in interfaceMutableConfiguration
- Parameters:
value
- aboolean
value
-
setValue
public void setValue(float value) Set the value of thisConfiguration
object to the specified float.- Specified by:
setValue
in interfaceMutableConfiguration
- Parameters:
value
- afloat
value
-
setAttribute
Set the value of the specified attribute to the specified string.- Specified by:
setAttribute
in interfaceMutableConfiguration
- Parameters:
name
- name of the attribute to setvalue
- aString
value
-
setAttribute
Set the value of the specified attribute to the specified int.- Specified by:
setAttribute
in interfaceMutableConfiguration
- Parameters:
name
- name of the attribute to setvalue
- anint
value
-
setAttribute
Set the value of the specified attribute to the specified long.- Specified by:
setAttribute
in interfaceMutableConfiguration
- Parameters:
name
- name of the attribute to setvalue
- anlong
value
-
setAttribute
Set the value of the specified attribute to the specified boolean.- Specified by:
setAttribute
in interfaceMutableConfiguration
- Parameters:
name
- name of the attribute to setvalue
- anboolean
value
-
setAttribute
Set the value of the specified attribute to the specified float.- Specified by:
setAttribute
in interfaceMutableConfiguration
- Parameters:
name
- name of the attribute to setvalue
- anfloat
value
-
addAttribute
Deprecated.Use setAttribute() insteadAdd an attribute to this configuration element, returning its old value or null.- Parameters:
name
- aString
valuevalue
- aString
value- Returns:
- a
String
value
-
addChild
Add a childConfiguration
to this configuration element.- Specified by:
addChild
in interfaceMutableConfiguration
- Parameters:
configuration
- aConfiguration
value
-
addAll
Add all the attributes, children and value from specified configuration element to current configuration element.- Specified by:
addAll
in interfaceMutableConfiguration
- Parameters:
other
- theConfiguration
element
-
addAllAttributes
Add all attributes from specified configuration element to current configuration element.- Specified by:
addAllAttributes
in interfaceMutableConfiguration
- Parameters:
other
- theConfiguration
element
-
addAllChildren
Add all childConfiguration
objects from specified configuration element to current configuration element.- Specified by:
addAllChildren
in interfaceMutableConfiguration
- Parameters:
other
- the otherConfiguration
value
-
removeChild
Remove a childConfiguration
to this configuration element.- Specified by:
removeChild
in interfaceMutableConfiguration
- Parameters:
configuration
- aConfiguration
value
-
getChildCount
public int getChildCount()Return count of children.- Returns:
- an
int
value
-
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. -
getMutableChild
Description copied from interface:MutableConfiguration
Equivalent togetMutableChild( name, true )
- Specified by:
getMutableChild
in interfaceMutableConfiguration
- Throws:
ConfigurationException
-
getMutableChild
public MutableConfiguration getMutableChild(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, andautoCreate
istrue
, a new mutable child is created and added to this configuration before being returned.- Specified by:
getMutableChild
in 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
null
ifautoCreate
was false and no child by the given name existed. - Throws:
ConfigurationException
- if an error occurrs.
-
getMutableChildren
Description copied from interface:MutableConfiguration
Returns an array of mutable children. Immutable children are converted just as forgetMutableChild
.- Specified by:
getMutableChildren
in interfaceMutableConfiguration
- Throws:
ConfigurationException
- if an error occurrs.
-
getMutableChildren
Description copied from interface:MutableConfiguration
Returns an array of mutable children with the given name. Immutable children are converted just as forgetMutableChild
.- Specified by:
getMutableChildren
in interfaceMutableConfiguration
- Throws:
ConfigurationException
- if an error occurrs.
-
equals
Compare if this configuration is equal to another. -
hashCode
public int hashCode()Obtaine the hashcode for this configuration.
-