com.anthonyeden.lib.config
Class ConfigurationBase

java.lang.Object
  extended bycom.anthonyeden.lib.config.ConfigurationBase
All Implemented Interfaces:
Configuration, MutableConfiguration

public class ConfigurationBase
extends java.lang.Object
implements MutableConfiguration

The ConfigurationBase is a base implementation of the MutableConfiguration interface.

Author:
Anthony Eden

Field Summary
static java.lang.String ENCODING
           
 
Constructor Summary
ConfigurationBase(java.lang.String name, java.lang.Object value, Configuration parent)
          Construct a new ConfigurationBase object.
ConfigurationBase(java.lang.String name, java.lang.Object value, Configuration parent, Location location)
          Construct a new ConfigurationBase object.
ConfigurationBase(java.lang.String name, java.lang.Object value, java.util.List children, java.util.Map attributes, Configuration parent)
          Construct a new ConfigurationBase object.
ConfigurationBase(java.lang.String name, java.lang.Object value, java.util.List children, java.util.Map attributes, Configuration parent, Location location)
          Construct a new ConfigurationBase object.
 
Method Summary
 void addAttribute(java.lang.String name, java.lang.Object value)
          Add an attribute with the given name.
 void addChild(Configuration configuration)
          Add the configuration object as a child of this configuration object.
 MutableConfiguration addChild(java.lang.String name)
          Add a child node with no child value to the configuration.
 MutableConfiguration addChild(java.lang.String name, java.lang.Object value)
          Add a child node to the configuration.
 void clearChildren()
          Remove all of the children of this configuration node.
 java.lang.String getAttribute(java.lang.String name)
          Get the named attribute or null.
 java.lang.String getAttribute(java.lang.String name, java.lang.String defaultValue)
          Get the named attribute.
 java.util.List getAttributeNames()
          Get a List of attribute names.
 Configuration getChild(java.lang.String name)
          Get the child configuration object with the given name.
 java.util.List getChildren()
          Get a list of all child nodes.
 java.util.List getChildren(java.lang.String name)
          Get a list of all child nodes with the given name.
 java.lang.String getChildValue(java.lang.String name)
          Get the value of the first child configuration object with the given name.
 java.lang.String getChildValue(java.lang.String name, java.lang.String defaultValue)
          Get the value of the first child configuration object with the given name.
 Location getLocation()
          Get location information for this configuration object.
 java.lang.String getName()
          Get the node's name.
 Configuration getParent()
          Get the parent configuration object.
 java.lang.String getValue()
          Get the node's value or null if the node contains no data.
 java.lang.String getValue(java.lang.String defaultValue)
          Get the node's value.
 void removeChild(Configuration configuration)
          Remove the specified configuration object.
 void save(java.io.OutputStream out)
          Save the configuration data to the specified output stream.
 void save(java.io.Writer out)
          Save the configuration data to the specified output stream.
 void setName(java.lang.String name)
          Set the node name.
 void setValue(java.lang.String value)
          Set the configuration object's value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING

public static final java.lang.String ENCODING
See Also:
Constant Field Values
Constructor Detail

ConfigurationBase

public ConfigurationBase(java.lang.String name,
                         java.lang.Object value,
                         Configuration parent)
Construct a new ConfigurationBase object.

Parameters:
name - The configuration object name
value - The configuration object value
parent - The parent Configuration

ConfigurationBase

public ConfigurationBase(java.lang.String name,
                         java.lang.Object value,
                         Configuration parent,
                         Location location)
Construct a new ConfigurationBase object.

Parameters:
name - The configuration object name
value - The configuration object value
parent - The parent Configuration
location - The Location object or null

ConfigurationBase

public ConfigurationBase(java.lang.String name,
                         java.lang.Object value,
                         java.util.List children,
                         java.util.Map attributes,
                         Configuration parent)
Construct a new ConfigurationBase object.

Parameters:
name - The configuration object name
value - The configuration object value
children - The List of children
attributes - The Map of attributes
parent - The parent Configuration

ConfigurationBase

public ConfigurationBase(java.lang.String name,
                         java.lang.Object value,
                         java.util.List children,
                         java.util.Map attributes,
                         Configuration parent,
                         Location location)
Construct a new ConfigurationBase object.

Parameters:
name - The configuration object name
value - The configuration object value
children - The List of children
attributes - The Map of attributes
parent - The parent Configuration
location - The Location or null
Method Detail

getName

public java.lang.String getName()
Get the node's name.

Specified by:
getName in interface Configuration
Returns:
The node's name

setName

public void setName(java.lang.String name)
Set the node name.

Specified by:
setName in interface MutableConfiguration
Parameters:
name - The new node name

getParent

