You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by eb...@apache.org on 2007/04/19 20:29:49 UTC

svn commit: r530508 - in /jakarta/commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/plist/ src/test/org/apache/commons/configuration/plist/ xdocs/

Author: ebourg
Date: Thu Apr 19 11:29:47 2007
New Revision: 530508

URL: http://svn.apache.org/viewvc?view=rev&rev=530508
Log:
Fixed the storage of byte[] properties in the plist configurations

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java?view=diff&rev=530508&r1=530507&r2=530508
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java Thu Apr 19 11:29:47 2007
@@ -552,6 +552,7 @@
     {
         fireEvent(EVENT_SET_PROPERTY, key, value, true);
 
+        // Update the existing nodes for this property
         Iterator itNodes = fetchNodeList(key).iterator();
         Iterator itValues;
         if (!isDelimiterParsingDisabled())
@@ -562,6 +563,7 @@
         {
             itValues = new SingletonIterator(value);
         }
+
         while (itNodes.hasNext() && itValues.hasNext())
         {
             ((ConfigurationNode) itNodes.next()).setValue(itValues.next());

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java?view=diff&rev=530508&r1=530507&r2=530508
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java Thu Apr 19 11:29:47 2007
@@ -141,6 +141,20 @@
         super(url);
     }
 
+    public void setProperty(String key, Object value)
+    {
+        // special case for byte arrays, they must be stored as is in the configuration
+        if (value instanceof byte[])
+        {
+            clearProperty(key);
+            addPropertyDirect(key, value);
+        }
+        else
+        {
+            super.setProperty(key, value);
+        }
+    }
+
     public void load(Reader in) throws ConfigurationException
     {
         PropertyListParser parser = new PropertyListParser(in);

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java?view=diff&rev=530508&r1=530507&r2=530508
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java Thu Apr 19 11:29:47 2007
@@ -181,6 +181,20 @@
         super(url);
     }
 
+    public void setProperty(String key, Object value)
+    {
+        // special case for byte arrays, they must be stored as is in the configuration
+        if (value instanceof byte[])
+        {
+            clearProperty(key);
+            addPropertyDirect(key, value);
+        }
+        else
+        {
+            super.setProperty(key, value);
+        }
+    }
+
     public void load(Reader in) throws ConfigurationException
     {
         // set up the DTD validation

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java?view=diff&rev=530508&r1=530507&r2=530508
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java Thu Apr 19 11:29:47 2007
@@ -255,6 +255,25 @@
         assertEquals("string with a special char", "\"foo;bar\"", config.quoteString("foo;bar"));
     }
 
+    /**
+     * Ensure that setProperty doesn't alter an array of byte
+     * since it's a first class type in plist file
+     */
+    public void testSetDataProperty() throws Exception
+    {
+        byte[] expected = new byte[]{1, 2, 3, 4};
+        PropertyListConfiguration config = new PropertyListConfiguration();
+        config.setProperty("foo", expected);
+        config.save("target/testdata.plist");
+
+        PropertyListConfiguration config2 = new PropertyListConfiguration("target/testdata.plist");
+        Object array = config2.getProperty("foo");
+
+        assertNotNull("data not found", array);
+        assertEquals("property type", byte[].class, array.getClass());
+        ArrayAssert.assertEquals(expected, (byte[]) array);
+    }
+
     public void testInitCopy()
     {
     	PropertyListConfiguration copy = new PropertyListConfiguration(config);

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java?view=diff&rev=530508&r1=530507&r2=530508
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java Thu Apr 19 11:29:47 2007
@@ -255,11 +255,29 @@
         }
     }
 
-	public void testInitCopy()
+    /**
+     * Ensure that setProperty doesn't alter an array of byte
+     * since it's a first class type in plist file
+     */
+    public void testSetDataProperty() throws Exception
+    {
+        byte[] expected = new byte[]{1, 2, 3, 4};
+        XMLPropertyListConfiguration config = new XMLPropertyListConfiguration();
+        config.setProperty("foo", expected);
+        config.save("target/testdata.plist.xml");
+
+        XMLPropertyListConfiguration config2 = new XMLPropertyListConfiguration("target/testdata.plist.xml");
+        Object array = config2.getProperty("foo");
+
+        assertNotNull("data not found", array);
+        assertEquals("property type", byte[].class, array.getClass());
+        ArrayAssert.assertEquals(expected, (byte[]) array);
+    }
+
+    public void testInitCopy()
 	{
-		XMLPropertyListConfiguration copy = new XMLPropertyListConfiguration(
-				(HierarchicalConfiguration) config);
+		XMLPropertyListConfiguration copy = new XMLPropertyListConfiguration((HierarchicalConfiguration) config);
 		StrictConfigurationComparator comp = new StrictConfigurationComparator();
 		assertTrue("Configurations are not equal", comp.compare(config, copy));
 	}
-}
+}
\ No newline at end of file

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=530508&r1=530507&r2=530508
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Thu Apr 19 11:29:47 2007
@@ -23,6 +23,10 @@
 
   <body>
     <release version="1.5-SNAPSHOT" date="in SVN" description="">
+      <action dev="ebourg" type="fix">
+        byte[] properties are properly saved as data fields in the plist
+        configurations (PropertyListConfiguration and XMLPropertyListConfiguration).
+      </action>
       <action dev="ebourg" type="add">
         DataConfiguration now supports the java.net.InetAddress and
         javax.mail.internet.InternetAddress types. Properties are
@@ -34,8 +38,8 @@
         throwExceptionOnMissing is set.
       </action>
       <action dev="ebourg" type="add">
-        Generic getters have been added to DataConfiguration (get(), getArray()
-        and getList())
+        Generic get methods have been added to DataConfiguration (get(),
+        getArray() and getList())
       </action>
       <action dev="oheger" type="fix" issue="CONFIGURATION-263">
         XMLConfiguration used to drop attributes when an element's value was a



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