commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r652316 - in /commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/beanutils/ src/test/org/apache/commons/configuration/beanutils/ xdocs/
Date Wed, 30 Apr 2008 11:00:01 GMT
Author: ebourg
Date: Wed Apr 30 03:59:58 2008
New Revision: 652316

URL: http://svn.apache.org/viewvc?rev=652316&view=rev
Log:
Fixed a bug in ConfigurationDynaBean that prevented to work with indexed properties stored
internally as arrays (CONFIGURATION-322)

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java
    commons/proper/configuration/trunk/xdocs/changes.xml

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java?rev=652316&r1=652315&r2=652316&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java
Wed Apr 30 03:59:58 2008
@@ -21,6 +21,7 @@
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -1134,6 +1135,10 @@
         {
             list = defaultValue;
         }
+        else if (value.getClass().isArray())
+        {
+            return Arrays.asList((Object[]) value);
+        }
         else
         {
             throw new ConversionException('\'' + key + "' doesn't map to a List object: "
+ value + ", a "

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java?rev=652316&r1=652315&r2=652316&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java
Wed Apr 30 03:59:58 2008
@@ -169,7 +169,7 @@
         }
         catch (ConversionException e)
         {
-            throw new IllegalArgumentException("Property '" + name + "' is not indexed.");
+            throw new IllegalArgumentException("Property '" + name + "' is not indexed.",
e);
         }
     }
 
@@ -213,7 +213,7 @@
             }
             else if (property.getClass().isArray())
             {
-                Array.set(value, index, value);
+                Array.set(property, index, value);
             }
             else if (index == 0)
             {
@@ -226,7 +226,7 @@
         }
         catch (ConversionException e)
         {
-            throw new IllegalArgumentException("Property '" + name + "' is not indexed.");
+            throw new IllegalArgumentException("Property '" + name + "' is not indexed.",
e);
         }
     }
 

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java?rev=652316&r1=652315&r2=652316&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java
Wed Apr 30 03:59:58 2008
@@ -18,14 +18,17 @@
 package org.apache.commons.configuration.beanutils;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-import junitx.framework.ObjectAssert;
 import org.apache.commons.beanutils.DynaProperty;
 import org.apache.commons.configuration.BaseConfiguration;
 import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.MapConfiguration;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+import junitx.framework.ObjectAssert;
 
 /**
  * <p>Test Case for the <code>ConfigurationDynaBean</code> implementation
class.
@@ -550,6 +553,24 @@
     }
 
     /**
+     * Test the modification of a configuration property stored internally as an array.
+     */
+    public void testSetArrayValue()
+    {
+        MapConfiguration configuration = new MapConfiguration(new HashMap());
+        configuration.getMap().put("objectArray", new Object[] {"value1", "value2", "value3"});
+
+        ConfigurationDynaBean bean = new ConfigurationDynaBean(configuration);
+
+        bean.set("objectArray", 1, "New Value 1");
+        Object value = bean.get("objectArray", 1);
+
+        assertNotNull("Returned new value 1", value);
+        ObjectAssert.assertInstanceOf("Returned String new value 1", String.class,  value);
+        assertEquals("Returned correct new value 1", "New Value 1", (String) value);
+    }
+
+    /**
      * Positive and negative tests on setMappedProperty valid arguments.
      */
     public void testSetMappedValues()

Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=652316&r1=652315&r2=652316&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Wed Apr 30 03:59:58 2008
@@ -23,6 +23,10 @@
 
   <body>
     <release version="1.6" date="in SVN" description="">
+      <action dev="ebourg" type="fix" issue="CONFIGURATION-322">
+        ConfigurationDynaBean now works properly with indexed properties
+        stored internally in the underlying configuration as arrays.
+      </action>
       <action dev="ebourg" type="fix" issue="CONFIGURATION-320">
         XMLPropertyListConfiguration is no longer limited to 32 bits integers.
       </action>



Mime
View raw message