Hi all. I'm sending this patches to the list to see if you would like to
include them into CVS.

These changes should help a developer, with a Configuration instance at
hand, determine it's parent and root Configuration instances.
It respects the read-only nature of Configuration objects.

-- 
Leandro Rodrigo Saad Cruz
IT - Inter Business Tecnologia e Servicos (IB)
http://www.ibnetwork.com.br
http://jakarta.apache.org/ojb
Index: src/java/org/apache/avalon/framework/configuration/Configuration.java
===================================================================
RCS file: /home/cvspublic/jakarta-avalon/src/java/org/apache/avalon/framework/configuration/Configuration.java,v
retrieving revision 1.23
diff -u -b -B -r1.23 Configuration.java
--- src/java/org/apache/avalon/framework/configuration/Configuration.java	7 Nov 2002 08:35:27 -0000	1.23
+++ src/java/org/apache/avalon/framework/configuration/Configuration.java	21 Nov 2002 13:27:53 -0000
@@ -499,4 +499,19 @@
      *         the value is not set.
      */
     boolean getAttributeAsBoolean( String name, boolean defaultValue );
+
+    /**
+     * Returns the parent os this Configuration instance, (can be null).
+     *
+     * @return Configuration object that this instance is child of.
+     */
+    public Configuration getParent();
+
+    /**
+     * Returns the root Configuration object that this Configuration instance is part of.
+     *
+     * @see SAXConfigurationHandler
+     * @return Configuration object that is the root of the Configuration tree.
+     */
+    public Configuration getRoot();
 }
Index: src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java
===================================================================
RCS file: /home/cvspublic/jakarta-avalon/src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java,v
retrieving revision 1.25
diff -u -b -B -r1.25 DefaultConfiguration.java
--- src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java	11 Nov 2002 01:54:07 -0000	1.25
+++ src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java	21 Nov 2002 13:31:02 -0000
@@ -84,6 +84,7 @@
     private ArrayList m_children;
     private String m_value;
     private boolean m_readOnly;
+    private Configuration m_parent;
 
     /**
      * Create a new <code>DefaultConfiguration</code> instance.
@@ -536,5 +537,46 @@
             throw new IllegalStateException
                 ( "Configuration is read only and can not be modified" );
         }
+    }
+
+
+
+    /**
+     * Returns the parent os this Configuration instance, (can be null).
+     *
+     * @return Configuration object that this instance is child of.
+     */
+    public Configuration getParent()
+    {
+        return m_parent;
+    }
+
+
+
+    /**
+     * Set the parent Configuration object for this instance
+     */
+    public void setParent(Configuration parent)
+    {
+        m_parent = parent;
+    }
+
+
+
+    /**
+     * Returns the root Configuration object that this Configuration instance is part of.
+     * A Configuration object is considered to be the root of the Configuration tree if it has no parent.    
+     *
+     * @see SAXConfigurationHandler
+     * @return Configuration object that is the root of the Configuration tree.
+     */
+    public Configuration getRoot()
+    {
+        if(m_parent != null)
+        {
+            return m_parent.getRoot();
+        }
+        return this;
+
     }
 }
Index: src/java/org/apache/avalon/framework/configuration/SAXConfigurationHandler.java
===================================================================
RCS file: /home/cvspublic/jakarta-avalon/src/java/org/apache/avalon/framework/configuration/SAXConfigurationHandler.java,v
retrieving revision 1.24
diff -u -b -B -r1.24 SAXConfigurationHandler.java
--- src/java/org/apache/avalon/framework/configuration/SAXConfigurationHandler.java	7 Nov 2002 08:35:27 -0000	1.24
+++ src/java/org/apache/avalon/framework/configuration/SAXConfigurationHandler.java	21 Nov 2002 13:27:14 -0000
@@ -232,6 +232,7 @@
         {
             final DefaultConfiguration parent =
                 (DefaultConfiguration)m_elements.get( depth - 1 );
+            configuration.setParent(parent);
             parent.addChild( configuration );
             // inherits parent's space preservation policy
             preserveSpace = m_preserveSpace.get( depth - 1 );

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to