org.apache.excalibur.configuration
Class CascadingConfiguration

java.lang.Object
  extended by org.apache.excalibur.configuration.CascadingConfiguration
All Implemented Interfaces:
org.apache.avalon.framework.configuration.Configuration

public class CascadingConfiguration
extends Object
implements org.apache.avalon.framework.configuration.Configuration

The CascadingConfiguration is a classic Configuration backed by parent Configuration. Operations such as getChild return a CascadingConfiguration encapsulating both a primary and parent configuration. Requests for attribute values are resolved against the base configuration initially. If the result of the resolution is unsucessful, the request is applied against the parent configuration. As a parent may also be a CascadingConfiguration, the evaluation will be applied until a value is resolved against a class parent Configuration.

Author:
Stephen McConnell

Constructor Summary
CascadingConfiguration(org.apache.avalon.framework.configuration.Configuration base, org.apache.avalon.framework.configuration.Configuration parent)
          Create a CascadingConfiguration with specified parent.
 
Method Summary
 String getAttribute(String paramName)
          Return the value of specified attribute.
 String getAttribute(String name, String defaultValue)
          Returns the value of the attribute specified by its name as a String, or the default value if no attribute by that name exists or is empty.
 boolean getAttributeAsBoolean(String paramName)
          Return the boolean value of the specified parameter contained in this node.
 boolean getAttributeAsBoolean(String name, boolean defaultValue)
          Returns the value of the attribute specified by its name as a boolean, or the default value if no attribute by that name exists or is empty.
 double getAttributeAsDouble(String paramName)
          Return the double value of the specified parameter contained in this node.
 double getAttributeAsDouble(String name, double defaultValue)
          Returns the value of the attribute specified by its name as a double, or the default value if no attribute by that name exists or is empty.
 float getAttributeAsFloat(String paramName)
          Return the float value of the specified parameter contained in this node.
 float getAttributeAsFloat(String name, float defaultValue)
          Returns the value of the attribute specified by its name as a float, or the default value if no attribute by that name exists or is empty.
 int getAttributeAsInteger(String paramName)
          Return the int value of the specified attribute contained in this node or the parent.
 int getAttributeAsInteger(String name, int defaultValue)
          Returns the value of the attribute specified by its name as a int, or the default value if no attribute by that name exists or is empty.
 long getAttributeAsLong(String name)
          Returns the value of the attribute specified by its name as a long.
 long getAttributeAsLong(String name, long defaultValue)
          Returns the value of the attribute specified by its name as a long, or the default value if no attribute by that name exists or is empty.
 String[] getAttributeNames()
          Return an array of all attribute names in both base and parent.
 org.apache.avalon.framework.configuration.Configuration getChild(String child)
          Return a new CascadingConfiguration instance encapsulating the specified child node of the base and parent node.
 org.apache.avalon.framework.configuration.Configuration getChild(String child, boolean createNew)
          Return a Configuration instance encapsulating the specified child node.
 org.apache.avalon.framework.configuration.Configuration[] getChildren()
          Return an Array of Configuration elements containing all node children of both base and parent configurations.
 org.apache.avalon.framework.configuration.Configuration[] getChildren(String name)
          Return an Array of Configuration elements containing all node children with the specified name from both base and parent configurations.
 String getLocation()
          Return a string describing location of the base Configuration.
 String getName()
          Return the name of the base node.
 String getNamespace()
          Returns the namespace the main Configuration node belongs to.
 String getValue()
          Return the String value of the node.
 String getValue(String defaultValue)
          Returns the value of the configuration element as a String.
 boolean getValueAsBoolean()
          Return the boolean value of the node.
 boolean getValueAsBoolean(boolean defaultValue)
          Returns the value of the configuration element as a boolean.
 double getValueAsDouble()
          Return the double value of the node.
 double getValueAsDouble(double defaultValue)
          Returns the value of the configuration element as a double.
 float getValueAsFloat()
          Return the float value of the node.
 float getValueAsFloat(float defaultValue)
          Returns the value of the configuration element as a float.
 int getValueAsInteger()
          Return the int value of the node.
 int getValueAsInteger(int defaultValue)
          Returns the value of the configuration element as an int.
 long getValueAsLong()
          Return the long value of the node.
 long getValueAsLong(long defaultValue)
          Returns the value of the configuration element as a long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CascadingConfiguration

public CascadingConfiguration(org.apache.avalon.framework.configuration.Configuration base,
                              org.apache.avalon.framework.configuration.Configuration parent)
Create a CascadingConfiguration with specified parent. The base configuration shall override a parent configuration on request for attribute values and configuration body values. Unresolved request are redirected up the parent chain until a classic configuration is reached. Request for child configurations will return a new CascadingConfiguration referencing the child of the base and the child of the primary (i.e. a child configuration chain).

Parameters:
base - the base Configuration
parent - the parent Configuration
Method Detail

