commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1438905 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/ test/java/org/apache/commons/configuration/
Date Sat, 26 Jan 2013 15:35:48 GMT
Author: oheger
Date: Sat Jan 26 15:35:48 2013
New Revision: 1438905

URL: http://svn.apache.org/viewvc?rev=1438905&view=rev
Log:
CombinedConfiguration now operates on the Configuration interface rather than on AbstractConfiguration.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestVFSConfigurationBuilder.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java?rev=1438905&r1=1438904&r2=1438905&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
Sat Jan 26 15:35:48 2013
@@ -28,6 +28,7 @@ import java.util.Set;
 
 import org.apache.commons.configuration.event.ConfigurationEvent;
 import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.event.EventSource;
 import org.apache.commons.configuration.tree.ConfigurationNode;
 import org.apache.commons.configuration.tree.DefaultConfigurationKey;
 import org.apache.commons.configuration.tree.DefaultConfigurationNode;
@@ -202,7 +203,7 @@ public class CombinedConfiguration exten
     private List<ConfigData> configurations;
 
     /** Stores a map with the named configurations. */
-    private Map<String, AbstractConfiguration> namedConfigurations;
+    private Map<String, Configuration> namedConfigurations;
 
     /** The default behavior is to ignore exceptions that occur during reload */
     private boolean ignoreReloadExceptions = true;
@@ -383,7 +384,7 @@ public class CombinedConfiguration exten
      * @param at the position of this configuration in the combined tree (can be
      * <b>null</b>)
      */
-    public void addConfiguration(AbstractConfiguration config, String name,
+    public void addConfiguration(Configuration config, String name,
             String at)
     {
         if (config == null)
@@ -410,7 +411,7 @@ public class CombinedConfiguration exten
             namedConfigurations.put(name, config);
         }
 
-        config.addConfigurationListener(this);
+        registerListenerAt(config);
         invalidate();
     }
 
@@ -422,7 +423,7 @@ public class CombinedConfiguration exten
      * @param config the configuration to add (must not be <b>null</b>)
      * @param name the name of this configuration (can be <b>null</b>)
      */
-    public void addConfiguration(AbstractConfiguration config, String name)
+    public void addConfiguration(Configuration config, String name)
     {
         addConfiguration(config, name, null);
     }
@@ -434,7 +435,7 @@ public class CombinedConfiguration exten
      *
      * @param config the configuration to add (must not be <b>null</b>)
      */
-    public void addConfiguration(AbstractConfiguration config)
+    public void addConfiguration(Configuration config)
     {
         addConfiguration(config, null, null);
     }
@@ -481,9 +482,9 @@ public class CombinedConfiguration exten
      * @return A List of all the configurations.
      * @since 1.7
      */
