You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2008/04/07 19:24:44 UTC

svn commit: r645622 [1/2] - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/ main/java/org/apache/commons/configuration2/beanutils/ main/java/org/apache/commons/configuration2/conve...

Author: ebourg
Date: Mon Apr  7 10:24:32 2008
New Revision: 645622

URL: http://svn.apache.org/viewvc?rev=645622&view=rev
Log:
First stab at implementing a pluggable conversion system
- The Converter interface provides a general contract for transforming values, a default implementation is provided and can be extended
- every configuration has a Converter instance
- The conversion methods from PropertyConverter have been split into TypeConverter classes

Added:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigDecimalConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigIntegerConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BooleanConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ByteConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CalendarConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CharacterConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ColorConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/Converter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DateConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DefaultPropertyConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DoubleConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/FloatConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/InetAddressConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/IntegerConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/InternetAddressConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/LocaleConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/LongConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/NumberConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ShortConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/TypeConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/URLConverter.java   (with props)
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/package.html
Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertyConverter.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/beanutils/BeanHelper.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertyConverter.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java?rev=645622&r1=645621&r2=645622&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java Mon Apr  7 10:24:32 2008
@@ -29,6 +29,8 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.commons.configuration2.converter.Converter;
+import org.apache.commons.configuration2.converter.DefaultPropertyConverter;
 import org.apache.commons.configuration2.event.ConfigurationErrorEvent;
 import org.apache.commons.configuration2.event.ConfigurationErrorListener;
 import org.apache.commons.configuration2.event.EventSource;
@@ -142,6 +144,9 @@
     /** Stores a reference to the object that handles variable interpolation.*/
     private StrSubstitutor substitutor;
 
+    /** Converter used for the transformation of the properties. */
+    protected Converter converter = new DefaultPropertyConverter();
+
     /** Stores the logger.*/
     private Logger log;
 
