Class LocaleConvertUtilsBean
Utility methods for converting locale-sensitive String scalar values to objects of the specified Class, String arrays to arrays of the specified Class and object to locale-sensitive String scalar value.
This class provides the implementations used by the static utility methods in
LocaleConvertUtils
.
The actual LocaleConverter
instance to be used
can be registered for each possible destination Class. Unless you override them, standard
LocaleConverter
instances are provided for all of the following
destination Classes:
- java.lang.BigDecimal
- java.lang.BigInteger
- byte and java.lang.Byte
- double and java.lang.Double
- float and java.lang.Float
- int and java.lang.Integer
- long and java.lang.Long
- short and java.lang.Short
- java.lang.String
- java.sql.Date
- java.sql.Time
- java.sql.Timestamp
For backwards compatibility, the standard locale converters
for primitive types (and the corresponding wrapper classes).
If you prefer to have another LocaleConverter
thrown instead, replace the standard LocaleConverter
instances
with ones created with the one of the appropriate constructors.
It's important that LocaleConverter
should be registered for
the specified locale and Class (or primitive type).
- Since:
- 1.7
- Version:
- $Id$
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
FastHashMap implementation that uses WeakReferences to overcome memory leak problems. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
Indicate whether the pattern is localized or notprivate Locale
The locale - default for convertion.private final org.apache.commons.logging.Log
TheLog
instance for this class.private final org.apache.commons.collections.FastHashMap
Every entry of the mapConverters is: key = locale value = FastHashMap of converters for the certain locale. -
Constructor Summary
ConstructorsConstructorDescriptionMakes the state by default (deregisters all converters for all locales) and then registers default locale converters. -
Method Summary
Modifier and TypeMethodDescriptionConvert the specified locale-sensitive value into a String.Convert the specified locale-sensitive value into a String using the conversion pattern.Convert the specified locale-sensitive value into a String using the paticular convertion pattern.Convert an array of specified values to an array of objects of the specified class (if possible) .Convert an array of specified values to an array of objects of the specified class (if possible) using the convertion pattern.Convert an array of specified values to an array of objects of the specified class (if possible) using the convertion pattern.Convert the specified value to an object of the specified class (if possible).Convert the specified value to an object of the specified class (if possible) using the convertion pattern.Convert the specified value to an object of the specified class (if possible) using the convertion pattern.protected org.apache.commons.collections.FastHashMap
Deprecated.This method will be modified to return a Map in the next release.void
Remove any registeredLocaleConverter
.void
deregister
(Class<?> clazz, Locale locale) Remove any registeredLocaleConverter
for the specified locale and Class.void
deregister
(Locale locale) Remove any registeredLocaleConverter
for the specified localeboolean
getter for applyLocalizedgetter for defaultLocale.static LocaleConvertUtilsBean
Gets singleton instance.Look up and return any registeredLocaleConverter
for the specified destination class and locale; if there is no registered Converter, returnnull
.protected org.apache.commons.collections.FastHashMap
Deprecated.This method will be modified to return a Map in the next release.void
register
(LocaleConverter converter, Class<?> clazz, Locale locale) Register a customLocaleConverter
for the specified destinationClass
, replacing any previously registered converter.void
setApplyLocalized
(boolean newApplyLocalized) setter for applyLocalizedvoid
setDefaultLocale
(Locale locale) setter for defaultLocale.
-
Field Details
-
defaultLocale
The locale - default for convertion. -
applyLocalized
private boolean applyLocalizedIndicate whether the pattern is localized or not -
log
private final org.apache.commons.logging.Log logTheLog
instance for this class. -
mapConverters
private final org.apache.commons.collections.FastHashMap mapConvertersEvery entry of the mapConverters is: key = locale value = FastHashMap of converters for the certain locale.
-
-
Constructor Details
-
LocaleConvertUtilsBean
public LocaleConvertUtilsBean()Makes the state by default (deregisters all converters for all locales) and then registers default locale converters.
-
-
Method Details
-
getInstance
Gets singleton instance. This is the same as the instance used by the defaultLocaleBeanUtilsBean
singleton.- Returns:
- the singleton instance
-
getDefaultLocale
getter for defaultLocale.- Returns:
- the default locale
-
setDefaultLocale
setter for defaultLocale.- Parameters:
locale
- the default locale
-
getApplyLocalized
public boolean getApplyLocalized()getter for applyLocalized- Returns:
true
if pattern is localized, otherwisefalse
-
setApplyLocalized
public void setApplyLocalized(boolean newApplyLocalized) setter for applyLocalized- Parameters:
newApplyLocalized
-true
if pattern is localized, otherwisefalse
-
convert
Convert the specified locale-sensitive value into a String.- Parameters:
value
- The Value to be converted- Returns:
- the converted value
- Throws:
ConversionException
- if thrown by an underlying Converter
-
convert
Convert the specified locale-sensitive value into a String using the conversion pattern.- Parameters:
value
- The Value to be convertedpattern
- The convertion pattern- Returns:
- the converted value
- Throws:
ConversionException
- if thrown by an underlying Converter
-
convert
Convert the specified locale-sensitive value into a String using the paticular convertion pattern.- Parameters:
value
- The Value to be convertedlocale
- The localepattern
- The convertion pattern- Returns:
- the converted value
- Throws:
ConversionException
- if thrown by an underlying Converter
-
convert
Convert the specified value to an object of the specified class (if possible). Otherwise, return a String representation of the value.- Parameters:
value
- The String scalar value to be convertedclazz
- The Data type to which this value should be converted.- Returns:
- the converted value
- Throws:
ConversionException
- if thrown by an underlying Converter
-
convert
Convert the specified value to an object of the specified class (if possible) using the convertion pattern. Otherwise, return a String representation of the value.- Parameters:
value
- The String scalar value to be convertedclazz
- The Data type to which this value should be converted.pattern
- The convertion pattern- Returns:
- the converted value
- Throws:
ConversionException
- if thrown by an underlying Converter
-
convert
Convert the specified value to an object of the specified class (if possible) using the convertion pattern. Otherwise, return a String representation of the value.- Parameters:
value
- The String scalar value to be convertedclazz
- The Data type to which this value should be converted.locale
- The localepattern
- The convertion pattern- Returns:
- the converted value
- Throws:
ConversionException
- if thrown by an underlying Converter
-
convert
Convert an array of specified values to an array of objects of the specified class (if possible) using the convertion pattern.- Parameters:
values
- Value to be converted (may be null)clazz
- Java array or element class to be converted topattern
- The convertion pattern- Returns:
- the converted value
- Throws:
ConversionException
- if thrown by an underlying Converter
-
convert
Convert an array of specified values to an array of objects of the specified class (if possible) .- Parameters:
values
- Value to be converted (may be null)clazz
- Java array or element class to be converted to- Returns:
- the converted value
- Throws:
ConversionException
- if thrown by an underlying Converter
-
convert
Convert an array of specified values to an array of objects of the specified class (if possible) using the convertion pattern.- Parameters:
values
- Value to be converted (may be null)clazz
- Java array or element class to be converted tolocale
- The localepattern
- The convertion pattern- Returns:
- the converted value
- Throws:
ConversionException
- if thrown by an underlying Converter
-
register
Register a customLocaleConverter
for the specified destinationClass
, replacing any previously registered converter.- Parameters:
converter
- The LocaleConverter to be registeredclazz
- The Destination class for conversions performed by this Converterlocale
- The locale
-
deregister
public void deregister()Remove any registeredLocaleConverter
. -
deregister
Remove any registeredLocaleConverter
for the specified locale- Parameters:
locale
- The locale
-
deregister
Remove any registeredLocaleConverter
for the specified locale and Class.- Parameters:
clazz
- Class for which to remove a registered Converterlocale
- The locale
-
lookup
Look up and return any registeredLocaleConverter
for the specified destination class and locale; if there is no registered Converter, returnnull
.- Parameters:
clazz
- Class for which to return a registered Converterlocale
- The Locale- Returns:
- The registered locale Converter, if any
-
lookup
Deprecated.This method will be modified to return a Map in the next release.Look up and return any registered FastHashMap instance for the specified locale; if there is no registered one, returnnull
.- Parameters:
locale
- The Locale- Returns:
- The FastHashMap instance contains the all
LocaleConverter
types for the specified locale.
-
create
Deprecated.This method will be modified to return a Map in the next release.Create allLocaleConverter
types for specified locale.- Parameters:
locale
- The Locale- Returns:
- The FastHashMap instance contains the all
LocaleConverter
types for the specified locale.
-