Class BaseLocaleConverter
java.lang.Object
org.apache.commons.beanutils.locale.BaseLocaleConverter
- All Implemented Interfaces:
Converter
,LocaleConverter
- Direct Known Subclasses:
DateLocaleConverter
,DecimalLocaleConverter
,StringLocaleConverter
The base class for all standart 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.
- Version:
- $Id$
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Object
The default value specified to our Constructor, if any.protected Locale
The locale specified to our Constructor, by default - system locale.protected boolean
The flag indicating whether the given pattern string is localized or not.private final org.apache.commons.logging.Log
All logging goes through this loggerprotected String
The default pattern specified to our Constructor, if any.protected boolean
Should we return the default value on conversion errors? -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BaseLocaleConverter
(Object defaultValue, Locale locale, String pattern) Create aLocaleConverter
that will return the specified default value if a conversion error occurs.protected
BaseLocaleConverter
(Object defaultValue, Locale locale, String pattern, boolean locPattern) Create aLocaleConverter
that will return the specified default value if a conversion error occurs.private
BaseLocaleConverter
(Object defaultValue, Locale locale, String pattern, boolean useDefault, boolean locPattern) Create aLocaleConverter
that will return the specified default value or throw aConversionException
if a conversion error occurs.protected
BaseLocaleConverter
(Locale locale, String pattern) Create aLocaleConverter
that will throw aConversionException
if a conversion error occurs.protected
BaseLocaleConverter
(Locale locale, String pattern, boolean locPattern) Create aLocaleConverter
that will throw aConversionException
if a conversion error occurs. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> T
checkConversionResult
(Class<T> type, Object result) Checks whether the result of a conversion is conform to the specified target type.<T> T
Convert the specified locale-sensitive input object into an output object of the specified type.<T> T
Convert the specified locale-sensitive input object into an output object of the specified type.Convert the specified locale-sensitive input object into an output object.Convert the specified locale-sensitive input object into an output object.private <T> T
getDefaultAs
(Class<T> type) Returns the default object specified for this converter cast for the given target type.protected abstract Object
Convert the specified locale-sensitive input object into an output object of the specified type.
-
Field Details
-
log
private final org.apache.commons.logging.Log logAll logging goes through this logger -
defaultValue
The default value specified to our Constructor, if any. -
useDefault
protected boolean useDefaultShould we return the default value on conversion errors? -
locale
The locale specified to our Constructor, by default - system locale. -
pattern
The default pattern specified to our Constructor, if any. -
locPattern
protected boolean locPatternThe flag indicating whether the given pattern string is localized or not.
-
-
Constructor Details
-
BaseLocaleConverter
Create aLocaleConverter
that will throw aConversionException
if a conversion error occurs. An unlocalized pattern is used for the convertion.- Parameters:
locale
- The localepattern
- The convertion pattern
-
BaseLocaleConverter
Create aLocaleConverter
that will throw aConversionException
if a conversion error occurs.- Parameters:
locale
- The localepattern
- The convertion patternlocPattern
- Indicate whether the pattern is localized or not
-
BaseLocaleConverter
Create aLocaleConverter
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 returnedlocale
- The localepattern
- The convertion pattern
-
BaseLocaleConverter
protected BaseLocaleConverter(Object defaultValue, Locale locale, String pattern, boolean locPattern) Create aLocaleConverter
that will return the specified default value if a conversion error occurs.- Parameters:
defaultValue
- The default value to be returnedlocale
- The localepattern
- The convertion patternlocPattern
- Indicate whether the pattern is localized or not
-
BaseLocaleConverter
private BaseLocaleConverter(Object defaultValue, Locale locale, String pattern, boolean useDefault, boolean locPattern) Create aLocaleConverter
that will return the specified default value or throw aConversionException
if a conversion error occurs.- Parameters:
defaultValue
- The default value to be returnedlocale
- The localepattern
- The convertion patternuseDefault
- Indicate whether the default value is used or notlocPattern
- Indicate whether the pattern is localized or not
-
-
Method Details
-
parse
Convert the specified locale-sensitive input object into an output object of the specified type.- Parameters:
value
- The input object to be convertedpattern
- The pattern is used for the convertion- Returns:
- The converted value
- Throws:
ParseException
- if conversion cannot be performed successfully
-
convert
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
Convert the specified locale-sensitive input object into an output object.- Parameters:
value
- The input object to be convertedpattern
- The pattern is used for the conversion- Returns:
- The converted value
- Throws:
ConversionException
- if conversion cannot be performed successfully
-
convert
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 interfaceConverter
- Type Parameters:
T
- The desired target type of the conversion- Parameters:
type
- Data type to which this value should be convertedvalue
- The input object to be converted- Returns:
- The converted value
- Throws:
ConversionException
- if conversion cannot be performed successfully
-
convert
Convert the specified locale-sensitive input object into an output object of the specified type.- Specified by:
convert
in interfaceLocaleConverter
- Type Parameters:
T
- The desired target type of the conversion- Parameters:
type
- Data is type to which this value should be convertedvalue
- is the input object to be convertedpattern
- 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
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
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 conversionresult
- 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
-