getName

public String getName()
Return the name of the base node.

Specified by:
getName in interface org.apache.avalon.framework.configuration.Configuration
Returns:
name of the Configuration node.

getLocation

public String getLocation()
Return a string describing location of the base Configuration. Location can be different for different mediums (ie "file:line" for normal XML files or "table:primary-key" for DB based configurations);

Specified by:
getLocation in interface org.apache.avalon.framework.configuration.Configuration
Returns:
a string describing location of Configuration

getNamespace

public String getNamespace()
                    throws org.apache.avalon.framework.configuration.ConfigurationException
Returns the namespace the main Configuration node belongs to.

Specified by:
getNamespace in interface org.apache.avalon.framework.configuration.Configuration
Returns:
a Namespace identifying the namespace of this Configuration.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - may be thrown by the underlying configuration
Since:
4.1

getChild

public org.apache.avalon.framework.configuration.Configuration getChild(String child)
Return a new CascadingConfiguration instance encapsulating the specified child node of the base and parent node.

Specified by:
getChild in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
child - The name of the child node.
Returns:
Configuration

getChild

public org.apache.avalon.framework.configuration.Configuration getChild(String child,
                                                                        boolean createNew)
Return a Configuration instance encapsulating the specified child node.

Specified by:
getChild in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
child - The name of the child node.
createNew - If true, a new Configuration will be created and returned if the specified child does not exist in either the base or parent configuratioin. If false, null will be returned when the specified child doesn't exist in either the base or the parent.
Returns:
Configuration

getChildren

public org.apache.avalon.framework.configuration.Configuration[] getChildren()
Return an Array of Configuration elements containing all node children of both base and parent configurations. The array order will reflect the order in the source config file, commencing with the base configuration.

Specified by:
getChildren in interface org.apache.avalon.framework.configuration.Configuration
Returns:
All child nodes

getChildren

public org.apache.avalon.framework.configuration.Configuration[] getChildren(String name)
Return an Array of Configuration elements containing all node children with the specified name from both base and parent configurations. The array order will reflect the order in the source config file commencing with the base configuration.

Specified by:
getChildren in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
name - The name of the children to get.
Returns:
The child nodes with name name

getAttributeNames

public String[] getAttributeNames()
Return an array of all attribute names in both base and parent.

The order of attributes in this array can not be relied on. As with XML, a Configuration's attributes are an unordered set. If your code relies on order, eg conf.getAttributeNames()[0], then it is liable to break if a different XML parser is used.

Specified by:
getAttributeNames in interface org.apache.avalon.framework.configuration.Configuration
Returns:
an array of all attribute names

getAttribute

public String getAttribute(String paramName)
                    throws org.apache.avalon.framework.configuration.ConfigurationException
Return the value of specified attribute. If the base configuration does not contain the attribute, the equivialent operation is applied to the parent configuration.

Specified by:
getAttribute in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
paramName - The name of the parameter you ask the value of.
Returns:
String value of attribute.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If no attribute with that name exists.

getAttributeAsInteger

public int getAttributeAsInteger(String paramName)
                          throws org.apache.avalon.framework.configuration.ConfigurationException
Return the int value of the specified attribute contained in this node or the parent.

Specified by:
getAttributeAsInteger in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
paramName - The name of the parameter you ask the value of.
Returns:
int value of attribute
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If no parameter with that name exists. or if conversion to int fails.

getAttributeAsLong

public long getAttributeAsLong(String name)
                        throws org.apache.avalon.framework.configuration.ConfigurationException
Returns the value of the attribute specified by its name as a long.

Specified by:
getAttributeAsLong in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
name - The name of the parameter you ask the value of.
Returns:
long value of attribute
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If no parameter with that name exists. or if conversion to long fails.

getAttributeAsFloat

public float getAttributeAsFloat(String paramName)
                          throws org.apache.avalon.framework.configuration.ConfigurationException
Return the float value of the specified parameter contained in this node.

Specified by:
getAttributeAsFloat in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
paramName - The name of the parameter you ask the value of.
Returns:
float value of attribute
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If no parameter with that name exists. or if conversion to float fails.

getAttributeAsDouble

public double getAttributeAsDouble(String paramName)
                            throws org.apache.avalon.framework.configuration.ConfigurationException
Return the double value of the specified parameter contained in this node.

Specified by:
getAttributeAsDouble in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
paramName - The name of the parameter you ask the value of.
Returns:
double value of attribute
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If no parameter with that name exists. or if conversion to float fails.

getAttributeAsBoolean

public boolean getAttributeAsBoolean(String paramName)
                              throws org.apache.avalon.framework.configuration.ConfigurationException
Return the boolean value of the specified parameter contained in this node.

Specified by:
getAttributeAsBoolean in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
paramName - The name of the parameter you ask the value of.
Returns:
boolean value of attribute
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If no parameter with that name exists. or if conversion to boolean fails.