public Configuration getParent()
Get the parent configuration object. This method will return null if this configuration object is the top-most configuration object in the configuration tree.

Specified by:
getParent in interface Configuration
Returns:
The parent configuration object or null

getChild

public Configuration getChild(java.lang.String name)
Get the child configuration object with the given name. If the child with the name does not exist then this method returns null. If more than one child with the given name exists then this method returns the first child.

Specified by:
getChild in interface Configuration
Parameters:
name - The child name
Returns:
The first named child or null

getChildValue

public java.lang.String getChildValue(java.lang.String name)
Get the value of the first child configuration object with the given name. If the child cannot be found or the child had no data then this method returns null.

Specified by:
getChildValue in interface Configuration
Parameters:
name - The child name
Returns:
The value or null

getChildValue

public java.lang.String getChildValue(java.lang.String name,
                                      java.lang.String defaultValue)
Get the value of the first child configuration object with the given name. If the child cannot be found or the child had no data then this method returns the given default value.

Specified by:
getChildValue in interface Configuration
Parameters:
name - The child name
defaultValue - The default value
Returns:
The value

getChildren

public java.util.List getChildren()
Get a list of all child nodes.

Specified by:
getChildren in interface Configuration
Returns:
A List of Configuration objects

getChildren

public java.util.List getChildren(java.lang.String name)
Get a list of all child nodes with the given name.

Specified by:
getChildren in interface Configuration
Parameters:
name - The child node name
Returns:
A List of Configuration objects

addChild

public MutableConfiguration addChild(java.lang.String name)
Add a child node with no child value to the configuration. This method should be the same as calling addChild(name, null)

Specified by:
addChild in interface MutableConfiguration
Parameters:
name - The name of the new configuration node
Returns:
The configuration node

addChild

public MutableConfiguration addChild(java.lang.String name,
                                     java.lang.Object value)
Add a child node to the configuration. The value's toString() method will be used to convert the value to a String.

Specified by:
addChild in interface MutableConfiguration
Parameters:
name - The name of the new configuration node
value - The value of the new configuration node
Returns:
The configuration node

addChild

public void addChild(Configuration configuration)
Add the configuration object as a child of this configuration object.

Specified by:
addChild in interface MutableConfiguration
Parameters:
configuration - The child configuration object

removeChild

public void removeChild(Configuration configuration)
Remove the specified configuration object.

Specified by:
removeChild in interface MutableConfiguration
Parameters:
configuration - The child configuration object

addAttribute

public void addAttribute(java.lang.String name,
                         java.lang.Object value)
Add an attribute with the given name. The value's toString() method will be used to convert the value to a String.

Specified by:
addAttribute in interface MutableConfiguration
Parameters:
name - The attribute name
value - The attribute value

setValue

public void setValue(java.lang.String value)
Set the configuration object's value.

Specified by:
setValue in interface MutableConfiguration
Parameters:
value - The new value

clearChildren

public void clearChildren()
Remove all of the children of this configuration node.

Specified by:
clearChildren in interface MutableConfiguration

getAttributeNames

public java.util.List getAttributeNames()
Get a List of attribute names.

Specified by:
getAttributeNames in interface Configuration
Returns:
A List of attribute names

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Get the named attribute or null.

Specified by:
getAttribute in interface Configuration
Parameters:
name - The attribute name
Returns:
The attribute value

getAttribute

public java.lang.String getAttribute(java.lang.String name,
                                     java.lang.String defaultValue)
Get the named attribute. If the attribute is not found then return the given default value.

Specified by:
getAttribute in interface Configuration
Parameters:
name - The attribute name
defaultValue - The default value
Returns:
The attribute value

getValue

public java.lang.String getValue()
Get the node's value or null if the node contains no data.

Specified by:
getValue in interface Configuration
Returns:
The node value or null

getValue

public java.lang.String getValue(java.lang.String defaultValue)
Get the node's value. If the node contains no data then return the given default value.

Specified by:
getValue in interface Configuration
Parameters:
defaultValue - The default value
Returns:
The node value

getLocation

public Location getLocation()
Get location information for this configuration object.

Specified by:
getLocation in interface Configuration
Returns:
Location

save

public void save(java.io.OutputStream out)
          throws ConfigurationException
Save the configuration data to the specified output stream. Please note that the caller must close the OutputStream.

Specified by:
save in interface MutableConfiguration
Parameters:
out - The OutputStream
Throws:
ConfigurationException

save

public void save(java.io.Writer out)
          throws ConfigurationException
Save the configuration data to the specified output stream. Please note that the caller must close the writer.

Specified by:
save in interface MutableConfiguration
Parameters:
out - The Writer
Throws:
ConfigurationException


Copyright (c) 2000-2003 Anthony Eden. All Rights Reserved.