commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r629741 - /commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java
Date Thu, 21 Feb 2008 10:47:59 GMT
Author: ebourg
Date: Thu Feb 21 02:47:45 2008
New Revision: 629741

URL: http://svn.apache.org/viewvc?rev=629741&view=rev
Log:
Fixed the String->char conversion necessary for BeanHelper without beanutils

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java?rev=629741&r1=629740&r2=629741&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java
Thu Feb 21 02:47:45 2008
@@ -95,6 +95,10 @@
         {
             result = toBoolean(value);
         }
+        else if (Character.class.equals(cls) || Character.TYPE.equals(cls))
+        {
+            result = toCharacter(value);
+        }
         else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive())
         {
             if (Integer.class.equals(cls) || Integer.TYPE.equals(cls))
@@ -205,6 +209,29 @@
         else
         {
             throw new ConversionException("The value " + value + " can't be converted to
a Boolean object");
+        }
+    }
+
+    /**
+     * Convert the specified object into a Character.
+     *
+     * @param value the value to convert
+     * @return the converted value
+     * @throws ConversionException thrown if the value cannot be converted to a character
+     */
+    static Character toCharacter(Object value) throws ConversionException
+    {
+        if (value instanceof Character)
+        {
+            return (Character) value;
+        }
+        else if (value instanceof CharSequence && ((CharSequence) value).length()
== 1)
+        {
+            return ((CharSequence) value).charAt(0);
+        }
+        else
+        {
+            throw new ConversionException("The value " + value + " can't be converted to
a Character object");
         }
     }
 



Mime
View raw message