commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1437179 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java test/java/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java
Date Tue, 22 Jan 2013 21:19:59 GMT
Author: oheger
Date: Tue Jan 22 21:19:59 2013
New Revision: 1437179

URL: http://svn.apache.org/viewvc?rev=1437179&view=rev
Log:
Added a method for obtaining all default prefix Lookups as a map.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java?rev=1437179&r1=1437178&r2=1437179&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java
Tue Jan 22 21:19:59 2013
@@ -91,6 +91,9 @@ public class ConfigurationInterpolator
     /** Constant for the prefix separator. */
     private static final char PREFIX_SEPARATOR = ':';
 
+    /** A map containing the default prefix lookups. */
+    private static final Map<String, Lookup> DEFAULT_PREFIX_LOOKUPS;
+
     /** A map with the currently registered lookup objects. */
     private final Map<String, Lookup> prefixLookups;
 
@@ -139,6 +142,20 @@ public class ConfigurationInterpolator
     }
 
     /**
+     * Returns a map containing the default prefix lookups. Every configuration
+     * object derived from {@code AbstractConfiguration} is by default
+     * initialized with a {@code ConfigurationInterpolator} containing these
+     * {@code Lookup} objects and their prefixes. The map cannot be modified
+     *
+     * @return a map with the default prefix {@code Lookup} objects and their
+     *         prefixes
+     */
+    public static Map<String, Lookup> getDefaultPrefixLookups()
+    {
+        return DEFAULT_PREFIX_LOOKUPS;
+    }
+
+    /**
      * Returns a map with the currently registered {@code Lookup} objects and
      * their prefixes. This is a snapshot copy of the internally used map. So
      * modifications of this map do not effect this instance.
@@ -450,4 +467,14 @@ public class ConfigurationInterpolator
         ci.setParentInterpolator(spec.getParentInterpolator());
         return ci;
     }
+
+    static
+    {
+        Map<String, Lookup> lookups = new HashMap<String, Lookup>();
+        for (DefaultLookups l : DefaultLookups.values())
+        {
+            lookups.put(l.getPrefix(), l.getLookup());
+        }
+        DEFAULT_PREFIX_LOOKUPS = Collections.unmodifiableMap(lookups);
+    }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java?rev=1437179&r1=1437178&r2=1437179&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java
Tue Jan 22 21:19:59 2013
@@ -537,4 +537,31 @@ public class TestConfigurationInterpolat
         assertSame("Wrong prefix lookup", preLookup, ci.getLookups().get("p"));
         assertSame("Wrong parent", interpolator, ci.getParentInterpolator());
     }
+
+    /**
+     * Tests whether default prefix lookups can be queried as a map.
+     */
+    @Test
+    public void testGetDefaultPrefixLookups()
+    {
+        Map<String, Lookup> lookups =
+                ConfigurationInterpolator.getDefaultPrefixLookups();
+        assertEquals("Wrong number of lookups", DefaultLookups.values().length,
+                lookups.size());
+        for (DefaultLookups l : DefaultLookups.values())
+        {
+            assertSame("Wrong entry for " + l, l.getLookup(),
+                    lookups.get(l.getPrefix()));
+        }
+    }
+
+    /**
+     * Tests that the map with default lookups cannot be modified.
+     */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testGetDefaultPrefixLookupsModify()
+    {
+        ConfigurationInterpolator.getDefaultPrefixLookups().put("test",
+                EasyMock.createMock(Lookup.class));
+    }
 }



Mime
View raw message