commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/locale LocaleConvertTestSuite.java LocaleConvertUtilsTestCase.java
Date Sun, 09 Mar 2003 21:25:17 GMT
rdonkin     2003/03/09 13:25:17

  Modified:    beanutils build.xml
               beanutils/src/java/org/apache/commons/beanutils/locale
                        BaseLocaleConverter.java LocaleConvertUtils.java
               beanutils/src/java/org/apache/commons/beanutils/locale/converters
                        ByteLocaleConverter.java DateLocaleConverter.java
                        DecimalLocaleConverter.java
                        FloatLocaleConverter.java
                        IntegerLocaleConverter.java
                        StringLocaleConverter.java
  Added:       beanutils/src/test/org/apache/commons/beanutils/locale
                        LocaleConvertTestSuite.java
                        LocaleConvertUtilsTestCase.java
  Log:
  This patch contain numerous improvements to locale convert utils. These include more graceful handling of nulls and more precise numeric classes returned from numeric convertions. Submitted by Michael Szlapa.
  
  Revision  Changes    Path
  1.51      +4 -4      jakarta-commons/beanutils/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/build.xml,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- build.xml	18 Feb 2003 22:50:08 -0000	1.50
  +++ build.xml	9 Mar 2003 21:25:16 -0000	1.51
  @@ -262,7 +262,7 @@
                                   test.dyna.result,
                                   test.dyna.row,
                                   test.bean.comparator,
  -                                test.locale.converters
  +                                test.locale.convert
                                  "
      description="Run all unit test cases">
     </target>
  @@ -433,7 +433,7 @@
       </java>
     </target>
     
  -  <target name="test.locale.converters" depends="compile.tests">
  +  <target name="test.locale.convert" depends="compile.tests">
       <echo message="Running Locale converters tests ..."/>
       <java classname="${test.runner}" fork="yes"
           failonerror="${test.failonerror}">
  @@ -443,7 +443,7 @@
                    value="${test.log}"/>
         <sysproperty key="org.apache.commons.logging.simplelog.defaultlog"
                    value="${test.level}"/>
  -      <arg value="org.apache.commons.beanutils.locale.converters.DateLocaleConverterTestCase"/>
  +      <arg value="org.apache.commons.beanutils.locale.LocaleConvertTestSuite"/>
         <classpath refid="test.classpath"/>
       </java>
     </target>
  
  
  
  1.4       +17 -12    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/BaseLocaleConverter.java
  
  Index: BaseLocaleConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/BaseLocaleConverter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BaseLocaleConverter.java	15 Jan 2003 21:59:42 -0000	1.3
  +++ BaseLocaleConverter.java	9 Mar 2003 21:25:17 -0000	1.4
  @@ -62,6 +62,9 @@
   package org.apache.commons.beanutils.locale;
   
   import org.apache.commons.beanutils.ConversionException;
  +import org.apache.commons.beanutils.locale.converters.DateLocaleConverter;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   
   import java.text.ParseException;
   import java.util.Locale;
  @@ -81,6 +84,9 @@
   
       // ----------------------------------------------------- Instance Variables
   
  +    /** All logging goes through this logger */
  +    private static Log log = LogFactory.getLog(BaseLocaleConverter.class);
  +
       /** The default value specified to our Constructor, if any. */
       private Object defaultValue = null;
   
  @@ -249,25 +255,24 @@
           if (value == null) {
               if (useDefault) {
                   return (defaultValue);
  -            }
  -            else {
  -                throw new ConversionException("No value specified");
  +            } else {
  +                // symmetric beanutils function allows null
  +                // so do not: throw new ConversionException("No value specified");
  +                log.debug("Null value specified for conversion, returing null");
  +                return null;
               }
           }
   
           try {
               if (pattern != null) {
                   return parse(value, pattern);
  -            }
  -            else {
  +            } else {
                   return parse(value, this.pattern);
               }
  -        }
  -        catch (Exception e) {
  +        } catch (Exception e) {
               if (useDefault) {
                   return (defaultValue);
  -            }
  -            else {
  +            } else {
                   throw new ConversionException(e);
               }
           }
  
  
  
  1.5       +26 -7     jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/LocaleConvertUtils.java
  
  Index: LocaleConvertUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/LocaleConvertUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LocaleConvertUtils.java	15 Jan 2003 21:59:42 -0000	1.4
  +++ LocaleConvertUtils.java	9 Mar 2003 21:25:17 -0000	1.5
  @@ -62,6 +62,7 @@
   package org.apache.commons.beanutils.locale;
   
   import org.apache.commons.beanutils.locale.converters.*;
  +import org.apache.commons.beanutils.Converter;
   import org.apache.commons.collections.FastHashMap;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -179,7 +180,7 @@
        *
        * @param value The Value to be converted
        *
  -     * @exception ConversionException if thrown by an underlying Converter
  +     * @exception org.apache.commons.beanutils.ConversionException if thrown by an underlying Converter
        */
       public static String convert(Object value) {
           return convert(value, defaultLocale, null);
  @@ -292,6 +293,20 @@
           return convert(values, clazz, getDefaultLocale(), pattern);
       }
   
  +   /**
  +    * Convert an array of specified values to an array of objects of the
  +    * specified class (if possible) .
  +    *
  +    * @param values Value to be converted (may be null)
  +    * @param clazz Java array or element class to be converted to
  +    *
  +    * @exception ConversionException if thrown by an underlying Converter
  +    */
  +   public static Object convert(String values[], Class clazz) {
  +
  +       return convert(values, clazz, getDefaultLocale(), null);
  +   }
  +
       /**
        * Convert an array of specified values to an array of objects of the
        * specified class (if possible) using the convertion pattern.
  @@ -449,9 +464,13 @@
   
           converter.put(String.class, new StringLocaleConverter(locale, applyLocalized));
   
  -        converter.put(Date.class, new SqlDateLocaleConverter(locale, applyLocalized));
  -        converter.put(Time.class, new SqlTimeLocaleConverter(locale, applyLocalized));
  -        converter.put(Timestamp.class, new SqlTimestampLocaleConverter(locale, applyLocalized));
  +        // conversion format patterns of java.sql.* types should correspond to default
  +        // behaviour of toString and valueOf methods of these classes
  +        converter.put(java.sql.Date.class, new SqlDateLocaleConverter(locale, "yyyy-MM-dd"));
  +        converter.put(java.sql.Time.class, new SqlTimeLocaleConverter(locale, "HH:mm:ss"));
  +        converter.put( java.sql.Timestamp.class,
  +                       new SqlTimestampLocaleConverter(locale, "yyyy-MM-dd HH:mm:ss.S")
  +                     );
   
           converter.setFast(true);
   
  
  
  
  1.4       +40 -18    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/ByteLocaleConverter.java
  
  Index: ByteLocaleConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/ByteLocaleConverter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ByteLocaleConverter.java	15 Jan 2003 21:59:43 -0000	1.3
  +++ ByteLocaleConverter.java	9 Mar 2003 21:25:17 -0000	1.4
  @@ -61,14 +61,17 @@
   
   package org.apache.commons.beanutils.locale.converters;
   
  +import org.apache.commons.beanutils.ConversionException;
  +
   import java.util.Locale;
  +import java.text.ParseException;
   
   
   /**
  - * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  + * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter}
    * implementation that converts an incoming
    * locale-sensitive String into a <code>java.lang.Byte</code> object,
  - * optionally using a default value or throwing a 
  + * optionally using a default value or throwing a
    * {@link org.apache.commons.beanutils.ConversionException}
    * if a conversion error occurs.</p>
    *
  @@ -81,7 +84,7 @@
       // ----------------------------------------------------------- Constructors
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine and an unlocalized pattern is used
  @@ -94,7 +97,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine.
  @@ -107,7 +110,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -119,7 +122,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs.
        *
  @@ -132,7 +135,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -145,7 +148,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs.
        *
  @@ -159,7 +162,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine and an unlocalized pattern is used
  @@ -173,7 +176,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine.
  @@ -187,7 +190,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -200,7 +203,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs.
        *
  @@ -214,7 +217,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -227,8 +230,8 @@
           this(defaultValue, locale, pattern, false);
       }
   
  -    /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +   /**
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs.
        *
  @@ -240,5 +243,24 @@
       public ByteLocaleConverter(Object defaultValue, Locale locale, String pattern, boolean locPattern) {
   
           super(defaultValue, locale, pattern);
  +    }
  +
  +    /**
  +     * Convert the specified locale-sensitive input object into an output object of the
  +     * specified type. This method will return values of type Byte.
  +     *
  +     * @param value The input object to be converted
  +     * @param pattern The pattern is used for the convertion
  +     *
  +     * @exception org.apache.commons.beanutils.ConversionException if conversion cannot be performed
  +     *  successfully
  +     */
  +    protected Object parse(Object value, String pattern) throws ParseException {
  +        final Number parsed = (Number) super.parse(value, pattern);
  +        if (parsed.longValue() != parsed.byteValue()) {
  +            throw new ConversionException("Supplied number is not of type Byte: " + parsed.longValue());
  +        }
  +        // now returns property Byte
  +        return new Byte(parsed.byteValue());
       }
   }
  
  
  
  1.5       +31 -5     jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java
  
  Index: DateLocaleConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DateLocaleConverter.java	15 Jan 2003 21:59:43 -0000	1.4
  +++ DateLocaleConverter.java	9 Mar 2003 21:25:17 -0000	1.5
  @@ -62,6 +62,8 @@
   package org.apache.commons.beanutils.locale.converters;
   
   import org.apache.commons.beanutils.locale.BaseLocaleConverter;
  +import org.apache.commons.logging.LogFactory;
  +import org.apache.commons.logging.Log;
   
   import java.text.ParseException;
   import java.text.ParsePosition;
  @@ -78,14 +80,19 @@
    * if a conversion error occurs.</p>
    *
    * @author Yauheny Mikulski
  + * @author Michael Szlapa
    */
   
   public class DateLocaleConverter extends BaseLocaleConverter {
   
       // ----------------------------------------------------- Instance Variables
   
  +    /** All logging goes through this logger */
  +    private static Log log = LogFactory.getLog(DateLocaleConverter.class);
  +
       /** The Date formatter */
  -    private SimpleDateFormat formatter = new SimpleDateFormat(pattern, locale);
  +    private SimpleDateFormat formatter = getPattern(pattern, locale);
  +
   
       // ----------------------------------------------------------- Constructors
   
  @@ -283,7 +290,7 @@
        * @param value The input object to be converted
        * @param pattern The pattern is used for the convertion
        *
  -     * @exception ConversionException if conversion cannot be performed
  +     * @exception org.apache.commons.beanutils.ConversionException if conversion cannot be performed
        *  successfully
        */
       protected Object parse(Object value, String pattern) throws ParseException {
  @@ -294,5 +301,24 @@
               formatter.applyPattern(pattern);
           }
           return formatter.parse((String) value);
  +    }
  +
  +    /**
  +     * Gets an appropriate <code>SimpleDateFormat</code> for given locale, 
  +     * default Date format pattern is not provided.
  +     */
  +    private SimpleDateFormat getPattern(String pattern, Locale locale) {
  +        // This method is a fix for null pattern, which would cause 
  +        // Null pointer exception when applied
  +        // Note: that many constructors default the pattern to null, 
  +        // so it only makes sense to handle nulls gracefully
  +        if(pattern == null) {
  +            pattern = locPattern ? 
  +                new SimpleDateFormat().toLocalizedPattern() : new SimpleDateFormat().toPattern();
  +            log.warn("Null pattern was provided, defaulting to: " + pattern);
  +        }
  +        SimpleDateFormat format = new SimpleDateFormat(pattern, locale);
  +        format.setLenient(false);
  +        return format;
       }
   }
  
  
  
  1.4       +17 -8     jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/DecimalLocaleConverter.java
  
  Index: DecimalLocaleConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/DecimalLocaleConverter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DecimalLocaleConverter.java	15 Jan 2003 21:59:43 -0000	1.3
  +++ DecimalLocaleConverter.java	9 Mar 2003 21:25:17 -0000	1.4
  @@ -62,6 +62,8 @@
   package org.apache.commons.beanutils.locale.converters;
   
   import org.apache.commons.beanutils.locale.BaseLocaleConverter;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   
   import java.text.DecimalFormat;
   import java.text.ParseException;
  @@ -84,6 +86,9 @@
   
       // ----------------------------------------------------- Instance Variables
   
  +    /** All logging goes through this logger */
  +    private static Log log = LogFactory.getLog(DecimalLocaleConverter.class);     
  +
       /** The Decimal formatter */
       private DecimalFormat formatter = (DecimalFormat) DecimalFormat.getInstance(locale);
   
  @@ -265,11 +270,15 @@
        */
       protected Object parse(Object value, String pattern) throws ParseException {
   
  -        if (locPattern) {
  -            formatter.applyLocalizedPattern(pattern);
  -        }
  -        else {
  -            formatter.applyPattern(pattern);
  +        // if some constructors default pattern to null, it makes only sense to handle null pattern gracefully
  +        if (pattern != null) {
  +            if (locPattern) {
  +                formatter.applyLocalizedPattern(pattern);
  +            } else {
  +                formatter.applyPattern(pattern);
  +            }
  +        } else {
  +            log.warn("No pattern provided, using default.");
           }
   
           return formatter.parse((String) value);
  
  
  
  1.4       +39 -17    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java
  
  Index: FloatLocaleConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FloatLocaleConverter.java	15 Jan 2003 21:59:43 -0000	1.3
  +++ FloatLocaleConverter.java	9 Mar 2003 21:25:17 -0000	1.4
  @@ -61,14 +61,17 @@
   
   package org.apache.commons.beanutils.locale.converters;
   
  +import org.apache.commons.beanutils.ConversionException;
  +
   import java.util.Locale;
  +import java.text.ParseException;
   
   
   /**
  - * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  + * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter}
    * implementation that converts an incoming
    * locale-sensitive String into a <code>java.math.BigDecimal</code> object,
  - * optionally using a default value or throwing a 
  + * optionally using a default value or throwing a
    * {@link org.apache.commons.beanutils.ConversionException}
    * if a conversion error occurs.</p>
    *
  @@ -81,7 +84,7 @@
       // ----------------------------------------------------------- Constructors
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine and an unlocalized pattern is used
  @@ -94,7 +97,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine.
  @@ -107,7 +110,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -119,7 +122,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs.
        *
  @@ -132,7 +135,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -145,7 +148,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs.
        *
  @@ -159,7 +162,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine and an unlocalized pattern is used
  @@ -173,7 +176,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine.
  @@ -187,7 +190,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -200,7 +203,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs.
        *
  @@ -214,7 +217,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -228,7 +231,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs.
        *
  @@ -241,4 +244,23 @@
   
           super(defaultValue, locale, pattern);
       }
  +
  +   /**
  +    * Convert the specified locale-sensitive input object into an output object of the
  +    * specified type.  This method will return Float value or throw exception if value
  +    * can not be stored in the Float.
  +    *
  +    * @param value The input object to be converted
  +    * @param pattern The pattern is used for the convertion
  +    *
  +    * @exception ConversionException if conversion cannot be performed
  +    *  successfully
  +    */
  +   protected Object parse(Object value, String pattern) throws ParseException {
  +      final Number parsed = (Number) super.parse(value, pattern);
  +      if( Math.abs(parsed.doubleValue() - parsed.floatValue()) > parsed.floatValue() * 0.00001 ) {
  +         throw new ConversionException("Suplied number is not of type Float: "+parsed.longValue());
  +      }
  +      return new Float(parsed.floatValue()); // unlike superclass it returns Float type
  +   }
   }
  
  
  
  1.4       +38 -17    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/IntegerLocaleConverter.java
  
  Index: IntegerLocaleConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/IntegerLocaleConverter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IntegerLocaleConverter.java	15 Jan 2003 21:59:44 -0000	1.3
  +++ IntegerLocaleConverter.java	9 Mar 2003 21:25:17 -0000	1.4
  @@ -61,14 +61,17 @@
   
   package org.apache.commons.beanutils.locale.converters;
   
  +import org.apache.commons.beanutils.ConversionException;
  +
   import java.util.Locale;
  +import java.text.ParseException;
   
   
   /**
  - * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  + * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter}
    * implementation that converts an incoming
    * locale-sensitive String into a <code>java.lang.Integer</code> object,
  - * optionally using a default value or throwing a 
  + * optionally using a default value or throwing a
    * {@link org.apache.commons.beanutils.ConversionException}
    * if a conversion error occurs.</p>
    *
  @@ -81,7 +84,7 @@
       // ----------------------------------------------------------- Constructors
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine and an unlocalized pattern is used
  @@ -95,7 +98,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine.
  @@ -108,7 +111,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -120,7 +123,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs.
        *
  @@ -133,7 +136,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -146,7 +149,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs.
        *
  @@ -160,7 +163,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine and an unlocalized pattern is used
  @@ -174,7 +177,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine.
  @@ -188,7 +191,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -201,7 +204,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs.
        *
  @@ -215,7 +218,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -229,7 +232,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs.
        *
  @@ -241,5 +244,23 @@
       public IntegerLocaleConverter(Object defaultValue, Locale locale, String pattern, boolean locPattern) {
   
           super(defaultValue, locale, pattern, locPattern);
  +    }
  +
  +    /**
  +     * Convert the specified locale-sensitive input object into an output object of the
  +     * specified type. This method will return Integer type.
  +     *
  +     * @param value The input object to be converted
  +     * @param pattern The pattern is used for the convertion
  +     *
  +     * @exception ConversionException if conversion cannot be performed
  +     *  successfully
  +     */
  +    protected Object parse(Object value, String pattern) throws ParseException {
  +        final Number parsed = (Number) super.parse(value, pattern);
  +        if (parsed.longValue() != parsed.intValue()) {
  +            throw new ConversionException("Suplied number is not of type Integer: " + parsed.longValue());
  +        }
  +        return new Integer(parsed.intValue()); // unlike superclass it will return proper Integer
       }
   }
  
  
  
  1.4       +35 -23    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/StringLocaleConverter.java
  
  Index: StringLocaleConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/locale/converters/StringLocaleConverter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StringLocaleConverter.java	15 Jan 2003 21:59:44 -0000	1.3
  +++ StringLocaleConverter.java	9 Mar 2003 21:25:17 -0000	1.4
  @@ -58,10 +58,12 @@
    * <http://www.apache.org/>.
    *
    */
  - 
  +
   package org.apache.commons.beanutils.locale.converters;
   
   import org.apache.commons.beanutils.locale.BaseLocaleConverter;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   
   import java.math.BigDecimal;
   import java.math.BigInteger;
  @@ -74,10 +76,10 @@
   
   
   /**
  - * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  + * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter}
    * implementation that converts an incoming
    * locale-sensitive object into a <code>java.lang.String</code> object,
  - * optionally using a default value or throwing a 
  + * optionally using a default value or throwing a
    * {@link org.apache.commons.beanutils.ConversionException}
    * if a conversion error occurs.</p>
    *
  @@ -86,10 +88,16 @@
   
   public class StringLocaleConverter extends BaseLocaleConverter {
   
  +    // ----------------------------------------------------- Instance Variables
  +
  +    /** All logging goes through this logger */
  +    private static Log log = LogFactory.getLog(StringLocaleConverter.class);     //msz fix
  +
  +
       // ----------------------------------------------------------- Constructors
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine and an unlocalized pattern is used
  @@ -102,7 +110,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine.
  @@ -115,7 +123,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -127,7 +135,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs.
        *
  @@ -140,7 +148,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -153,7 +161,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will throw a {@link org.apache.commons.beanutils.ConversionException}
        * if a conversion error occurs.
        *
  @@ -167,7 +175,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine and an unlocalized pattern is used
  @@ -181,7 +189,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. The locale is the default locale for
        * this instance of the Java Virtual Machine.
  @@ -195,7 +203,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -208,7 +216,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs.
        *
  @@ -222,7 +230,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs. An unlocalized pattern is used for the convertion.
        *
  @@ -236,7 +244,7 @@
       }
   
       /**
  -     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
  +     * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
        * that will return the specified default value
        * if a conversion error occurs.
        *
  @@ -307,11 +315,15 @@
   
           DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale);
   
  -        if (locPattern) {
  -            numberFormat.applyLocalizedPattern(pattern);
  -        }
  -        else {
  -            numberFormat.applyPattern(pattern);
  +        // if some constructors default pattern to null, it makes only sense to handle null pattern gracefully
  +        if (pattern != null) {
  +            if (locPattern) {
  +                numberFormat.applyLocalizedPattern(pattern);
  +            } else {
  +                numberFormat.applyPattern(pattern);
  +            }
  +        } else {
  +            log.warn("No pattern provided, using default.");
           }
   
           return numberFormat;
  
  
  
  1.1                  jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/locale/LocaleConvertTestSuite.java
  
  Index: LocaleConvertTestSuite.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/locale/LocaleConvertTestSuite.java,v 1.1 2003/03/09 21:25:17 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/09 21:25:17 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.beanutils.locale;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.commons.beanutils.locale.converters.DateLocaleConverterTestCase;
  
  /**
   * <p>
   * Created a test suite so that new test cases can be added here without having to
   * edit the build.xml.
   * </p>
   *
   * @author  Robert Burrell Donkin
   * @version $Revision: 1.1 $ $Date: 2003/03/09 21:25:17 $
   */
  
  public class LocaleConvertTestSuite {
  
      /**
       * Return the tests included in this test suite.
       */
      public static Test suite() {
          TestSuite testSuite = new TestSuite();
          testSuite.addTestSuite(LocaleConvertUtilsTestCase.class);
          testSuite.addTestSuite(DateLocaleConverterTestCase.class);
          return testSuite;
      }
  }
  
  
  
  
  1.1                  jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/locale/LocaleConvertUtilsTestCase.java
  
  Index: LocaleConvertUtilsTestCase.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/locale/LocaleConvertUtilsTestCase.java,v 1.1 2003/03/09 21:25:17 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/09 21:25:17 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.beanutils.locale;
  
  
  import java.lang.reflect.InvocationTargetException;
  import java.sql.Date;
  import java.sql.Time;
  import java.sql.Timestamp;
  import java.util.HashMap;
  
  import junit.framework.TestCase;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import org.apache.commons.beanutils.ConvertUtils;
  import org.apache.commons.beanutils.ConversionException;
  
  
  /**
   * <p>
   *  Test Case for the LocaleConvertUtils class.
   *  See unimplemented functionality of the convert utils in the method begining with fixme
   * </p>
   *
   * @author  Michael Szlapa
   * @version $Revision: 1.1 $ $Date: 2003/03/09 21:25:17 $
   */
  
  public class LocaleConvertUtilsTestCase extends TestCase {
  
      // ---------------------------------------------------- Instance Variables
  
  
      // ---------------------------------------------------------- Constructors
  
  
      /**
       * Construct a new instance of this test case.
       *
       * @param name Name of the test case
       */
      public LocaleConvertUtilsTestCase(String name) {
          super(name);
      }
  
  
      // -------------------------------------------------- Overall Test Methods
  
  
      /**
       * Set up instance variables required by this test case.
       */
      public void setUp() {
  
          LocaleConvertUtils.deregister();
  
      }
  
  
      /**
       * Return the tests included in this test suite.
       */
      public static Test suite() {
          return (new TestSuite(LocaleConvertUtilsTestCase.class));
      }
  
  
      /**
       * Tear down instance variables required by this test case.
       */
      public void tearDown() {
          ;    // No action required
      }
  
  
      // ------------------------------------------------ Individual Test Methods
  
  
      /**
       * Negative String to primitive integer array tests.
       */
      public void fixmetestNegativeIntegerArray() {
  
          fail("Array conversions not implemented yet.");
  
          Object value = null;
          int intArray[] = new int[0];
  
          value = LocaleConvertUtils.convert((String) null, intArray.getClass());
          checkIntegerArray(value, intArray);
          value = LocaleConvertUtils.convert("a", intArray.getClass());
          checkIntegerArray(value, intArray);
          value = LocaleConvertUtils.convert("{ a }", intArray.getClass());
          checkIntegerArray(value, intArray);
          value = LocaleConvertUtils.convert("1a3", intArray.getClass());
          checkIntegerArray(value, intArray);
          value = LocaleConvertUtils.convert("{ 1a3 }", intArray.getClass());
          checkIntegerArray(value, intArray);
          value = LocaleConvertUtils.convert("0,1a3", intArray.getClass());
          checkIntegerArray(value, intArray);
          value = LocaleConvertUtils.convert("{ 0, 1a3 }", intArray.getClass());
          checkIntegerArray(value, intArray);
  
      }
  
  
      /**
       * Negative scalar conversion tests.  These rely on the standard
       * default value conversions in LocaleConvertUtils.
       */
      public void testNegativeScalar() {
  
          Object value = null;
  
          /*  fixme Boolean converters not implemented at this point
          value = LocaleConvertUtils.convert("foo", Boolean.TYPE);
          ...
  
          value = LocaleConvertUtils.convert("foo", Boolean.class);
          ...
          */
  
  
          try {
              value = LocaleConvertUtils.convert("foo", Byte.TYPE);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
          try {
              value = LocaleConvertUtils.convert("foo", Byte.class);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
          /* fixme - not implemented
           try {
               value = LocaleConvertUtils.convert("org.apache.commons.beanutils.Undefined", Class.class);
               fail("Should have thrown conversion exception");
           } catch (ConversionException e) {
               ; // Expected result
           }
           */
  
          try {
              value = LocaleConvertUtils.convert("foo", Double.TYPE);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
          try {
              value = LocaleConvertUtils.convert("foo", Double.class);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
          try {
              value = LocaleConvertUtils.convert("foo", Float.TYPE);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
          try {
              value = LocaleConvertUtils.convert("foo", Float.class);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
          try {
              value = LocaleConvertUtils.convert("foo", Integer.TYPE);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
          try {
              value = LocaleConvertUtils.convert("foo", Integer.class);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
          try {
              value = LocaleConvertUtils.convert("foo", Byte.TYPE);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
          try {
              value = LocaleConvertUtils.convert("foo", Long.class);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
          try {
              value = LocaleConvertUtils.convert("foo", Short.TYPE);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
          try {
              value = LocaleConvertUtils.convert("foo", Short.class);
              fail("Should have thrown conversion exception");
          } catch (ConversionException e) {
              ; // Expected result
          }
  
      }
  
  
      /**
       * Negative String to String array tests.
       */
      public void fixmetestNegativeStringArray() {
  
          fail("Array conversions not implemented yet.");
  
          Object value = null;
          String stringArray[] = new String[0];
  
          value = LocaleConvertUtils.convert((String) null, stringArray.getClass());
          checkStringArray(value, stringArray);
      }
  
  
      /**
       * Test conversion of object to string for arrays - .
       */
      public void fixmetestObjectToStringArray() {
  
          fail("Array conversions not implemented yet.");
          int intArray0[] = new int[0];
          int intArray1[] = {123};
          int intArray2[] = {123, 456};
          String stringArray0[] = new String[0];
          String stringArray1[] = {"abc"};
          String stringArray2[] = {"abc", "def"};
  
          assertEquals("intArray0", null,
                  LocaleConvertUtils.convert(intArray0));
          assertEquals("intArray1", "123",
                  LocaleConvertUtils.convert(intArray1));
          assertEquals("intArray2", "123",
                  LocaleConvertUtils.convert(intArray2));
  
          assertEquals("stringArray0", null,
                  LocaleConvertUtils.convert(stringArray0));
          assertEquals("stringArray1", "abc",
                  LocaleConvertUtils.convert(stringArray1));
          assertEquals("stringArray2", "abc",
                  LocaleConvertUtils.convert(stringArray2));
  
      }
  
  
      /**
       * Test conversion of object to string for scalars.
       */
      public void testObjectToStringScalar() {
  
          assertEquals("Boolean->String", "false",
                  LocaleConvertUtils.convert(Boolean.FALSE));
          assertEquals("Boolean->String", "true",
                  LocaleConvertUtils.convert(Boolean.TRUE));
          assertEquals("Byte->String", "123",
                  LocaleConvertUtils.convert(new Byte((byte) 123)));
          assertEquals("Character->String", "a",
                  LocaleConvertUtils.convert(new Character('a')));
          assertEquals("Double->String", "123.4",
                  LocaleConvertUtils.convert(new Double((double) 123.4)));
          assertEquals("Float->String", "123.4",
                  LocaleConvertUtils.convert(new Float((float) 123.4)));
          assertEquals("Integer->String", "123",
                  LocaleConvertUtils.convert(new Integer((int) 123)));
          assertEquals("Long->String", "123",
                  LocaleConvertUtils.convert(new Long((long) 123)));
          assertEquals("Short->String", "123",
                  LocaleConvertUtils.convert(new Short((short) 123)));
          assertEquals("String->String", "abc",
                  LocaleConvertUtils.convert("abc"));
          assertEquals("String->String null", null,
                  LocaleConvertUtils.convert(null));
  
      }
  
  
      /**
       * Positive array conversion tests.
       */
      public void fixmetestPositiveArray() {
  
          fail("Array conversions not implemented yet.");
  
          String values1[] = {"10", "20", "30"};
          Object value = LocaleConvertUtils.convert(values1, Integer.TYPE);
          int shape[] = new int[0];
          assertEquals(shape.getClass(), value.getClass());
          int results1[] = (int[]) value;
          assertEquals(results1[0], 10);
          assertEquals(results1[1], 20);
          assertEquals(results1[2], 30);
  
          String values2[] = {"100", "200", "300"};
          value = LocaleConvertUtils.convert(values2, shape.getClass());
          assertEquals(shape.getClass(), value.getClass());
          int results2[] = (int[]) value;
          assertEquals(results2[0], 100);
          assertEquals(results2[1], 200);
          assertEquals(results2[2], 300);
      }
  
  
      /**
       * Positive String to primitive integer array tests.
       */
      public void fixmetestPositiveIntegerArray() {
  
          fail("Array conversions not implemented yet.");
  
          Object value = null;
          int intArray[] = new int[0];
          int intArray1[] = new int[]{0};
          int intArray2[] = new int[]{0, 10};
  
          value = LocaleConvertUtils.convert("{  }", intArray.getClass());
          checkIntegerArray(value, intArray);
  
          value = LocaleConvertUtils.convert("0", intArray.getClass());
          checkIntegerArray(value, intArray1);
          value = LocaleConvertUtils.convert(" 0 ", intArray.getClass());
          checkIntegerArray(value, intArray1);
          value = LocaleConvertUtils.convert("{ 0 }", intArray.getClass());
          checkIntegerArray(value, intArray1);
  
          value = LocaleConvertUtils.convert("0,10", intArray.getClass());
          checkIntegerArray(value, intArray2);
          value = LocaleConvertUtils.convert("0 10", intArray.getClass());
          checkIntegerArray(value, intArray2);
          value = LocaleConvertUtils.convert("{0,10}", intArray.getClass());
          checkIntegerArray(value, intArray2);
          value = LocaleConvertUtils.convert("{0 10}", intArray.getClass());
          checkIntegerArray(value, intArray2);
          value = LocaleConvertUtils.convert("{ 0, 10 }", intArray.getClass());
          checkIntegerArray(value, intArray2);
          value = LocaleConvertUtils.convert("{ 0 10 }", intArray.getClass());
          checkIntegerArray(value, intArray2);
      }
  
  
      /**
       * Positive scalar conversion tests.
       */
      public void testPositiveScalar() {
          Object value = null;
  
          /* fixme Boolean converters not implemented
           value = LocaleConvertUtils.convert("true", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), true);
  
           value = LocaleConvertUtils.convert("true", Boolean.class);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), true);
  
           value = LocaleConvertUtils.convert("yes", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), true);
  
           value = LocaleConvertUtils.convert("yes", Boolean.class);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), true);
  
           value = LocaleConvertUtils.convert("y", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), true);
  
           value = LocaleConvertUtils.convert("y", Boolean.class);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), true);
  
           value = LocaleConvertUtils.convert("on", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), true);
  
           value = LocaleConvertUtils.convert("on", Boolean.class);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), true);
  
           value = LocaleConvertUtils.convert("false", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), false);
  
           value = LocaleConvertUtils.convert("false", Boolean.class);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), false);
  
           value = LocaleConvertUtils.convert("no", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), false);
  
           value = LocaleConvertUtils.convert("no", Boolean.class);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), false);
  
           value = LocaleConvertUtils.convert("n", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), false);
  
           value = LocaleConvertUtils.convert("n", Boolean.class);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), false);
  
           value = LocaleConvertUtils.convert("off", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), false);
  
           value = LocaleConvertUtils.convert("off", Boolean.class);
           assertTrue(value instanceof Boolean);
           assertEquals(((Boolean) value).booleanValue(), false);
           */
  
          value = LocaleConvertUtils.convert("123", Byte.TYPE);
          assertTrue(value instanceof Byte);
          assertEquals(((Byte) value).byteValue(), (byte) 123);
  
          value = LocaleConvertUtils.convert("123", Byte.class);
          assertTrue(value instanceof Byte);
          assertEquals(((Byte) value).byteValue(), (byte) 123);
  
          /*fixme Character conversion not implemented yet
          value = LocaleConvertUtils.convert("a", Character.TYPE);
          assertTrue(value instanceof Character);
          assertEquals(((Character) value).charValue(), 'a');
  
          value = LocaleConvertUtils.convert("a", Character.class);
          assertTrue(value instanceof Character);
          assertEquals(((Character) value).charValue(), 'a');
          */
          /* fixme - this is a discrepancy with standard converters ( probably not major issue )
          value = LocaleConvertUtils.convert("java.lang.String", Class.class);
          assertTrue(value instanceof Class);
          assertEquals(String.class, (Class) value);
          */
  
          value = LocaleConvertUtils.convert("123.456", Double.TYPE);
          assertTrue(value instanceof Double);
          assertEquals(((Double) value).doubleValue(), (double) 123.456,
                  (double) 0.005);
  
          value = LocaleConvertUtils.convert("123.456", Double.class);
          assertTrue(value instanceof Double);
          assertEquals(((Double) value).doubleValue(), (double) 123.456,
                  (double) 0.005);
  
          value = LocaleConvertUtils.convert("123.456", Float.TYPE);
          assertTrue(value instanceof Float);
          assertEquals(((Float) value).floatValue(), (float) 123.456,
                  (float) 0.005);
  
          value = LocaleConvertUtils.convert("123.456", Float.class);
          assertTrue(value instanceof Float);
          assertEquals(((Float) value).floatValue(), (float) 123.456,
                  (float) 0.005);
  
          value = LocaleConvertUtils.convert("123", Integer.TYPE);
          assertTrue(value instanceof Integer);
          assertEquals(((Integer) value).intValue(), (int) 123);
  
          value = LocaleConvertUtils.convert("123", Integer.class);
          assertTrue(value instanceof Integer);
          assertEquals(((Integer) value).intValue(), (int) 123);
  
          value = LocaleConvertUtils.convert("123", Long.TYPE);
          assertTrue(value instanceof Long);
          assertEquals(((Long) value).longValue(), (long) 123);
  
          value = LocaleConvertUtils.convert("123456", Long.class);
          assertTrue(value instanceof Long);
          assertEquals(((Long) value).longValue(), (long) 123456);
  
          /* fixme - Short conversion not implemented at this point
          value = LocaleConvertUtils.convert("123", Short.TYPE);
          assertTrue(value instanceof Short);
          assertEquals(((Short) value).shortValue(), (short) 123);
  
          value = LocaleConvertUtils.convert("123", Short.class);
          assertTrue(value instanceof Short);
          assertEquals(((Short) value).shortValue(), (short) 123);
          */
  
          String input = null;
  
          input = "2002-03-17";
          value = LocaleConvertUtils.convert(input, Date.class);
          assertTrue(value instanceof Date);
          assertEquals(input, value.toString());
  
          input = "20:30:40";
          value = LocaleConvertUtils.convert(input, Time.class);
          assertTrue(value instanceof Time);
          assertEquals(input, value.toString());
  
          input = "2002-03-17 20:30:40.0";
          value = LocaleConvertUtils.convert(input, Timestamp.class);
          assertTrue(value instanceof Timestamp);
          assertEquals(input, value.toString());
  
      }
  
  
      /**
       * Positive String to String array tests.
       */
      public void fixmetestPositiveStringArray() {
  
          fail("Array conversions not implemented yet.");
  
          Object value = null;
          String stringArray[] = new String[0];
          String stringArray1[] = new String[]
          {"abc"};
          String stringArray2[] = new String[]
          {"abc", "de,f"};
  
          value = LocaleConvertUtils.convert("", stringArray.getClass());
          checkStringArray(value, stringArray);
          value = LocaleConvertUtils.convert(" ", stringArray.getClass());
          checkStringArray(value, stringArray);
          value = LocaleConvertUtils.convert("{}", stringArray.getClass());
          checkStringArray(value, stringArray);
          value = LocaleConvertUtils.convert("{  }", stringArray.getClass());
          checkStringArray(value, stringArray);
  
          value = LocaleConvertUtils.convert("abc", stringArray.getClass());
          checkStringArray(value, stringArray1);
          value = LocaleConvertUtils.convert("{abc}", stringArray.getClass());
          checkStringArray(value, stringArray1);
          value = LocaleConvertUtils.convert("\"abc\"", stringArray.getClass());
          checkStringArray(value, stringArray1);
          value = LocaleConvertUtils.convert("{\"abc\"}", stringArray.getClass());
          checkStringArray(value, stringArray1);
          value = LocaleConvertUtils.convert("'abc'", stringArray.getClass());
          checkStringArray(value, stringArray1);
          value = LocaleConvertUtils.convert("{'abc'}", stringArray.getClass());
          checkStringArray(value, stringArray1);
  
          value = LocaleConvertUtils.convert("abc 'de,f'",
                  stringArray.getClass());
          checkStringArray(value, stringArray2);
          value = LocaleConvertUtils.convert("{abc, 'de,f'}",
                  stringArray.getClass());
          checkStringArray(value, stringArray2);
          value = LocaleConvertUtils.convert("\"abc\",\"de,f\"",
                  stringArray.getClass());
          checkStringArray(value, stringArray2);
          value = LocaleConvertUtils.convert("{\"abc\" 'de,f'}",
                  stringArray.getClass());
          checkStringArray(value, stringArray2);
          value = LocaleConvertUtils.convert("'abc' 'de,f'",
                  stringArray.getClass());
          checkStringArray(value, stringArray2);
          value = LocaleConvertUtils.convert("{'abc', \"de,f\"}",
                  stringArray.getClass());
          checkStringArray(value, stringArray2);
  
      }
  
  
      // -------------------------------------------------------- Private Methods
  
  
      private void checkIntegerArray(Object value, int intArray[]) {
  
          assertNotNull("Returned value is not null", value);
          assertEquals("Returned value is int[]",
                  intArray.getClass(), value.getClass());
          int results[] = (int[]) value;
          assertEquals("Returned array length", intArray.length, results.length);
          for (int i = 0; i < intArray.length; i++) {
              assertEquals("Returned array value " + i,
                      intArray[i], results[i]);
          }
  
      }
  
  
      private void checkStringArray(Object value, String stringArray[]) {
  
          assertNotNull("Returned value is not null", value);
          assertEquals("Returned value is String[]",
                  stringArray.getClass(), value.getClass());
          String results[] = (String[]) value;
          assertEquals("Returned array length",
                  stringArray.length, results.length);
          for (int i = 0; i < stringArray.length; i++) {
              assertEquals("Returned array value " + i,
                      stringArray[i], results[i]);
          }
  
      }
  
  
  }
  
  
  
  

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


Mime
View raw message