commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1785885 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration2/ main/java/org/apache/commons/configuration2/plist/ test/java/org/apache/commons/configuration2/
Date Tue, 07 Mar 2017 20:59:38 GMT
Author: oheger
Date: Tue Mar  7 20:59:38 2017
New Revision: 1785885

URL: http://svn.apache.org/viewvc?rev=1785885&view=rev
Log:
[CONFIGURATION-653] Better support for immutable configurations.

Some utility methods in ConfigurationUtils or ConfigurationConverter
now provide overloaded methods accepting an ImmutableConfiguration.
This base interface is now also used in checks in
PropertyListConfiguration and XMLPropertyListConfiguration where
possible.

Thanks to Vincent Maurin for the patch.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationConverter.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationUtils.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationConverter.java?rev=1785885&r1=1785884&r2=1785885&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationConverter.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationConverter.java
Tue Mar  7 20:59:38 2017
@@ -62,10 +62,10 @@ public final class ConfigurationConverte
      * configuration (if it extends AbstractConfiguration) or with a comma as
      * delimiter otherwise.
      *
-     * @param config Configuration object to convert
+     * @param config ImmutableConfiguration object to convert
      * @return Properties created from the Configuration
      */
-    public static Properties getProperties(Configuration config)
+    public static Properties getProperties(ImmutableConfiguration config)
     {
         Properties props = new Properties();
         ListDelimiterHandler listHandler;
@@ -115,6 +115,21 @@ public final class ConfigurationConverte
     }
 
     /**
+     * Convert a Configuration class into a Properties class. List properties
+     * are joined into a string using either the list delimiter handler of the
+     * configuration (if it extends AbstractConfiguration) or with a comma as
+     * delimiter otherwise.
+     * This version of the method exists only for backwards compatibility reason.
+     *
+     * @param config Configuration object to convert
+     * @return Properties created from the Configuration
+     */
+    public static Properties getProperties(Configuration config)
+    {
+        return getProperties((ImmutableConfiguration) config);
+    }
+
+    /**
      * Convert a Configuration class into a Map class.
      *
      * @param config Configuration object to convert

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationUtils.java?rev=1785885&r1=1785884&r2=1785885&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationUtils.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationUtils.java
Tue Mar  7 20:59:38 2017
@@ -105,18 +105,30 @@ public final class ConfigurationUtils
      * @param configuration the configuration
      * @param out the output stream to dump the configuration to
      */
-    public static void dump(Configuration configuration, PrintStream out)
+    public static void dump(ImmutableConfiguration configuration, PrintStream out)
     {
         dump(configuration, new PrintWriter(out));
     }
 
     /**
+     * Dump the configuration key/value mappings to some ouput stream.
+     * This version of the method exists only for backwards compatibility reason.
+     *
+     * @param configuration the configuration
+     * @param out the output stream to dump the configuration to
+     */
+    public static void dump(Configuration configuration, PrintStream out)
+    {
+        dump((ImmutableConfiguration) configuration, out);
+    }
+
+    /**
      * Dump the configuration key/value mappings to some writer.
      *
      * @param configuration the configuration
      * @param out the writer to dump the configuration to
      */