getValue

public String getValue()
                throws org.apache.avalon.framework.configuration.ConfigurationException
Return the String value of the node.

Specified by:
getValue in interface org.apache.avalon.framework.configuration.Configuration
Returns:
the value of the node.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - May be raised by underlying base or parent configuration.

getValueAsInteger

public int getValueAsInteger()
                      throws org.apache.avalon.framework.configuration.ConfigurationException
Return the int value of the node.

Specified by:
getValueAsInteger in interface org.apache.avalon.framework.configuration.Configuration
Returns:
int the value as an integer
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If conversion to int fails.

getValueAsFloat

public float getValueAsFloat()
                      throws org.apache.avalon.framework.configuration.ConfigurationException
Return the float value of the node.

Specified by:
getValueAsFloat in interface org.apache.avalon.framework.configuration.Configuration
Returns:
the value of the node.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If conversion to float fails.

getValueAsDouble

public double getValueAsDouble()
                        throws org.apache.avalon.framework.configuration.ConfigurationException
Return the double value of the node.

Specified by:
getValueAsDouble in interface org.apache.avalon.framework.configuration.Configuration
Returns:
the value of the node.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If conversion to double fails.

getValueAsBoolean

public boolean getValueAsBoolean()
                          throws org.apache.avalon.framework.configuration.ConfigurationException
Return the boolean value of the node.

Specified by:
getValueAsBoolean in interface org.apache.avalon.framework.configuration.Configuration
Returns:
the value of the node.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If conversion to boolean fails.

getValueAsLong

public long getValueAsLong()
                    throws org.apache.avalon.framework.configuration.ConfigurationException
Return the long value of the node.

Specified by:
getValueAsLong in interface org.apache.avalon.framework.configuration.Configuration
Returns:
the value of the node.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If conversion to long fails.

getValue

public String getValue(String defaultValue)
Returns the value of the configuration element as a String. If the configuration value is not set, the default value will be used.

Specified by:
getValue in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
defaultValue - The default value desired.
Returns:
String value of the Configuration, or default if none specified.

getValueAsInteger

public int getValueAsInteger(int defaultValue)
Returns the value of the configuration element as an int. If the configuration value is not set, the default value will be used.

Specified by:
getValueAsInteger in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
defaultValue - The default value desired.
Returns:
int value of the Configuration, or default if none specified.

getValueAsLong

public long getValueAsLong(long defaultValue)
Returns the value of the configuration element as a long. If the configuration value is not set, the default value will be used.

Specified by:
getValueAsLong in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
defaultValue - The default value desired.
Returns:
long value of the Configuration, or default if none specified.

getValueAsFloat

public float getValueAsFloat(float defaultValue)
Returns the value of the configuration element as a float. If the configuration value is not set, the default value will be used.

Specified by:
getValueAsFloat in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
defaultValue - The default value desired.
Returns:
float value of the Configuration, or default if none specified.

getValueAsDouble

public double getValueAsDouble(double defaultValue)
Returns the value of the configuration element as a double. If the configuration value is not set, the default value will be used.

Specified by:
getValueAsDouble in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
defaultValue - The default value desired.
Returns:
double value of the Configuration, or default if none specified.

getValueAsBoolean

public boolean getValueAsBoolean(boolean defaultValue)
Returns the value of the configuration element as a boolean. If the configuration value is not set, the default value will be used.

Specified by:
getValueAsBoolean in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
defaultValue - The default value desired.
Returns:
boolean value of the Configuration, or default if none specified.

getAttribute

public String getAttribute(String name,
                           String defaultValue)
Returns the value of the attribute specified by its name as a String, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttribute in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
name - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
String value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.

getAttributeAsInteger

public int getAttributeAsInteger(String name,
                                 int defaultValue)
Returns the value of the attribute specified by its name as a int, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttributeAsInteger in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
name - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
int value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.

getAttributeAsLong

public long getAttributeAsLong(String name,
                               long defaultValue)
Returns the value of the attribute specified by its name as a long, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttributeAsLong in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
name - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
long value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.

getAttributeAsFloat

public float getAttributeAsFloat(String name,
                                 float defaultValue)
Returns the value of the attribute specified by its name as a float, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttributeAsFloat in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
name - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
float value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.

getAttributeAsDouble

public double getAttributeAsDouble(String name,
                                   double defaultValue)
Returns the value of the attribute specified by its name as a double, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttributeAsDouble in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
name - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
double value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.

getAttributeAsBoolean

public boolean getAttributeAsBoolean(String name,
                                     boolean defaultValue)
Returns the value of the attribute specified by its name as a boolean, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttributeAsBoolean in interface org.apache.avalon.framework.configuration.Configuration
Parameters:
name - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
boolean value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.


Copyright © 1997-2003 Apache Software Foundation. All Rights Reserved.