Class BaseLocaleConverter<T>

java.lang.Object
org.apache.commons.beanutils2.locale.BaseLocaleConverter<T>
Type Parameters:
T - The converter type.
All Implemented Interfaces:
Converter<T>, LocaleConverter<T>
Direct Known Subclasses:
DateLocaleConverter, DecimalLocaleConverter, StringLocaleConverter

public abstract class BaseLocaleConverter<T> extends Object implements LocaleConverter<T>
The base class for all standard type locale-sensitive converters. It has LocaleConverter and Converter implementations, that convert an incoming locale-sensitive Object into an object of correspond type, optionally using a default value or throwing a ConversionException if a conversion error occurs.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Builds instances of BaseLocaleConverter subclasses.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final T
    The default value specified to our Constructor, if any.
    protected final Locale
    The locale specified to our Constructor, by default - system locale.
    protected final boolean
    The flag indicating whether the given pattern string is localized or not.
    protected final String
    The default pattern specified to our Constructor, if any.
    protected final boolean
    Should we return the default value on conversion errors?
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    BaseLocaleConverter(T defaultValue, Locale locale, String pattern, boolean useDefault, boolean locPattern)
    Constructs a LocaleConverter that will return the specified default value or throw a ConversionException if a conversion error occurs.
  • Method Summary

    Modifier and Type
    Method
    Description
    <R> R
    convert(Class<R> type, Object value)
    Converts the specified locale-sensitive input object into an output object of the specified type.
    <R> R
    convert(Class<R> type, Object value, String pattern)
    Converts the specified locale-sensitive input object into an output object of the specified type.
    convert(Object value)
    Converts the specified locale-sensitive input object into an output object.
    convert(Object value, String pattern)
    Converts the specified locale-sensitive input object into an output object.
    protected abstract T
    parse(Object value, String pattern)
    Converts the specified locale-sensitive input object into an output object of the specified type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • defaultValue

      protected final T defaultValue
      The default value specified to our Constructor, if any.
    • locale

      protected final Locale locale
      The locale specified to our Constructor, by default - system locale.
    • localizedPattern

      protected final boolean localizedPattern
      The flag indicating whether the given pattern string is localized or not.
    • pattern

      protected final String pattern
      The default pattern specified to our Constructor, if any.
    • useDefault

      protected final boolean useDefault
      Should we return the default value on conversion errors?
  • Constructor Details

    • BaseLocaleConverter

      protected BaseLocaleConverter(T defaultValue, Locale locale, String pattern, boolean useDefault, boolean locPattern)
      Constructs a LocaleConverter that will return the specified default value or throw a ConversionException if a conversion error occurs.
      Parameters:
      defaultValue - The default value to be returned
      locale - The locale
      pattern - The conversion pattern
      useDefault - Indicate whether the default value is used or not
      locPattern - Indicate whether the pattern is localized or not
  • Method Details

    • convert

      public <R> R convert(Class<R> type, Object value)
      Converts the specified locale-sensitive input object into an output object of the specified type. The default pattern is used for the conversion.
      Specified by:
      convert in interface Converter<T>
      Type Parameters:
      R - the result type.
      Parameters:
      type - Data type to which this value should be converted
      value - The input object to be converted
      Returns:
      The converted value
      Throws:
      ConversionException - if conversion cannot be performed successfully
    • convert

      public <R> R convert(Class<R> type, Object value, String pattern)
      Converts the specified locale-sensitive input object into an output object of the specified type.
      Specified by:
      convert in interface LocaleConverter<T>
      Type Parameters:
      R - the result type.
      Parameters:
      type - Data is type to which this value should be converted
      value - is the input object to be converted
      pattern - is the pattern is used for the conversion; if null is passed then the default pattern associated with the converter object will be used.
      Returns:
      The converted value
      Throws:
      ConversionException - if conversion cannot be performed successfully
    • convert

      public Object convert(Object value)
      Converts the specified locale-sensitive input object into an output object. The default pattern is used for the conversion.
      Parameters:
      value - The input object to be converted
      Returns:
      The converted value
      Throws:
      ConversionException - if conversion cannot be performed successfully
    • convert

      public T convert(Object value, String pattern)
      Converts the specified locale-sensitive input object into an output object.
      Parameters:
      value - The input object to be converted
      pattern - The pattern is used for the conversion
      Returns:
      The converted value
      Throws:
      ConversionException - if conversion cannot be performed successfully
    • parse

      protected abstract T parse(Object value, String pattern) throws ParseException
      Converts the specified locale-sensitive input object into an output object of the specified type.
      Parameters:
      value - The input object to be converted
      pattern - The pattern is used for the conversion
      Returns:
      The converted value
      Throws:
      ParseException - if conversion cannot be performed successfully