-    public static void dump(Configuration configuration, PrintWriter out)
+    public static void dump(ImmutableConfiguration configuration, PrintWriter out)
     {
         for (Iterator<String> keys = configuration.getKeys(); keys.hasNext();)
         {
@@ -136,13 +148,25 @@ public final class ConfigurationUtils
     }
 
     /**
+     * Dump the configuration key/value mappings to some writer.
+     * This version of the method exists only for backwards compatibility reason.
+     *
+     * @param configuration the configuration
+     * @param out the writer to dump the configuration to
+     */
+    public static void dump(Configuration configuration, PrintWriter out)
+    {
+        dump((ImmutableConfiguration) configuration, out);
+    }
+
+    /**
      * Get a string representation of the key/value mappings of a
      * configuration.
      *
      * @param configuration the configuration
      * @return a string representation of the configuration
      */
-    public static String toString(Configuration configuration)
+    public static String toString(ImmutableConfiguration configuration)
     {
         StringWriter writer = new StringWriter();
         dump(configuration, new PrintWriter(writer));
@@ -150,6 +174,19 @@ public final class ConfigurationUtils
     }
 
     /**
+     * Get a string representation of the key/value mappings of a
+     * configuration.
+     * This version of the method exists only for backwards compatibility reason.
+     *
+     * @param configuration the configuration
+     * @return a string representation of the configuration
+     */
+    public static String toString(Configuration configuration)
+    {
+        return toString((ImmutableConfiguration) configuration);
+    }
+
+    /**
      * <p>Copy all properties from the source configuration to the target
      * configuration. Properties in the target configuration are replaced with
      * the properties with the same key in the source configuration.</p>
@@ -163,7 +200,7 @@ public final class ConfigurationUtils
      * @param target the target configuration
      * @since 1.1
      */
-    public static void copy(Configuration source, Configuration target)
+    public static void copy(ImmutableConfiguration source, Configuration target)
     {
         for (Iterator<String> keys = source.getKeys(); keys.hasNext();)
         {
@@ -173,6 +210,25 @@ public final class ConfigurationUtils
     }
 
     /**
+     * <p>Copy all properties from the source configuration to the target
+     * configuration. Properties in the target configuration are replaced with
+     * the properties with the same key in the source configuration.</p>
+     * <p><em>Note:</em> This method is not able to handle some specifics
of
+     * configurations derived from {@code AbstractConfiguration} (e.g.
+     * list delimiters). For a full support of all of these features the
+     * {@code copy()} method of {@code AbstractConfiguration} should
+     * be used. In a future release this method might become deprecated.</p>
+     *
+     * @param source the source configuration
+     * @param target the target configuration
+     * @since 1.1
+     */
+    public static void copy(Configuration source, Configuration target)
+    {
+        copy((ImmutableConfiguration) source, target);
+    }
+
+    /**
      * <p>Append all properties from the source configuration to the target
      * configuration. Properties in the source configuration are appended to
      * the properties with the same key in the target configuration.</p>
@@ -186,7 +242,7 @@ public final class ConfigurationUtils
      * @param target the target configuration
      * @since 1.1
      */
-    public static void append(Configuration source, Configuration target)
+    public static void append(ImmutableConfiguration source, Configuration target)
     {
         for (Iterator<String> keys = source.getKeys(); keys.hasNext();)
         {
@@ -196,6 +252,25 @@ public final class ConfigurationUtils
     }
 
     /**
+     * <p>Append all properties from the source configuration to the target
+     * configuration. Properties in the source configuration are appended to
+     * the properties with the same key in the target configuration.</p>
+     * <p><em>Note:</em> This method is not able to handle some specifics
of
+     * configurations derived from {@code AbstractConfiguration} (e.g.
+     * list delimiters). For a full support of all of these features the
+     * {@code copy()} method of {@code AbstractConfiguration} should
+     * be used. In a future release this method might become deprecated.</p>
+     *
+     * @param source the source configuration
+     * @param target the target configuration
+     * @since 1.1
+     */
+    public static void append(Configuration source, Configuration target)
+    {
+        append((ImmutableConfiguration) source, target);
+    }
+
+    /**
      * Converts the passed in configuration to a hierarchical one. If the
      * configuration is already hierarchical, it is directly returned. Otherwise
      * all properties are copied into a new hierarchical configuration.

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java?rev=1785885&r1=1785884&r2=1785885&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java
Tue Mar  7 20:59:38 2017
@@ -34,6 +34,7 @@ import org.apache.commons.configuration2
 import org.apache.commons.configuration2.Configuration;
 import org.apache.commons.configuration2.FileBasedConfiguration;
 import org.apache.commons.configuration2.HierarchicalConfiguration;
+import org.apache.commons.configuration2.ImmutableConfiguration;
 import org.apache.commons.configuration2.MapConfiguration;
 import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.commons.configuration2.tree.ImmutableNode;
@@ -322,13 +323,13 @@ public class PropertyListConfiguration e
                             .getNodeHandler();
             printNode(out, indentLevel, handler.getRootNode(), handler);
         }
-        else if (value instanceof Configuration)
+        else if (value instanceof ImmutableConfiguration)
         {
             // display a flat Configuration as a dictionary
             out.println();
             out.println(padding + "{");
 
-            Configuration config = (Configuration) value;
+            ImmutableConfiguration config = (ImmutableConfiguration) value;
             Iterator<String> it = config.getKeys();
             while (it.hasNext())
             {

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java?rev=1785885&r1=1785884&r2=1785885&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
Tue Mar  7 20:59:38 2017
@@ -45,6 +45,7 @@ import org.apache.commons.configuration2
 import org.apache.commons.configuration2.Configuration;
 import org.apache.commons.configuration2.FileBasedConfiguration;
 import org.apache.commons.configuration2.HierarchicalConfiguration;
+import org.apache.commons.configuration2.ImmutableConfiguration;
 import org.apache.commons.configuration2.MapConfiguration;
 import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.commons.configuration2.ex.ConfigurationRuntimeException;
@@ -387,12 +388,12 @@ public class XMLPropertyListConfiguratio
             printNode(out, indentLevel, config.getNodeModel().getNodeHandler()
                     .getRootNode());
         }
-        else if (value instanceof Configuration)
+        else if (value instanceof ImmutableConfiguration)
         {
             // display a flat Configuration as a dictionary
             out.println(padding + "<dict>");
 
-            Configuration config = (Configuration) value;
+            ImmutableConfiguration config = (ImmutableConfiguration) value;
             Iterator<String> it = config.getKeys();
             while (it.hasNext())
             {

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java?rev=1785885&r1=1785884&r2=1785885&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java
Tue Mar  7 20:59:38 2017
@@ -59,7 +59,7 @@ public class ConfigurationAssert
      * @param expected the expected properties
      * @param actual the configuration to check
      */
-    public static void assertConfigurationEquals(Configuration expected, Configuration actual)
+    public static void assertConfigurationEquals(ImmutableConfiguration expected, ImmutableConfiguration
actual)
     {
         // check that the actual configuration contains all the properties of the expected
configuration
         for (Iterator<String> it = expected.getKeys(); it.hasNext();)
@@ -150,7 +150,7 @@ public class ConfigurationAssert
      * @param config the configuration
      * @return a list with all keys of this configuration
      */
-    public static List<String> keysToList(Configuration config)
+    public static List<String> keysToList(ImmutableConfiguration config)
     {
         List<String> keyList = new LinkedList<String>();
         appendKeys(config, keyList);
@@ -163,7 +163,7 @@ public class ConfigurationAssert
      * @param config the configuration
      * @return a set with all keys of this configuration
      */
-    public static Set<String> keysToSet(Configuration config)
+    public static Set<String> keysToSet(ImmutableConfiguration config)
     {
         Set<String> keySet = new HashSet<String>();
         appendKeys(config, keySet);
@@ -176,7 +176,7 @@ public class ConfigurationAssert
      * @param config the configuration
      * @param collection the target collection
      */
-    public static void appendKeys(Configuration config,
+    public static void appendKeys(ImmutableConfiguration config,
             Collection<String> collection)
     {
         for (Iterator<String> it = config.getKeys(); it.hasNext();)



Mime
View raw message