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/20 01:08:37 UTC

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

Author: ebourg
Date: Thu Apr 19 16:08:36 2007
New Revision: 530587

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

Modified:
    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

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=530587&r1=530586&r2=530587
==============================================================================
--- 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 16:08:36 2007
@@ -155,6 +155,20 @@
         }
     }
 
+    public void addProperty(String key, Object value)
+    {
+        if (value instanceof byte[])
+        {
+            fireEvent(EVENT_ADD_PROPERTY, key, value, true);
+            addPropertyDirect(key, value);
+            fireEvent(EVENT_ADD_PROPERTY, key, value, false);
+        }
+        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=530587&r1=530586&r2=530587
==============================================================================
--- 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 16:08:36 2007
@@ -195,6 +195,20 @@
         }
     }
 
+    public void addProperty(String key, Object value)
+    {
+        if (value instanceof byte[])
+        {
+            fireEvent(EVENT_ADD_PROPERTY, key, value, true);
+            addPropertyDirect(key, value);
+            fireEvent(EVENT_ADD_PROPERTY, key, value, false);
+        }
+        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=530587&r1=530586&r2=530587
==============================================================================
--- 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 16:08:36 2007
@@ -274,6 +274,24 @@
         ArrayAssert.assertEquals(expected, (byte[]) array);
     }
 
+    /**
+     * Ensure that addProperty doesn't alter an array of byte
+     */
+    public void testAddDataProperty() throws Exception
+    {
+        byte[] expected = new byte[]{1, 2, 3, 4};
+        PropertyListConfiguration config = new PropertyListConfiguration();
+        config.addProperty("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=530587&r1=530586&r2=530587
==============================================================================
--- 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 16:08:36 2007
@@ -274,10 +274,28 @@
         ArrayAssert.assertEquals(expected, (byte[]) array);
     }
 
+    /**
+     * Ensure that addProperty doesn't alter an array of byte
+     */
+    public void testAddDataProperty() throws Exception
+    {
+        byte[] expected = new byte[]{1, 2, 3, 4};
+        XMLPropertyListConfiguration config = new XMLPropertyListConfiguration();
+        config.addProperty("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);
 		StrictConfigurationComparator comp = new StrictConfigurationComparator();
 		assertTrue("Configurations are not equal", comp.compare(config, copy));
 	}
-}
\ No newline at end of file
+}



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