[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    svn commit: r491251 - in /jakarta/commons/proper/configuration/trunk:
From:       oheger () apache ! org
Date:       2006-12-30 16:36:46
Message-ID: 20061230163647.056D41A981A () eris ! apache ! org
[Download RAW message or body]

Author: oheger
Date: Sat Dec 30 08:36:46 2006
New Revision: 491251

URL: http://svn.apache.org/viewvc?view=rev&rev=491251
Log:
CONFIGURATION-192: Provide access to the ConfigurationInterpolator object associated \
with a configuration; more unit tests

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java
  jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
  jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java
                
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/ \
org/apache/commons/configuration/AbstractConfiguration.java?view=diff&rev=491251&r1=491250&r2=491251
 ==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java \
                (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java \
Sat Dec 30 08:36:46 2006 @@ -252,6 +252,25 @@
     }
 
     /**
+     * Returns the <code>ConfigurationInterpolator</code> object that manages
+     * the lookup objects for resolving variables. <em>Note:</em> If this
+     * object is manipulated (e.g. new lookup objects added), synchronisation
+     * has to be manually ensured. Because
+     * <code>ConfigurationInterpolator</code> is not thread-safe concurrent
+     * access to properties of this configuration instance (which causes the
+     * interpolator to be invoked) may cause race conditions.
+     *
+     * @return the <code>ConfigurationInterpolator</code> associated with this
+     * configuration
+     * @since 1.4
+     */
+    public ConfigurationInterpolator getInterpolator()
+    {
+        return (ConfigurationInterpolator) getSubstitutor()
+                .getVariableResolver();
+    }
+
+    /**
      * Creates the interpolator object that is responsible for variable
      * interpolation. This method is invoked on first access of the
      * interpolation features. It creates a new instance of

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
                
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/ \
org/apache/commons/configuration/TestBaseConfiguration.java?view=diff&rev=491251&r1=491250&r2=491251
 ==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java \
                (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java \
Sat Dec 30 08:36:46 2006 @@ -17,6 +17,7 @@
 
 package org.apache.commons.configuration;
 
+import java.awt.event.KeyEvent;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
@@ -29,6 +30,8 @@
 
 import org.apache.commons.configuration.event.ConfigurationEvent;
 import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
+import org.apache.commons.lang.text.StrLookup;
 
 import junit.framework.TestCase;
 import junitx.framework.ListAssert;
@@ -705,6 +708,17 @@
     }
 
     /**
+     * Tests interpolation of constant values.
+     */
+    public void testInterpolationConstants()
+    {
+        config.addProperty("key.code",
+                "${const:java.awt.event.KeyEvent.VK_CANCEL}");
+        assertEquals("Wrong value of constant variable", KeyEvent.VK_CANCEL,
+                config.getInt("key.code"));
+    }
+
+    /**
      * Tests whether a variable can be escaped, so that it won't be
      * interpolated.
      */
@@ -714,6 +728,24 @@
         config.addProperty("escVar", "Use the variable $${${var}}.");
         assertEquals("Wrong escaped variable", "Use the variable ${x}.", config
                 .getString("escVar"));
+    }
+
+    /**
+     * Tests accessing and manipulating the interpolator object.
+     */
+    public void testGetInterpolator()
+    {
+        config.addProperty("var", "${echo:testVar}");
+        ConfigurationInterpolator interpol = config.getInterpolator();
+        interpol.registerLookup("echo", new StrLookup()
+        {
+            public String lookup(String varName)
+            {
+                return "Value of variable " + varName;
+            }
+        });
+        assertEquals("Wrong value of echo variable",
+                "Value of variable testVar", config.getString("var"));
     }
 
     public void testGetHexadecimalValue()

Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?view=diff&rev=491251&r1=491250&r2=491251
 ==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Sat Dec 30 08:36:46 \
2006 @@ -23,6 +23,14 @@
 
   <body>
     <release version="1.4-dev" date="in SVN">
+      <action dev="oheger" type="add" issue="CONFIGURATION-192">
+        Variable interpolation features have been improved. A variable can now
+        have the form <code>${prefix:variableName}</code> where the prefix
+        defines the type of the variable. The standard types <em>sys</em> for
+        system properties and <em>const</em> for constants are supported.
+        Variables without a prefix are treated as references to other
+        configuration properties (which is compatible to earlier versions).
+      </action>
       <action dev="oheger" type="update" issue="CONFIGURATION-244">
         The number of dependencies needed for DefaultConfigurationBuilder was
         reduced by letting some of the default configuration providers resolve



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic