Here we go...
...it would be great if someone could look over this
and then apply it. I changed the AbstractConfiguration
and DefaultConfiguration as discussed before
cheers
--
Torsten
Index: AbstractConfiguration.java
===================================================================
RCS file:
/home/cvspublic/jakarta-avalon/src/java/org/apache/avalon/framework/configuration/AbstractConfiguration.java,v
retrieving revision 1.12
diff -u -r1.12 AbstractConfiguration.java
--- AbstractConfiguration.java 11 Dec 2001 09:00:45 -0000 1.12
+++ AbstractConfiguration.java 13 Feb 2002 10:25:13 -0000
@@ -19,7 +19,50 @@
*/
public abstract class AbstractConfiguration
implements Configuration
-{
+{
+ private Configuration parent;
+
+ /**
+ * The default contstructor
+ */
+ public AbstractConfiguration() {
+ this.parent = null;
+ }
+
+ /**
+ * This contstructor is to pass a parent <code>Configuration</code>
+ * object. Since this is an abstract class it will only called with
+ * <code>super()</code>
+ */
+ public AbstractConfiguration( final Configuration parent ) {
+ this.parent = parent;
+ }
+
+ /**
+ * checks the current configuration for a value, if non is found
+ * and a parent is available the lookup is passed to the parent configuration
+ * @throws ConfigurationException if an error occurs
+ * @return the value
+ * <code>null</code>.
+ */
+ private String getCascadingValue()
+ throws ConfigurationException
+ {
+ if (parent != null) {
+ try
+ {
+ return getValue();
+ }
+ catch( final ConfigurationException ce )
+ {
+ return parent.getValue();
+ }
+ }
+ else {
+ return getValue();
+ }
+ }
+
/**
* Returns the prefix of the namespace. This is only used as a serialization
* hint, therefore is not part of the client API. It should be included in
@@ -42,7 +85,7 @@
public int getValueAsInteger()
throws ConfigurationException
{
- final String value = getValue();
+ final String value = getCascadingValue();
try
{
if( value.startsWith( "0x" ) )
@@ -103,7 +146,7 @@
public long getValueAsLong()
throws ConfigurationException
{
- final String value = getValue();
+ final String value = getCascadingValue();
try
{
if( value.startsWith( "0x" ) )
@@ -161,7 +204,7 @@
public float getValueAsFloat()
throws ConfigurationException
{
- final String value = getValue();
+ final String value = getCascadingValue();
try
{
return Float.parseFloat( value );
@@ -201,7 +244,7 @@
public boolean getValueAsBoolean()
throws ConfigurationException
{
- final String value = getValue();
+ final String value = getCascadingValue();
if( value.equals( "true" ) )
{
return true;
@@ -246,7 +289,7 @@
{
try
{
- return getValue();
+ return getCascadingValue();
}
catch( final ConfigurationException ce )
{
Index: DefaultConfiguration.java
===================================================================
RCS file:
/home/cvspublic/jakarta-avalon/src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java,v
retrieving revision 1.13
diff -u -r1.13 DefaultConfiguration.java
--- DefaultConfiguration.java 11 Dec 2001 09:00:45 -0000 1.13
+++ DefaultConfiguration.java 13 Feb 2002 10:25:13 -0000
@@ -39,11 +39,40 @@
*/
public DefaultConfiguration( final String name, final String location )
{
- this (name, location, "", "");
+ this (null, name, location, "", "");
+ }
+
+ /**
+ * Create a new <code>DefaultConfiguration</code> instance
+ * with a parent <code>Configuration</code>
+ */
+ public DefaultConfiguration( final Configuration parent, final String name, final
+String location )
+ {
+ this (parent, name, location, "", "");
+ }
+
+
+ /**
+ * Create a new <code>DefaultConfiguration</code> instance.
+ * @param name config node name
+ * @param location Builder-specific locator string
+ * @param ns Namespace string (typically a URI). Should not be null; use ""
+ * if no namespace.
+ * @param prefix A short string prefixed to element names, associating
+ * elements with a longer namespace string. Should not be null; use "" if no
+ * namespace.
+ */
+ public DefaultConfiguration( final String name,
+ final String location,
+ final String ns,
+ final String prefix )
+ {
+ this (null, name, location, "", "");
}
/**
* Create a new <code>DefaultConfiguration</code> instance.
+ * @param parent the parent configuration object
* @param name config node name
* @param location Builder-specific locator string
* @param ns Namespace string (typically a URI). Should not be null; use ""
@@ -52,11 +81,13 @@
* elements with a longer namespace string. Should not be null; use "" if no
* namespace.
*/
- public DefaultConfiguration( final String name,
+ public DefaultConfiguration( final Configuration parent,
+ final String name,
final String location,
final String ns,
final String prefix )
{
+ super(parent);
m_name = name;
m_location = location;
m_namespace = ns;
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>