commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1426979 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/combined/ test/java/org/apache/commons/configuration/builder/combined/
Date Sun, 30 Dec 2012 19:15:53 GMT
Author: oheger
Date: Sun Dec 30 19:15:53 2012
New Revision: 1426979

URL: http://svn.apache.org/viewvc?rev=1426979&view=rev
Log:
Made CombinedConfigurationBuilder more extensible.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java?rev=1426979&r1=1426978&r2=1426979&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
Sun Dec 30 19:15:53 2012
@@ -679,6 +679,24 @@ public class CombinedConfigurationBuilde
     }
 
     /**
+     * Creates a default builder for the definition configuration and
+     * initializes it with a parameters object. This method is called if no
+     * definition builder is defined in this builder's parameters. This
+     * implementation creates a default file-based builder which produces an
+     * {@code XMLConfiguration}; it expects a corresponding file specification.
+     * Note: This method is called in a synchronized block.
+     *
+     * @param builderParams the parameters object for the builder
+     * @return the standard builder for the definition configuration
+     */
+    protected ConfigurationBuilder<? extends HierarchicalConfiguration> createXMLDefinitionBuilder(
+            BuilderParameters builderParams)
+    {
+        return new FileBasedConfigurationBuilder<XMLConfiguration>(
+                XMLConfiguration.class).configure(builderParams);
+    }
+
+    /**
      * Returns the configuration containing the definition of the combined
      * configuration to be created. This method only returns a defined result
      * during construction of the result configuration. The definition
@@ -702,6 +720,20 @@ public class CombinedConfigurationBuilde
     }
 
     /**
+     * Returns a collection with the builders for all child configuration
+     * sources. This method can be used by derived classes providing additional
+     * functionality on top of the declared configuration sources. It only
+     * returns a defined value during construction of the result configuration
+     * instance.
+     *
+     * @return a collection with the builders for child configuration sources
+     */
+    protected Collection<ConfigurationBuilder<? extends Configuration>> getChildBuilders()
+    {
+        return sourceData.getChildBuilders();
+    }
+
+    /**
      * {@inheritDoc} This implementation evaluates the {@code result} property
      * of the definition configuration. It creates a combined bean declaration
      * with both the properties specified in the definition file and the
@@ -1228,21 +1260,6 @@ public class CombinedConfigurationBuilde
     }
 
     /**
-     * Creates a default builder for the definition configuration and
-     * initializes it with a parameters object. The default builder creates an
-     * {@code XMLConfiguration}; it expects a corresponding file specification.
-     *
-     * @param builderParams the parameters object for the builder
-     * @return the standard builder for the definition configuration
-     */
-    private static ConfigurationBuilder<? extends HierarchicalConfiguration> createXMLDefinitionBuilder(
-            BuilderParameters builderParams)
-    {
-        return new FileBasedConfigurationBuilder<XMLConfiguration>(
-                XMLConfiguration.class).configure(builderParams);
-    }
-
-    /**
      * Initializes the list nodes of the node combiner for the given combined
      * configuration. This information can be set in the header section of the
      * configuration definition file for both the override and the union
@@ -1298,6 +1315,9 @@ public class CombinedConfigurationBuilde
         /** A map for direct access to a builder by its name. */
         private final Map<String, ConfigurationBuilder<? extends Configuration>>
namedBuilders;
 
+        /** A collection with all child builders. */
+        private final Collection<ConfigurationBuilder<? extends Configuration>>
allBuilders;
+
         /** A listener for reacting on changes of sub builders. */
         private BuilderListener changeListener;
 
@@ -1312,6 +1332,8 @@ public class CombinedConfigurationBuilde
                     new LinkedList<SubnodeConfiguration>();
             namedBuilders =
                     new HashMap<String, ConfigurationBuilder<? extends Configuration>>();
+            allBuilders =
+                    new LinkedList<ConfigurationBuilder<? extends Configuration>>();
         }
 
         /**
@@ -1360,7 +1382,7 @@ public class CombinedConfigurationBuilde
          */
         public void cleanUp()
         {
-            for (ConfigurationBuilder<?> b : namedBuilders.values())
+            for (ConfigurationBuilder<?> b : getChildBuilders())
             {
                 b.removeBuilderListener(changeListener);
             }
@@ -1368,6 +1390,17 @@ public class CombinedConfigurationBuilde
         }
 
         /**
+         * Returns a collection containing the builders for all child
+         * configuration sources.
+         *
+         * @return the child configuration builders
+         */
+        public Collection<ConfigurationBuilder<? extends Configuration>> getChildBuilders()
+        {
+            return allBuilders;
+        }
+
+        /**
          * Returns a collection with all configuration source declarations
          * defined in the override section.
          *
@@ -1441,6 +1474,7 @@ public class CombinedConfigurationBuilde
             {
                 namedBuilders.put(decl.getName(), builder);
             }
+            allBuilders.add(builder);
             builder.addBuilderListener(changeListener);
             return builder;
         }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java?rev=1426979&r1=1426978&r2=1426979&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
Sun Dec 30 19:15:53 2012
@@ -974,6 +974,20 @@ public class TestCombinedConfigurationBu
     }
 
     /**
+     * Tests whether all child builders can be obtained.
+     */
+    @Test
+    public void testGetChildBuilders() throws ConfigurationException
+    {
+        builder.configure(new FileBasedBuilderParametersImpl()
+                .setFile(TEST_FILE));
+        builder.getConfiguration();
+        Collection<ConfigurationBuilder<? extends Configuration>> childBuilders
=
+                builder.getChildBuilders();
+        assertEquals("Wrong number of child builders", 3, childBuilders.size());
+    }
+
+    /**
      * A test builder provider implementation for testing whether providers can
      * be defined in the definition file.
      */



Mime
View raw message