Currently the string based properties are handled as follows:

foo.bar = aaa
foo.bar = bbb

Configuration object returns "aaa" when using the following call:
getString("foo.bar"). However, in this scenario:

foo.bar = 1
foo.bar = 2

... calling getInt("foo.bar") will cause ClassCastException because multiple
instances of the same property are put in a Container object.

I propose that non-string properties (such as int, long, double, float,
byte) are handled the same way as strings. This is useful if you want to
keep the original property file intact and include it in a custom property
file:

site.properties:
================
...
services.TemplateService.layout.cache.size=20
...
include = TurbineResources.properties

TurbineResources.properties:
============================
...
services.TemplateService.layout.cache.size=10

In the above scenario, call to
getInt("services.TemplateService.layout.cache.size") should return 20 rather
than throw a ClassCastException. Attached patch implements my proposal.

Best regards,

Mark Orciuch - [EMAIL PROTECTED]
Jakarta Jetspeed - Enterprise Portal in Java
http://jakarta.apache.org/jetspeed/
Index: BaseConfiguration.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/BaseConfiguration.java,v
retrieving revision 1.5
diff -u -r1.5 BaseConfiguration.java
--- BaseConfiguration.java      3 Dec 2002 14:13:55 -0000       1.5
+++ BaseConfiguration.java      20 Dec 2002 21:59:27 -0000
@@ -632,6 +632,13 @@
             Boolean b = new Boolean(s);
             return b;
         }
+        else if (value instanceof Container)
+        {
+          Container c = (Container) value;
+          String s = testBoolean((String) c.get(0));
+          Boolean b = new Boolean(s);
+          return b;
+        }
         else if (value == null)
         {
             if (defaults != null)
@@ -717,6 +724,12 @@
             Byte b = new Byte((String) value);
             return b;
         }
+        else if (value instanceof Container)
+        {
+          Container c = (Container) value;
+          Byte b = new Byte((String) c.get(0));
+          return b;
+        }
         else if (value == null)
         {
             if (defaults != null)
@@ -802,6 +815,12 @@
             Double d = new Double((String) value);
             return d;
         }
+        else if (value instanceof Container)
+        {
+          Container c = (Container) value;
+          Double d = new Double((String) c.get(0));
+          return d;
+        }
         else if (value == null)
         {
             if (defaults != null)
@@ -887,6 +906,12 @@
             Float f = new Float((String) value);
             return f;
         }
+        else if (value instanceof Container)
+        {
+          Container c = (Container) value;
+          Float f = new Float((String) c.get(0));
+          return f;
+        }
         else if (value == null)
         {
             if (defaults != null)
@@ -980,6 +1005,12 @@
             Integer i = new Integer((String) value);
             return i;
         }
+        else if (value instanceof Container)
+        {
+          Container c = (Container) value;
+          Integer i = new Integer((String) c.get(0));
+          return i;
+        }
         else if (value == null)
         {
             if (defaults != null)
@@ -1065,6 +1096,12 @@
             Long l = new Long((String) value);
             return l;
         }
+        else if (value instanceof Container)
+        {
+          Container c = (Container) value;
+          Long l = new Long((String) c.get(0));
+          return l;
+        }
         else if (value == null)
         {
             if (defaults != null)
@@ -1149,6 +1186,12 @@
         {
             Short s = new Short((String) value);
             return s;
+        }
+        else if (value instanceof Container)
+        {
+          Container c = (Container) value;
+          Short s = new Short((String) c.get(0));
+          return s;
         }
         else if (value == null)
         {

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to