Class BaseLocaleConverter

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Object defaultValue
      The default value specified to our Constructor, if any.
      protected java.util.Locale locale
      The locale specified to our Constructor, by default - system locale.
      protected boolean locPattern
      The flag indicating whether the given pattern string is localized or not.
      private org.apache.commons.logging.Log log
      All logging goes through this logger
      protected java.lang.String pattern
      The default pattern specified to our Constructor, if any.
      protected boolean useDefault
      Should we return the default value on conversion errors?
    • Constructor Summary

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

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      private static <T> T checkConversionResult​(java.lang.Class<T> type, java.lang.Object result)
      Checks whether the result of a conversion is conform to the specified target type.
      <T> T convert​(java.lang.Class<T> type, java.lang.Object value)
      Convert the specified locale-sensitive input object into an output object of the specified type.
      <T> T convert​(java.lang.Class<T> type, java.lang.Object value, java.lang.String pattern)
      Convert the specified locale-sensitive input object into an output object of the specified type.
      java.lang.Object convert​(java.lang.Object value)
      Convert the specified locale-sensitive input object into an output object.
      java.lang.Object convert​(java.lang.Object value, java.lang.String pattern)
      Convert the specified locale-sensitive input object into an output object.
      private <T> T getDefaultAs​(java.lang.Class<T> type)
      Returns the default object specified for this converter cast for the given target type.
      protected abstract java.lang.Object parse​(java.lang.Object value, java.lang.String pattern)
      Convert 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 Detail

      • log

        private final org.apache.commons.logging.Log log
        All logging goes through this logger
      • defaultValue

        private java.lang.Object defaultValue
        The default value specified to our Constructor, if any.
      • useDefault

        protected boolean useDefault
        Should we return the default value on conversion errors?
      • locale

        protected java.util.Locale locale
        The locale specified to our Constructor, by default - system locale.
      • pattern

        protected java.lang.String pattern
        The default pattern specified to our Constructor, if any.
      • locPattern

        protected boolean locPattern
        The flag indicating whether the given pattern string is localized or not.
    • Constructor Detail

      • BaseLocaleConverter

        protected BaseLocaleConverter​(java.util.Locale locale,
                                      java.lang.String pattern)
        Create a LocaleConverter that will throw a ConversionException if a conversion error occurs. An unlocalized pattern is used for the convertion.
        Parameters:
        locale - The locale
        pattern - The convertion pattern
      • BaseLocaleConverter

        protected BaseLocaleConverter​(java.util.Locale locale,
                                      java.lang.String pattern,
                                      boolean locPattern)
        Create a LocaleConverter that will throw a ConversionException if a conversion error occurs.
        Parameters:
        locale - The locale
        pattern - The convertion pattern
        locPattern - Indicate whether the pattern is localized or not
      • BaseLocaleConverter

        protected BaseLocaleConverter​(java.lang.Object defaultValue,
                                      java.util.Locale locale,
                                      java.lang.String pattern)
        Create a LocaleConverter that will return the specified default value if a conversion error occurs. An unlocalized pattern is used for the convertion.
        Parameters:
        defaultValue - The default value to be returned
        locale - The locale
        pattern - The convertion pattern
      • BaseLocaleConverter

        protected BaseLocaleConverter​(java.lang.Object defaultValue,
                                      java.util.Locale locale,
                                      java.lang.String pattern,
                                      boolean locPattern)
        Create a LocaleConverter that will return the specified default value if a conversion error occurs.
        Parameters:
        defaultValue - The default value to be returned
        locale - The locale
        pattern - The convertion pattern
        locPattern - Indicate whether the pattern is localized or not
      • BaseLocaleConverter

        private BaseLocaleConverter​(java.lang.Object defaultValue,
                                    java.util.Locale locale,
                                    java.lang.String pattern,
                                    boolean useDefault,
                                    boolean locPattern)
        Create 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 convertion pattern
        useDefault - Indicate whether the default value is used or not
        locPattern - Indicate whether the pattern is localized or not
    • Method Detail

      • parse

        protected abstract java.lang.Object parse​(java.lang.Object value,
                                                  java.lang.String pattern)
                                           throws java.text.ParseException
        Convert 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 convertion
        Returns:
        The converted value
        Throws:
        java.text.ParseException - if conversion cannot be performed successfully
      • convert

        public java.lang.Object convert​(java.lang.Object value)
        Convert 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 java.lang.Object convert​(java.lang.Object value,
                                        java.lang.String pattern)
        Convert 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
      • convert

        public <T> T convert​(java.lang.Class<T> type,
                             java.lang.Object value)
        Convert the specified locale-sensitive input object into an output object of the specified type. The default pattern is used for the convertion.
        Specified by:
        convert in interface Converter
        Type Parameters:
        T - The desired target type of the conversion
        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 <T> T convert​(java.lang.Class<T> type,
                             java.lang.Object value,
                             java.lang.String pattern)
        Convert the specified locale-sensitive input object into an output object of the specified type.
        Specified by:
        convert in interface LocaleConverter
        Type Parameters:
        T - The desired target type of the conversion
        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
      • getDefaultAs

        private <T> T getDefaultAs​(java.lang.Class<T> type)
        Returns the default object specified for this converter cast for the given target type. If the default value is not conform to the given type, an exception is thrown.
        Type Parameters:
        T - the desired target type
        Parameters:
        type - the target class of the conversion
        Returns:
        the default value in the given target type
        Throws:
        ConversionException - if the default object is not compatible with the target type
      • checkConversionResult

        private static <T> T checkConversionResult​(java.lang.Class<T> type,
                                                   java.lang.Object result)
        Checks whether the result of a conversion is conform to the specified target type. If this is the case, the passed in result object is cast to the correct target type. Otherwise, an exception is thrown.
        Type Parameters:
        T - the desired result type
        Parameters:
        type - the target class of the conversion
        result - the conversion result object
        Returns:
        the result cast to the target class
        Throws:
        ConversionException - if the result object is not compatible with the target type