-    public List<AbstractConfiguration> getConfigurations()
+    public List<Configuration> getConfigurations()
     {
-        List<AbstractConfiguration> list = new ArrayList<AbstractConfiguration>(configurations.size());
+        List<Configuration> list = new ArrayList<Configuration>(configurations.size());
         for (ConfigData cd : configurations)
         {
             list.add(cd.getConfiguration());
@@ -541,7 +542,7 @@ public class CombinedConfiguration exten
         {
             namedConfigurations.remove(cd.getName());
         }
-        cd.getConfiguration().removeConfigurationListener(this);
+        unregisterListenerAt(cd.getConfiguration());
         invalidate();
         return cd.getConfiguration();
     }
@@ -638,7 +639,7 @@ public class CombinedConfiguration exten
     {
         fireEvent(EVENT_CLEAR, null, null, true);
         configurations = new ArrayList<ConfigData>();
-        namedConfigurations = new HashMap<String, AbstractConfiguration>();
+        namedConfigurations = new HashMap<String, Configuration>();
         fireEvent(EVENT_CLEAR, null, null, false);
         invalidate();
     }
@@ -659,7 +660,7 @@ public class CombinedConfiguration exten
         copy.clear();
         for (ConfigData cd : configurations)
         {
-            copy.addConfiguration((AbstractConfiguration) ConfigurationUtils
+            copy.addConfiguration(ConfigurationUtils
                     .cloneConfiguration(cd.getConfiguration()), cd.getName(),
                     cd.getAt());
         }
@@ -838,13 +839,41 @@ public class CombinedConfiguration exten
     }
 
     /**
+     * Registers this combined configuration as listener at the given child
+     * configuration.
+     *
+     * @param configuration the child configuration
+     */
+    private void registerListenerAt(Configuration configuration)
+    {
+        if (configuration instanceof EventSource)
+        {
+            ((EventSource) configuration).addConfigurationListener(this);
+        }
+    }
+
+    /**
+     * Removes this combined configuration as listener from the given child
+     * configuration.
+     *
+     * @param configuration the child configuration
+     */
+    private void unregisterListenerAt(Configuration configuration)
+    {
+        if (configuration instanceof EventSource)
+        {
+            ((EventSource) configuration).removeConfigurationListener(this);
+        }
+    }
+
+    /**
      * An internal helper class for storing information about contained
      * configurations.
      */
     class ConfigData
     {
         /** Stores a reference to the configuration. */
-        private AbstractConfiguration configuration;
+        private Configuration configuration;
 
         /** Stores the name under which the configuration is stored. */
         private String name;
@@ -866,7 +895,7 @@ public class CombinedConfiguration exten
          * @param n the name
          * @param at the at position
          */
-        public ConfigData(AbstractConfiguration config, String n, String at)
+        public ConfigData(Configuration config, String n, String at)
         {
             configuration = config;
             name = n;
@@ -879,7 +908,7 @@ public class CombinedConfiguration exten
          *
          * @return the configuration
          */
-        public AbstractConfiguration getConfiguration()
+        public Configuration getConfiguration()
         {
             return configuration;
         }

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java?rev=1438905&r1=1438904&r2=1438905&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java
Sat Jan 26 15:35:48 2013
@@ -70,8 +70,8 @@ public class DynamicCombinedConfiguratio
     private List<ConfigData> configurations = new ArrayList<ConfigData>();
 
     /** Stores a map with the named configurations. */
-    private Map<String, AbstractConfiguration> namedConfigurations =
-            new HashMap<String, AbstractConfiguration>();
+    private Map<String, Configuration> namedConfigurations =
+            new HashMap<String, Configuration>();
 
     /** The key pattern for the CombinedConfiguration map */
     private String keyPattern;
@@ -183,7 +183,7 @@ public class DynamicCombinedConfiguratio
      * <b>null</b>)
      */
     @Override
-    public void addConfiguration(AbstractConfiguration config, String name,
+    public void addConfiguration(Configuration config, String name,
             String at)
     {
         ConfigData cd = new ConfigData(config, name, at);
@@ -873,7 +873,7 @@ public class DynamicCombinedConfiguratio
     static class ConfigData
     {
         /** Stores a reference to the configuration. */
-        private AbstractConfiguration configuration;
+        private Configuration configuration;
 
         /** Stores the name under which the configuration is stored. */
         private String name;
@@ -889,7 +889,7 @@ public class DynamicCombinedConfiguratio
          * @param n the name
          * @param at the at position
          */
-        public ConfigData(AbstractConfiguration config, String n, String at)
+        public ConfigData(Configuration config, String n, String at)
         {
             configuration = config;
             name = n;
@@ -901,7 +901,7 @@ public class DynamicCombinedConfiguratio
          *
          * @return the configuration
          */
-        public AbstractConfiguration getConfiguration()
+        public Configuration getConfiguration()
         {
             return configuration;
         }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java?rev=1438905&r1=1438904&r2=1438905&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
Sat Jan 26 15:35:48 2013
@@ -734,10 +734,10 @@ public class TestCombinedConfiguration
         config.addConfiguration(setUpTestConfiguration(), TEST_NAME, "conf2");
         AbstractConfiguration pc = new PropertiesConfiguration();
         config.addConfiguration(pc, "props");
-        List<AbstractConfiguration> list = config.getConfigurations();
+        List<Configuration> list = config.getConfigurations();
         assertNotNull("No list of configurations returned", list);
         assertTrue("Incorrect number of configurations", list.size() == 3);
-        AbstractConfiguration c = list.get(2);
+        Configuration c = list.get(2);
         assertTrue("Incorrect configuration", c == pc);
     }
 

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestVFSConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestVFSConfigurationBuilder.java?rev=1438905&r1=1438904&r2=1438905&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestVFSConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestVFSConfigurationBuilder.java
Sat Jan 26 15:35:48 2013
@@ -954,9 +954,9 @@ public class TestVFSConfigurationBuilder
         System.getProperties().remove("Id");
 
         CombinedConfiguration config = factory.getConfiguration(true);
-        List<AbstractConfiguration> list = config.getConfigurations();
+        List<Configuration> list = config.getConfigurations();
         assertTrue("Incorrect number of configurations - " + list.size(), list.size() ==
4);
-        Iterator<AbstractConfiguration> iter = list.iterator();
+        Iterator<Configuration> iter = list.iterator();
         while (iter.hasNext())
         {
             Configuration conf = iter.next();
@@ -967,7 +967,7 @@ public class TestVFSConfigurationBuilder
             }
             else if (conf instanceof CombinedConfiguration)
             {
-                Iterator<AbstractConfiguration> it = ((CombinedConfiguration)conf).getConfigurations().iterator();
+                Iterator<Configuration> it = ((CombinedConfiguration)conf).getConfigurations().iterator();
                 while (it.hasNext())
                 {
                     conf = it.next();
@@ -992,9 +992,9 @@ public class TestVFSConfigurationBuilder
         FileSystem fs = factory.getFileSystem();
         assertNotNull("No File System",fs);
         assertTrue("Incorrect File System", fs instanceof VFSFileSystem);
-        List<AbstractConfiguration> list = config.getConfigurations();
+        List<Configuration> list = config.getConfigurations();
         assertTrue("Incorrect number of configurations - " + list.size(), list.size() ==
4);
-        Iterator<AbstractConfiguration> iter = list.iterator();
+        Iterator<Configuration> iter = list.iterator();
         while (iter.hasNext())
         {
             Configuration conf = iter.next();
@@ -1005,7 +1005,7 @@ public class TestVFSConfigurationBuilder
             }
             else if (conf instanceof CombinedConfiguration)
             {
-                Iterator<AbstractConfiguration> it = ((CombinedConfiguration)conf).getConfigurations().iterator();
+                Iterator<Configuration> it = ((CombinedConfiguration)conf).getConfigurations().iterator();
                 while (it.hasNext())
                 {
                     conf = it.next();



Mime
View raw message