@@ -335,6 +340,29 @@
     }
 
     /**
+     * Returns the Converter used for the transformation of the properties.
+     * By default the {@link DefaultPropertyConverter} is used.
+     *
+     * @return
+     * @since 2.0
+     */
+    public Converter getConverter()
+    {
+        return converter;
+    }
+
+    /**
+     * Sets the Converter used for the transformation of the properties.
+     *
+     * @param converter
+     * @since 2.0
+     */
+    public void setConverter(Converter converter)
+    {
+        this.converter = converter;
+    }
+
+    /**
      * Returns the logger used by this configuration object.
      *
      * @return the logger
@@ -620,10 +648,6 @@
         return props;
     }
 
-    /**
-     * {@inheritDoc}
-     * @see PropertyConverter#toBoolean(Object)
-     */
     public boolean getBoolean(String key)
     {
         Boolean b = getBoolean(key, null);
@@ -637,10 +661,6 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     * @see PropertyConverter#toBoolean(Object)
-     */
     public boolean getBoolean(String key, boolean defaultValue)
     {
         return getBoolean(key, BooleanUtils.toBooleanObject(defaultValue)).booleanValue();
@@ -656,7 +676,6 @@
      * @return the value of this key converted to a <code>Boolean</code>
      * @throws ConversionException if the value cannot be converted to a
      * <code>Boolean</code>
-     * @see PropertyConverter#toBoolean(Object)
      */
     public Boolean getBoolean(String key, Boolean defaultValue)
     {
@@ -670,7 +689,7 @@
         {
             try
             {
-                return PropertyConverter.toBoolean(interpolate(value));
+                return converter.convert(Boolean.class, interpolate(value));
             }
             catch (ConversionException e)
             {
@@ -709,7 +728,7 @@
         {
             try
             {
-                return PropertyConverter.toByte(interpolate(value));
+                return converter.convert(Byte.class, interpolate(value));
             }
             catch (ConversionException e)
             {
@@ -748,7 +767,7 @@
         {
             try
             {
-                return PropertyConverter.toDouble(interpolate(value));
+                return converter.convert(Double.class, interpolate(value));
             }
             catch (ConversionException e)
             {
@@ -787,7 +806,7 @@
         {
             try
             {
-                return PropertyConverter.toFloat(interpolate(value));
+                return converter.convert(Float.class, interpolate(value));
             }
             catch (ConversionException e)
             {
@@ -833,7 +852,7 @@
         {
             try
             {
-                return PropertyConverter.toInteger(interpolate(value));
+                return converter.convert(Integer.class, interpolate(value));
             }
             catch (ConversionException e)
             {
@@ -872,7 +891,7 @@
         {
             try
             {
-                return PropertyConverter.toLong(interpolate(value));
+                return converter.convert(Long.class, interpolate(value));
             }
             catch (ConversionException e)
             {
@@ -911,7 +930,7 @@
         {
             try
             {
-                return PropertyConverter.toShort(interpolate(value));
+                return converter.convert(Short.class, interpolate(value));
             }
             catch (ConversionException e)
             {
@@ -953,7 +972,7 @@
         {
             try
             {
-                return PropertyConverter.toBigDecimal(interpolate(value));
+                return converter.convert(BigDecimal.class, interpolate(value));
             }
             catch (ConversionException e)
             {
@@ -995,7 +1014,7 @@
         {
             try
             {
-                return PropertyConverter.toBigInteger(interpolate(value));
+                return converter.convert(BigInteger.class, interpolate(value));
             }
             catch (ConversionException e)
             {

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java?rev=645622&r1=645621&r2=645622&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java Mon Apr  7 10:24:32 2008
@@ -223,11 +223,11 @@
             {
                 if (Date.class.equals(cls) || Calendar.class.equals(cls))
                 {
-                    return PropertyConverter.to(cls, interpolate(value), getDefaultDateFormat());
+                    return converter.convert(cls, interpolate(value), getDefaultDateFormat());
                 }
                 else
                 {
-                    return PropertyConverter.to(cls, interpolate(value));
+                    return converter.convert(cls, interpolate(value));
                 }
             }
             catch (ConversionException e)
@@ -315,7 +315,7 @@
                         // attempt to convert the elements of the array
                         for (int i = 0; i < length; i++)
                         {
-                            list.add(PropertyConverter.to(cls, interpolate(Array.get(value, i)), params));
+                            list.add(converter.convert(cls, interpolate(Array.get(value, i)), params));
                         }
                     }
                 }
@@ -325,13 +325,13 @@
 
                     for (Object o : values)
                     {
-                        list.add(PropertyConverter.to(cls, interpolate(o), params));
+                        list.add(converter.convert(cls, interpolate(o), params));
                     }
                 }
                 else
                 {
                     // attempt to convert a single value
-                    list.add(PropertyConverter.to(cls, interpolate(value), params));
+                    list.add(converter.convert(cls, interpolate(value), params));
                 }
             }
             catch (ConversionException e)
@@ -471,7 +471,7 @@
                 int i = 0;
                 for (Object o : values)
                 {
-                    Array.set(array, i++, PropertyConverter.to(ClassUtils.primitiveToWrapper(cls), interpolate(o)));
+                    Array.set(array, i++, converter.convert(ClassUtils.primitiveToWrapper(cls), interpolate(o)));
                 }
             }
             else
@@ -479,7 +479,7 @@
                 try
                 {
                     // attempt to convert a single value
-                    Object convertedValue = PropertyConverter.to(ClassUtils.primitiveToWrapper(cls), interpolate(value));
+                    Object convertedValue = converter.convert(ClassUtils.primitiveToWrapper(cls), interpolate(value));
 
                     // create an array of one element
                     array = Array.newInstance(cls, 1);
@@ -1267,7 +1267,7 @@
         {
             try
             {
-                return PropertyConverter.toDate(interpolate(value), format);
+                return converter.convert(Date.class, interpolate(value), format);
             }
             catch (ConversionException e)
             {
@@ -1362,7 +1362,7 @@
             int length = Array.getLength(value);
             for (int i = 0; i < length; i++)
             {
-                list.add(PropertyConverter.toDate(interpolate(Array.get(value, i)), format));
+                list.add(converter.convert(Date.class, interpolate(Array.get(value, i)), format));
             }
         }
         else if (value instanceof Collection)
@@ -1372,7 +1372,7 @@
 
             for (Object o : values)
             {
-                list.add(PropertyConverter.toDate(interpolate(o), format));
+                list.add(converter.convert(Date.class, interpolate(o), format));
             }
         }
         else
@@ -1381,7 +1381,7 @@
             {
                 // attempt to convert a single value
                 list = new ArrayList<Date>();
-                list.add(PropertyConverter.toDate(interpolate(value), format));
+                list.add(converter.convert(Date.class, interpolate(value), format));
             }
             catch (ConversionException e)
             {
@@ -1565,7 +1565,7 @@
         {
             try
             {
-                return PropertyConverter.toCalendar(interpolate(value), format);
+                return converter.convert(Calendar.class, interpolate(value), format);
             }
             catch (ConversionException e)
             {
@@ -1660,7 +1660,7 @@
             int length = Array.getLength(value);
             for (int i = 0; i < length; i++)
             {
-                list.add(PropertyConverter.toCalendar(interpolate(Array.get(value, i)), format));
+                list.add(converter.convert(Calendar.class, interpolate(Array.get(value, i)), format));
             }
         }
         else if (value instanceof Collection)
@@ -1670,7 +1670,7 @@
 
             for (Object o : values)
             {
-                list.add(PropertyConverter.toCalendar(interpolate(o), format));
+                list.add(converter.convert(Calendar.class, interpolate(o), format));
             }
         }
         else
@@ -1679,7 +1679,7 @@
             {
                 // attempt to convert a single value
                 list = new ArrayList<Calendar>();
-                list.add(PropertyConverter.toCalendar(interpolate(value), format));
+                list.add(converter.convert(Calendar.class, interpolate(value), format));
             }
             catch (ConversionException e)
             {

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=645622&r1=645621&r2=645622&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 Mon Apr  7 10:24:32 2008
@@ -17,28 +17,13 @@
 
 package org.apache.commons.configuration2;
 
-import java.awt.Color;
 import java.lang.reflect.Array;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.net.InetAddress;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.UnknownHostException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Collection;
-import java.util.Date;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Locale;
 
-import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.StringUtils;
 
 /**
@@ -56,15 +41,6 @@
     /** Constant for the list delimiter escaping character as string.*/
     static final String LIST_ESCAPE = String.valueOf(LIST_ESC_CHAR);
 
-    /** Constant for the prefix of hex numbers.*/
-    private static final String HEX_PREFIX = "0x";
-
-    /** Constant for the radix of hex numbers.*/
-    private static final int HEX_RADIX = 16;
-
-    /** The fully qualified name of {@link javax.mail.internet.InternetAddress} */
-    private static final String INTERNET_ADDRESS_CLASSNAME = "javax.mail.internet.InternetAddress";
-
     /**
      * Private constructor prevents instances from being created.
      */
@@ -74,451 +50,6 @@
     }
 
     /**
-     * Converts the specified value to the target class. If the class is a
-     * primitive type (Integer.TYPE, Boolean.TYPE, etc) the value returned
-     * will use the wrapper type (Integer.class, Boolean.class, etc).
-     *
-     * @param cls   the target class of the converted value
-     * @param value the value to convert
-     * @param params optional parameters used for the conversion
-     * @return the converted value
-     * @throws ConversionException if the value is not compatible with the requested type
-     *
-     * @since 1.5
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> T to(Class<T> cls, Object value, Object... params) throws ConversionException
-    {
-        Object result = null;
-
-        if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls))
-        {
-            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))
-            {
-                result = toInteger(value);
-            }
-            else if (Long.class.equals(cls) || Long.TYPE.equals(cls))
-            {
-                result = toLong(value);
-            }
-            else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls))
-            {
-                result = toByte(value);
-            }
-            else if (Short.class.equals(cls) || Short.TYPE.equals(cls))
-            {
-                result = toShort(value);
-            }
-            else if (Float.class.equals(cls) || Float.TYPE.equals(cls))
-            {
-                result = toFloat(value);
-            }
-            else if (Double.class.equals(cls) || Double.TYPE.equals(cls))
-            {
-                result = toDouble(value);
-            }
-            else if (BigInteger.class.equals(cls))
-            {
-                result = toBigInteger(value);
-            }
-            else if (BigDecimal.class.equals(cls))
-            {
-                result = toBigDecimal(value);
-            }
-        }
-        else if (Date.class.equals(cls))
-        {
-            result = toDate(value, (String) params[0]);
-        }
-        else if (Calendar.class.equals(cls))
-        {
-            result = toCalendar(value, (String) params[0]);
-        }
-        else if (URL.class.equals(cls))
-        {
-            result = toURL(value);
-        }
-        else if (Locale.class.equals(cls))
-        {
-            result = toLocale(value);
-        }
-        else if (cls.isEnum())
-        {
-            // This causes an unchecked warning because the concrete Enum class
-            // cannot be fully determined.
-            result = toEnum(value, cls.asSubclass(Enum.class));
-        }
-        else if (Color.class.equals(cls))
-        {
-            result = toColor(value);
-        }
-        else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME))
-        {
-            result = toInternetAddress(value);
-        }
-        else if (InetAddress.class.isAssignableFrom(cls))
-        {
-            result = toInetAddress(value);
-        }
-        else
-        {
-            throw new ConversionException("The value '" + value + "' ("
-                    + value.getClass() + ")" + " can't be converted to a "
-                    + cls.getName() + " object");
-        }
-
-        return (T) result;
-    }
-
-    /**
-     * Convert the specified object into a Boolean. Internally the
-     * <code>org.apache.commons.lang.BooleanUtils</code> class from the
-     * <a href="http://commons.apache.org/lang/">Commons Lang</a>
-     * project is used to perform this conversion. This class accepts some more
-     * tokens for the boolean value of <b>true</b>, e.g. <code>yes</code> and
-     * <code>on</code>. Please refer to the documentation of this class for more
-     * details.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a boolean
-     */
-    public static Boolean toBoolean(Object value) throws ConversionException
-    {
-        if (value instanceof Boolean)
-        {
-            return (Boolean) value;
-        }
-        else if (value instanceof String)
-        {
-            Boolean b = BooleanUtils.toBooleanObject((String) value);
-            if (b == null)
-            {
-                throw new ConversionException("The value " + value + " can't be converted to a Boolean object");
-            }
-            return b;
-        }
-        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");
-        }
-    }
-
-    /**
-     * Convert the specified object into a Byte.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a byte
-     */
-    public static Byte toByte(Object value) throws ConversionException
-    {
-        Number n = toNumber(value, Byte.class);
-        if (n instanceof Byte)
-        {
-            return (Byte) n;
-        }
-        else
-        {
-            return new Byte(n.byteValue());
-        }
-    }
-
-    /**
-     * Convert the specified object into a Short.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a short
-     */
-    public static Short toShort(Object value) throws ConversionException
-    {
-        Number n = toNumber(value, Short.class);
-        if (n instanceof Short)
-        {
-            return (Short) n;
-        }
-        else
-        {
-            return new Short(n.shortValue());
-        }
-    }
-
-    /**
-     * Convert the specified object into an Integer.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to an integer
-     */
-    public static Integer toInteger(Object value) throws ConversionException
-    {
-        Number n = toNumber(value, Integer.class);
-        if (n instanceof Integer)
-        {
-            return (Integer) n;
-        }
-        else
-        {
-            return new Integer(n.intValue());
-        }
-    }
-
-    /**
-     * Convert the specified object into a Long.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a Long
-     */
-    public static Long toLong(Object value) throws ConversionException
-    {
-        Number n = toNumber(value, Long.class);
-        if (n instanceof Long)
-        {
-            return (Long) n;
-        }
-        else
-        {
-            return new Long(n.longValue());
-        }
-    }
-
-    /**
-     * Convert the specified object into a Float.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a Float
-     */
-    public static Float toFloat(Object value) throws ConversionException
-    {
-        Number n = toNumber(value, Float.class);
-        if (n instanceof Float)
-        {
-            return (Float) n;
-        }
-        else
-        {
-            return new Float(n.floatValue());
-        }
-    }
-
-    /**
-     * Convert the specified object into a Double.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a Double
-     */
-    public static Double toDouble(Object value) throws ConversionException
-    {
-        Number n = toNumber(value, Double.class);
-        if (n instanceof Double)
-        {
-            return (Double) n;
-        }
-        else
-        {
-            return new Double(n.doubleValue());
-        }
-    }
-
-    /**
-     * Convert the specified object into a BigInteger.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a BigInteger
-     */
-    public static BigInteger toBigInteger(Object value) throws ConversionException
-    {
-        Number n = toNumber(value, BigInteger.class);
-        if (n instanceof BigInteger)
-        {
-            return (BigInteger) n;
-        }
-        else
-        {
-            return BigInteger.valueOf(n.longValue());
-        }
-    }
-
-    /**
-     * Convert the specified object into a BigDecimal.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a BigDecimal
-     */
-    public static BigDecimal toBigDecimal(Object value) throws ConversionException
-    {
-        Number n = toNumber(value, BigDecimal.class);
-        if (n instanceof BigDecimal)
-        {
-            return (BigDecimal) n;
-        }
-        else
-        {
-            return new BigDecimal(n.doubleValue());
-        }
-    }
-
-    /**
-     * Tries to convert the specified object into a number object. This method
-     * is used by the conversion methods for number types. Note that the return
-     * value is not in always of the specified target class, but only if a new
-     * object has to be created.
-     *
-     * @param value the value to be converted (must not be <b>null</b>)
-     * @param targetClass the target class of the conversion (must be derived
-     * from <code>java.lang.Number</code>)
-     * @return the converted number
-     * @throws ConversionException if the object cannot be converted
-     */
-    static Number toNumber(Object value, Class<? extends Number> targetClass) throws ConversionException
-    {
-        if (value instanceof Number)
-        {
-            return (Number) value;
-        }
-        else
-        {
-            String str = value.toString();
-            if (str.startsWith(HEX_PREFIX))
-            {
-                try
-                {
-                    return new BigInteger(str.substring(HEX_PREFIX.length()), HEX_RADIX);
-                }
-                catch (NumberFormatException nex)
-                {
-                    throw new ConversionException("Could not convert " + str
-                            + " to " + targetClass.getName()
-                            + "! Invalid hex number.", nex);
-                }
-            }
-
-            try
-            {
-                Constructor<? extends Number> constr = targetClass.getConstructor(String.class);
-                return (Number) constr.newInstance(str);
-            }
-            catch (InvocationTargetException itex)
-            {
-                throw new ConversionException("Could not convert " + str
-                        + " to " + targetClass.getName(), itex
-                        .getTargetException());
-            }
-            catch (Exception ex)
-            {
-                // Treat all possible exceptions the same way
-                throw new ConversionException(
-                        "Conversion error when trying to convert " + str
-                                + " to " + targetClass.getName(), ex);
-            }
-        }
-    }
-
-    /**
-     * Convert the specified object into an URL.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to an URL
-     */
-    public static URL toURL(Object value) throws ConversionException
-    {
-        if (value instanceof URL)
-        {
-            return (URL) value;
-        }
-        else if (value instanceof String)
-        {
-            try
-            {
-                return new URL((String) value);
-            }
-            catch (MalformedURLException e)
-            {
-                throw new ConversionException("The value " + value + " can't be converted to an URL", e);
-            }
-        }
-        else
-        {
-            throw new ConversionException("The value " + value + " can't be converted to an URL");
-        }
-    }
-
-    /**
-     * Convert the specified object into a Locale.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a Locale
-     */
-    public static Locale toLocale(Object value) throws ConversionException
-    {
-        if (value instanceof Locale)
-        {
-            return (Locale) value;
-        }
-        else if (value instanceof String)
-        {
-            String[] elements = ((String) value).split("_");
-            int size = elements.length;
-
-            if (size >= 1 && ((elements[0]).length() == 2 || (elements[0]).length() == 0))
-            {
-                String language = elements[0];
-                String country = (size >= 2) ? elements[1] : "";
-                String variant = (size >= 3) ? elements[2] : "";
-
-                return new Locale(language, country, variant);
-            }
-            else
-            {
-                throw new ConversionException("The value " + value + " can't be converted to a Locale");
-            }
-        }
-        else
-        {
-            throw new ConversionException("The value " + value + " can't be converted to a Locale");
-        }
-    }
-
-    /**
      * Split a string on the specified delimiter. To be removed when
      * commons-lang has a better replacement available (Tokenizer?).
      *
@@ -605,266 +136,6 @@
     {
         String s1 = StringUtils.replace(s, LIST_ESCAPE, LIST_ESCAPE + LIST_ESCAPE);
         return StringUtils.replace(s1, String.valueOf(delimiter), LIST_ESCAPE + delimiter);
-    }
-
-    /**
-     * Convert the specified object into a Color. If the value is a String,
-     * the format allowed is (#)?[0-9A-F]{6}([0-9A-F]{2})?. Examples:
-     * <ul>
-     *   <li>FF0000 (red)</li>
-     *   <li>0000FFA0 (semi transparent blue)</li>
-     *   <li>#CCCCCC (gray)</li>
-     *   <li>#00FF00A0 (semi transparent green)</li>
-     * </ul>
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a Color
-     */
-    public static Color toColor(Object value) throws ConversionException
-    {
-        if (value instanceof Color)
-        {
-            return (Color) value;
-        }
-        else if (value instanceof String && !StringUtils.isBlank((String) value))
-        {
-            String color = ((String) value).trim();
-
-            int[] components = new int[3];
-
-            // check the size of the string
-            int minlength = components.length * 2;
-            if (color.length() < minlength)
-            {
-                throw new ConversionException("The value " + value + " can't be converted to a Color");
-            }
-
-            // remove the leading #
-            if (color.startsWith("#"))
-            {
-                color = color.substring(1);
-            }
-
-            try
-            {
-                // parse the components
-                for (int i = 0; i < components.length; i++)
-                {
-                    components[i] = Integer.parseInt(color.substring(2 * i, 2 * i + 2), HEX_RADIX);
-                }
-
-                // parse the transparency
-                int alpha;
-                if (color.length() >= minlength + 2)
-                {
-                    alpha = Integer.parseInt(color.substring(minlength, minlength + 2), HEX_RADIX);
-                }
-                else
-                {
-                    alpha = Color.black.getAlpha();
-                }
-
-                return new Color(components[0], components[1], components[2], alpha);
-            }
-            catch (Exception e)
-            {
-                throw new ConversionException("The value " + value + " can't be converted to a Color", e);
-            }
-        }
-        else
-        {
-            throw new ConversionException("The value " + value + " can't be converted to a Color");
-        }
-    }
-
-    /**
-     * Convert the specified value into an internet address.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a InetAddress
-     *
-     * @since 1.5
-     */
-    static InetAddress toInetAddress(Object value) throws ConversionException
-    {
-        if (value instanceof InetAddress)
-        {
-            return (InetAddress) value;
-        }
-        else if (value instanceof String)
-        {
-            try
-            {
-                return InetAddress.getByName((String) value);
-            }
-            catch (UnknownHostException e)
-            {
-                throw new ConversionException("The value " + value + " can't be converted to a InetAddress", e);
-            }
-        }
-        else
-        {
-            throw new ConversionException("The value " + value + " can't be converted to a InetAddress");
-        }
-    }
-
-    /**
-     * Convert the specified value into an email address.
-     *
-     * @param value the value to convert
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to an email address
-     *
-     * @since 1.5
-     */
-    static Object toInternetAddress(Object value) throws ConversionException
-    {
-        if (value.getClass().getName().equals(INTERNET_ADDRESS_CLASSNAME))
-        {
-            return value;
-        }
-        else if (value instanceof String)
-        {
-            // Invoke per reflection because the dependency to Java mail
-            // should be optional.
-            try
-            {
-                Constructor<?> ctor = Class.forName(INTERNET_ADDRESS_CLASSNAME).getConstructor(String.class);
-                return ctor.newInstance(value);
-            }
-            catch (Exception e)
-            {
-                throw new ConversionException("The value " + value + " can't be converted to a InternetAddress", e);
-            }
-        }
-        else
-        {
-            throw new ConversionException("The value " + value + " can't be converted to a InternetAddress");
-        }
-    }
-
-    /**
-     * Convert the specified value into a Java 5 enum.
-     *
-     * @param value the value to convert
-     * @param cls   the type of the enumeration
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to an enumeration
-     *
-     * @since 1.5
-     */
-    static <T extends Enum<T>> T toEnum(Object value, Class<T> cls) throws ConversionException
-    {
-        if (value.getClass().equals(cls))
-        {
-            // already an enum => return directly
-            return cls.cast(value);
-        }
-        else if (value instanceof String)
-        {
-            // For strings try to find the matching enum literal
-            try
-            {
-                return Enum.valueOf(cls, String.valueOf(value));
-            }
-            catch (Exception e)
-            {
-                throw new ConversionException("The value " + value + " can't be converted to a " + cls.getName());
-            }
-        }
-        else if (value instanceof Number)
-        {
-            // A number is interpreted as the ordinal index of an enum literal
-            try
-            {
-                T[] valuesArray = cls.getEnumConstants();
-                return valuesArray[((Number) value).intValue()];
-            }
-            catch (Exception e)
-            {
-                throw new ConversionException("The value " + value + " can't be converted to a " + cls.getName());
-            }
-        }
-        else
-        {
-            throw new ConversionException("The value " + value + " can't be converted to a " + cls.getName());
-        }
-    }
-
-    /**
-     * Convert the specified object into a Date.
-     *
-     * @param value  the value to convert
-     * @param format the DateFormat pattern to parse String values
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a Calendar
-     */
-    public static Date toDate(Object value, String format) throws ConversionException
-    {
-        if (value instanceof Date)
-        {
-            return (Date) value;
-        }
-        else if (value instanceof Calendar)
-        {
-            return ((Calendar) value).getTime();
-        }
-        else if (value instanceof String)
-        {
-            try
-            {
-                return new SimpleDateFormat(format).parse((String) value);
-            }
-            catch (ParseException e)
-            {
-                throw new ConversionException("The value " + value + " can't be converted to a Date", e);
-            }
-        }
-        else
-        {
-            throw new ConversionException("The value " + value + " can't be converted to a Date");
-        }
-    }
-
-    /**
-     * Convert the specified object into a Calendar.
-     *
-     * @param value  the value to convert
-     * @param format the DateFormat pattern to parse String values
-     * @return the converted value
-     * @throws ConversionException thrown if the value cannot be converted to a Calendar
-     */
-    public static Calendar toCalendar(Object value, String format) throws ConversionException
-    {
-        if (value instanceof Calendar)
-        {
-            return (Calendar) value;
-        }
-        else if (value instanceof Date)
-        {
-            Calendar calendar = Calendar.getInstance();
-            calendar.setTime((Date) value);
-            return calendar;
-        }
-        else if (value instanceof String)
-        {
-            try
-            {
-                Calendar calendar = Calendar.getInstance();
-                calendar.setTime(new SimpleDateFormat(format).parse((String) value));
-                return calendar;
-            }
-            catch (ParseException e)
-            {
-                throw new ConversionException("The value " + value + " can't be converted to a Calendar", e);
-            }
-        }
-        else
-        {
-            throw new ConversionException("The value " + value + " can't be converted to a Calendar");
-        }
     }
 
     /**

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/beanutils/BeanHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/beanutils/BeanHelper.java?rev=645622&r1=645621&r2=645622&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/beanutils/BeanHelper.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/beanutils/BeanHelper.java Mon Apr  7 10:24:32 2008
@@ -27,7 +27,8 @@
 import java.util.Set;
 
 import org.apache.commons.configuration2.ConfigurationRuntimeException;
-import org.apache.commons.configuration2.PropertyConverter;
+import org.apache.commons.configuration2.converter.Converter;
+import org.apache.commons.configuration2.converter.DefaultPropertyConverter;
 import org.apache.commons.lang.ClassUtils;
 
 /**
@@ -60,6 +61,9 @@
     /** Stores a map with the registered bean factories. */
     private static Map<String, BeanFactory> beanFactories = Collections.synchronizedMap(new HashMap<String, BeanFactory>());
 
+    /** Converter to set the bean properties */
+    private static Converter converter = new DefaultPropertyConverter();
+
     /**
      * Stores the default bean factory, which will be used if no other factory
      * is provided.
@@ -212,7 +216,7 @@
 
             // set the property
             Class type = descriptor.getPropertyType();
-            Object convertedValue = type.isAssignableFrom(value.getClass()) ? value : PropertyConverter.to(type, value);
+            Object convertedValue = type.isAssignableFrom(value.getClass()) ? value : converter.convert(type, value);
             descriptor.getWriteMethod().invoke(bean, convertedValue);
         }
         catch (ConfigurationRuntimeException e)

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigDecimalConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigDecimalConverter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigDecimalConverter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigDecimalConverter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import java.math.BigDecimal;
+
+import org.apache.commons.configuration2.ConversionException;
+
+/**
+ * BigDecimal converter.
+ * 
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+class BigDecimalConverter extends NumberConverter<BigDecimal>
+{
+    private static final TypeConverter instance = new BigDecimalConverter();
+
+    public static TypeConverter getInstance()
+    {
+        return instance;
+    }
+
+    public BigDecimal convert(Object value, Object... params) throws ConversionException
+    {
+        Number n = toNumber(value, BigDecimal.class);
+        if (n instanceof BigDecimal)
+        {
+            return (BigDecimal) n;
+        }
+        else
+        {
+            return new BigDecimal(n.doubleValue());
+        }
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigDecimalConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigDecimalConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigIntegerConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigIntegerConverter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigIntegerConverter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigIntegerConverter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import java.math.BigInteger;
+
+import org.apache.commons.configuration2.ConversionException;
+
+/**
+ * BigInteger converter.
+ * 
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+class BigIntegerConverter extends NumberConverter<BigInteger>
+{
+    private static final TypeConverter instance = new BigIntegerConverter();
+
+    public static TypeConverter getInstance()
+    {
+        return instance;
+    }
+
+    public BigInteger convert(Object value, Object... params) throws ConversionException
+    {
+        Number n = toNumber(value, BigInteger.class);
+        if (n instanceof BigInteger)
+        {
+            return (BigInteger) n;
+        }
+        else
+        {
+            return BigInteger.valueOf(n.longValue());
+        }
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigIntegerConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BigIntegerConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BooleanConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BooleanConverter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BooleanConverter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BooleanConverter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import org.apache.commons.lang.BooleanUtils;
+import org.apache.commons.configuration2.ConversionException;
+
+/**
+ * Boolean converter.
+ * 
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+class BooleanConverter implements TypeConverter<Boolean>
+{
+    private static final BooleanConverter instance = new BooleanConverter();
+
+    public static BooleanConverter getInstance()
+    {
+        return instance;
+    }
+
+    public Boolean convert(Object value, Object... params)
+    {
+        if (value instanceof Boolean)
+        {
+            return (Boolean) value;
+        }
+        else if (value instanceof String)
+        {
+            Boolean b = BooleanUtils.toBooleanObject((String) value);
+            if (b == null)
+            {
+                throw new ConversionException("The value " + value + " can't be converted to a Boolean object");
+            }
+            return b;
+        }
+        else
+        {
+            throw new ConversionException("The value " + value + " can't be converted to a Boolean object");
+        }
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BooleanConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/BooleanConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ByteConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ByteConverter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ByteConverter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ByteConverter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import org.apache.commons.configuration2.ConversionException;
+
+/**
+ * Byte converter.
+ * 
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+class ByteConverter extends NumberConverter<Byte>
+{
+    private static final TypeConverter instance = new ByteConverter();
+
+    public static TypeConverter getInstance()
+    {
+        return instance;
+    }
+
+    public Byte convert(Object value, Object... params) throws ConversionException
+    {
+        Number n = toNumber(value, Byte.class);
+        if (n instanceof Byte)
+        {
+            return (Byte) n;
+        }
+        else
+        {
+            return new Byte(n.byteValue());
+        }
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ByteConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ByteConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CalendarConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CalendarConverter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CalendarConverter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CalendarConverter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
+
+import org.apache.commons.configuration2.ConversionException;
+
+/**
+ * Calendar converter. This converter uses an optional parameter to specify
+ * the format of the date when converting string values.
+ *
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+class CalendarConverter implements TypeConverter<Calendar>
+{
+    private static final TypeConverter instance = new CalendarConverter();
+
+    public static TypeConverter getInstance()
+    {
+        return instance;
+    }
+
+    public Calendar convert(Object value, Object... params)
+    {
+        if (value instanceof Date)
+        {
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime((Date) value);
+            return calendar;
+        }
+        else if (value instanceof String)
+        {
+            try
+            {
+                Calendar calendar = Calendar.getInstance();
+                calendar.setTime(new SimpleDateFormat((String) params[0]).parse((String) value));
+                return calendar;
+            }
+            catch (ParseException e)
+            {
+                throw new ConversionException("The value " + value + " can't be converted to a Calendar", e);
+            }
+        }
+        else
+        {
+            throw new ConversionException("The value " + value + " can't be converted to a Calendar");
+        }
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CalendarConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CalendarConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CharacterConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CharacterConverter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CharacterConverter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CharacterConverter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import org.apache.commons.configuration2.ConversionException;
+
+/**
+ * Character converter.
+ * 
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+public class CharacterConverter implements TypeConverter
+{
+    private static final TypeConverter instance = new CharacterConverter();
+
+    public static TypeConverter getInstance()
+    {
+        return instance;
+    }
+
+    public Object convert(Object value, Object[] params) throws ConversionException
+    {
+        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");
+        }
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CharacterConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/CharacterConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ColorConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ColorConverter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ColorConverter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ColorConverter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import java.awt.Color;
+
+import org.apache.commons.configuration2.ConversionException;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Color converter. This converter supports String value matching the format
+ * (#)?[0-9A-F]{6}([0-9A-F]{2})?. Examples:
+ * <ul>
+ *   <li>FF0000 (red)</li>
+ *   <li>0000FFA0 (semi transparent blue)</li>
+ *   <li>#CCCCCC (gray)</li>
+ *   <li>#00FF00A0 (semi transparent green)</li>
+ * </ul>
+ *
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+class ColorConverter implements TypeConverter<Color>
+{
+    /** Constant for the radix of hex numbers.*/
+    private static final int HEX_RADIX = 16;
+
+    private static final TypeConverter instance = new ColorConverter();
+
+    public static TypeConverter getInstance()
+    {
+        return instance;
+    }
+
+    public Color convert(Object value, Object... params)
+    {
+        if (value instanceof String && !StringUtils.isBlank((String) value))
+        {
+            String color = ((String) value).trim();
+
+            int[] components = new int[3];
+
+            // check the size of the string
+            int minlength = components.length * 2;
+            if (color.length() < minlength)
+            {
+                throw new ConversionException("The value " + value + " can't be converted to a Color");
+            }
+
+            // remove the leading #
+            if (color.startsWith("#"))
+            {
+                color = color.substring(1);
+            }
+
+            try
+            {
+                // parse the components
+                for (int i = 0; i < components.length; i++)
+                {
+                    components[i] = Integer.parseInt(color.substring(2 * i, 2 * i + 2), HEX_RADIX);
+                }
+
+                // parse the transparency
+                int alpha;
+                if (color.length() >= minlength + 2)
+                {
+                    alpha = Integer.parseInt(color.substring(minlength, minlength + 2), HEX_RADIX);
+                }
+                else
+                {
+                    alpha = Color.BLACK.getAlpha();
+                }
+
+                return new Color(components[0], components[1], components[2], alpha);
+            }
+            catch (Exception e)
+            {
+                throw new ConversionException("The value " + value + " can't be converted to a Color", e);
+            }
+        }
+        else
+        {
+            throw new ConversionException("The value " + value + " can't be converted to a Color");
+        }
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ColorConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/ColorConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/Converter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/Converter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/Converter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/Converter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import org.apache.commons.configuration2.ConversionException;
+
+/**
+ * Interface for converting values into differents types.
+ *
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+public interface Converter
+{
+    /**
+     * Converts the value to the specified type.
+     *
+     * @param cls    the target class
+     * @param value  the value to be converted
+     * @param params additional conversion parameters
+     *
+     * @return the value converted into the target type
+     * @throws ConversionException if the value is not compatible with the requested type
+     */
+    <T> T convert(Class<T> cls, Object value, Object... params) throws ConversionException;
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/Converter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/Converter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DateConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DateConverter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DateConverter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DateConverter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import java.util.Date;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
+
+import org.apache.commons.configuration2.ConversionException;
+
+/**
+ * Date converter. This converter uses an optional parameter to specify
+ * the format of the date when converting string values.
+ *
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+class DateConverter implements TypeConverter<Date>
+{
+    private static final TypeConverter instance = new DateConverter();
+
+    public static TypeConverter getInstance()
+    {
+        return instance;
+    }
+
+    public Date convert(Object value, Object... params)
+    {
+        if (value instanceof Calendar)
+        {
+            return ((Calendar) value).getTime();
+        }
+        else if (value instanceof String)
+        {
+            try
+            {
+                return new SimpleDateFormat((String) params[0]).parse((String) value);
+            }
+            catch (ParseException e)
+            {
+                throw new ConversionException("The value " + value + " can't be converted to a Date", e);
+            }
+        }
+        else
+        {
+            throw new ConversionException("The value " + value + " can't be converted to a Date");
+        }
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DateConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DateConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DefaultPropertyConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DefaultPropertyConverter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DefaultPropertyConverter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DefaultPropertyConverter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import java.awt.Color;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.InetAddress;
+import java.net.URL;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+
+import org.apache.commons.configuration2.ConversionException;
+
+/**
+ * Default implementation of the Converter interface.
+ * 
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+public class DefaultPropertyConverter implements Converter
+{
+    @SuppressWarnings("unchecked")
+    public <T> T convert(Class<T> cls, Object value, Object... params) throws ConversionException
+    {
+        // return the value if it's already an instance of the requested type
+        if (cls.isAssignableFrom(value.getClass()))
+        {
+            return (T) value;
+        }
+
+        // special cases for Enums
+        if (cls.isEnum())
+        {
+            return (T) toEnum(value, cls.asSubclass(Enum.class));
+        }
+
+        TypeConverter<T> converter = getConverter(cls);
+
+        if (converter == null)
+        {
+            throw new ConversionException("The value '" + value + "' (" + value.getClass() + ")"
+                    + " can't be converted to a " + cls.getName() + " object");
+        }
+        else
+        {
+            return converter.convert(value, params);
+        }
+    }
+
+    /**
+     * Returns a converter suitable to converting a value into the specified type.
+     *
+     * @param cls the target class of the converter
+     */
+    @SuppressWarnings("unchecked")
+    protected <T> TypeConverter<T> getConverter(Class<T> cls)
+    {
+       TypeConverter converter = null;
+
+        if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls))
+        {
+            converter = BooleanConverter.getInstance();
+        }
+        else if (Character.class.equals(cls) || Character.TYPE.equals(cls))
+        {
+            converter = CharacterConverter.getInstance();
+        }
+        else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive())
+        {
+            if (Integer.class.equals(cls) || Integer.TYPE.equals(cls))
+            {
+                converter = IntegerConverter.getInstance();
+            }
+            else if (Long.class.equals(cls) || Long.TYPE.equals(cls))
+            {
+                converter = LongConverter.getInstance();
+            }
+            else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls))
+            {
+                converter = ByteConverter.getInstance();
+            }
+            else if (Short.class.equals(cls) || Short.TYPE.equals(cls))
+            {
+                converter = ShortConverter.getInstance();
+            }
+            else if (Float.class.equals(cls) || Float.TYPE.equals(cls))
+            {
+                converter = FloatConverter.getInstance();
+            }
+            else if (Double.class.equals(cls) || Double.TYPE.equals(cls))
+            {
+                converter = DoubleConverter.getInstance();
+            }
+            else if (BigInteger.class.equals(cls))
+            {
+                converter = BigIntegerConverter.getInstance();
+            }
+            else if (BigDecimal.class.equals(cls))
+            {
+                converter = BigDecimalConverter.getInstance();
+            }
+        }
+        else if (Date.class.equals(cls))
+        {
+            converter = DateConverter.getInstance();
+        }
+        else if (Calendar.class.equals(cls))
+        {
+            converter = CalendarConverter.getInstance();
+        }
+        else if (URL.class.equals(cls))
+        {
+            converter = URLConverter.getInstance();
+        }
+        else if (Locale.class.equals(cls))
+        {
+            converter = LocaleConverter.getInstance();
+        }
+        else if (Color.class.equals(cls))
+        {
+            converter = ColorConverter.getInstance();
+        }
+        else if (cls.getName().equals("javax.mail.internet.InternetAddress"))
+        {
+            converter = InternetAddressConverter.getInstance();
+        }
+        else if (InetAddress.class.isAssignableFrom(cls))
+        {
+            converter = InetAddressConverter.getInstance();
+        }
+
+        return converter;
+    }
+
+
+    /**
+     * Convert the specified value into a Java 5 enum.
+     *
+     * @param value the value to convert
+     * @param cls   the type of the enumeration
+     * @return the converted value
+     * @throws ConversionException thrown if the value cannot be converted to an enumeration
+     *
+     * @since 1.5
+     */
+    static <T extends Enum<T>> T toEnum(Object value, Class<T> cls) throws ConversionException
+    {
+        if (value.getClass().equals(cls))
+        {
+            // already an enum => return directly
+            return cls.cast(value);
+        }
+        else if (value instanceof String)
+        {
+            // For strings try to find the matching enum literal
+            try
+            {
+                return Enum.valueOf(cls, String.valueOf(value));
+            }
+            catch (Exception e)
+            {
+                throw new ConversionException("The value " + value + " can't be converted to a " + cls.getName());
+            }
+        }
+        else if (value instanceof Number)
+        {
+            // A number is interpreted as the ordinal index of an enum literal
+            try
+            {
+                T[] valuesArray = cls.getEnumConstants();
+                return valuesArray[((Number) value).intValue()];
+            }
+            catch (Exception e)
+            {
+                throw new ConversionException("The value " + value + " can't be converted to a " + cls.getName());
+            }
+        }
+        else
+        {
+            throw new ConversionException("The value " + value + " can't be converted to a " + cls.getName());
+        }
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DefaultPropertyConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DefaultPropertyConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DoubleConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DoubleConverter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DoubleConverter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DoubleConverter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import org.apache.commons.configuration2.ConversionException;
+
+/**
+ * Double converter.
+ * 
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+class DoubleConverter extends NumberConverter<Double>
+{
+    private static final TypeConverter instance = new DoubleConverter();
+
+    public static TypeConverter getInstance()
+    {
+        return instance;
+    }
+
+    public Double convert(Object value, Object... params) throws ConversionException
+    {
+        Number n = toNumber(value, Double.class);
+        if (n instanceof Double)
+        {
+            return (Double) n;
+        }
+        else
+        {
+            return new Double(n.doubleValue());
+        }
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DoubleConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/DoubleConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/FloatConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/FloatConverter.java?rev=645622&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/FloatConverter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/FloatConverter.java Mon Apr  7 10:24:32 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration2.converter;
+
+import org.apache.commons.configuration2.ConversionException;
+
+/**
+ * Float converter.
+ * 
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ * @since 2.0
+ */
+class FloatConverter extends NumberConverter<Float>
+{
+    private static final TypeConverter instance = new FloatConverter();
+
+    public static TypeConverter getInstance()
+    {
+        return instance;
+    }
+
+    public Float convert(Object value, Object... params) throws ConversionException
+    {
+        Number n = toNumber(value, Float.class);
+        if (n instanceof Float)
+        {
+            return (Float) n;
+        }
+        else
+        {
+            return new Float(n.floatValue());
+        }
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/FloatConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/converter/FloatConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Re: svn commit: r645622 [1/2] - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/ main/java/org/apache/commons/configuration2/beanutils/ main/java/org/apache/commons/configuration2/conve...

Posted by Emmanuel Bourg <eb...@apache.org>.
Oliver Heger a écrit :
> 
> mvn clean package gives the errors below.
> 
> Removing <scope>test</scope> from the dependency to Java mail helps.

Thanks, I forgot this file in the commit, I'll make the dependency 
optional instead.

Emmanuel Bourg

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


Re: svn commit: r645622 [1/2] - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/ main/java/org/apache/commons/configuration2/beanutils/ main/java/org/apache/commons/configuration2/conve...

Posted by Oliver Heger <ol...@oliver-heger.de>.
ebourg@apache.org schrieb:
> Author: ebourg
> Date: Mon Apr  7 10:24:32 2008
> New Revision: 645622
> 
> URL: http://svn.apache.org/viewvc?rev=645622&view=rev
> Log:
> First stab at implementing a pluggable conversion system
> - The Converter interface provides a general contract for transforming values, a default implementation is provided and can be extended
> - every configuration has a Converter instance
> - The conversion methods from PropertyConverter have been split into TypeConverter classes
> 

mvn clean package gives the errors below.

Removing <scope>test</scope> from the dependency to Java mail helps.

Oliver

[ERROR] BUILD FAILURE
[INFO] 
------------------------------------------------------------------------
[INFO] Compilation failure

D:\data\projects\OpenSource\configuration2\src\main\java\org\apache\commons\conf
iguration2\converter\InternetAddressConverter.java:[20,27] package 
javax.mail.in
ternet does not exist

D:\data\projects\OpenSource\configuration2\src\main\java\org\apache\commons\conf
iguration2\converter\InternetAddressConverter.java:[31,56] cannot find 
symbol
symbol: class InternetAddress
class InternetAddressConverter implements TypeConverter<InternetAddress>

D:\data\projects\OpenSource\configuration2\src\main\java\org\apache\commons\conf
iguration2\converter\InternetAddressConverter.java:[40,11] cannot find 
symbol
symbol  : class InternetAddress
location: class 
org.apache.commons.configuration2.converter.InternetAddressConve
rter

D:\data\projects\OpenSource\configuration2\src\main\java\org\apache\commons\conf
iguration2\converter\InternetAddressConverter.java:[46,27] cannot find 
symbol
symbol  : class InternetAddress
location: class 
org.apache.commons.configuration2.converter.InternetAddressConve
rter

<snip/>

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