org.apache.commons.beanutils.locale
Class LocaleConvertUtilsBean
java.lang.Object
org.apache.commons.beanutils.locale.LocaleConvertUtilsBean
public class LocaleConvertUtilsBean
extends java.lang.Object
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).
private boolean | applyLocalized - Indicate whether the pattern is localized or not
|
private Locale | defaultLocale - The locale - default for convertion.
|
private Log | log - The
Log instance for this class.
|
private FastHashMap | mapConverters - Every entry of the mapConverters is:
key = locale
value = FastHashMap of converters for the certain locale.
|
LocaleConvertUtilsBean() - Makes the state by default (deregisters all converters for all locales)
and then registers default locale converters.
|
String | convert(Object value) - Convert the specified locale-sensitive value into a String.
|
String | convert(Object value, Locale locale, String pattern) - Convert the specified locale-sensitive value into a String
using the paticular convertion pattern.
|
String | convert(Object value, String pattern) - Convert the specified locale-sensitive value into a String
using the convertion pattern.
|
Object | convert(String value, Class clazz) - Convert the specified value to an object of the specified class (if
possible).
|
Object | convert(String value, Class clazz, Locale locale, String pattern) - Convert the specified value to an object of the specified class (if
possible) using the convertion pattern.
|
Object | convert(String value, Class clazz, String pattern) - Convert the specified value to an object of the specified class (if
possible) using the convertion pattern.
|
Object | convert(values[] , Class clazz) - Convert an array of specified values to an array of objects of the
specified class (if possible) .
|
Object | convert(values[] , Class clazz, Locale locale, String pattern) - Convert an array of specified values to an array of objects of the
specified class (if possible) using the convertion pattern.
|
Object | convert(values[] , Class clazz, String pattern) - Convert an array of specified values to an array of objects of the
specified class (if possible) using the convertion pattern.
|
protected FastHashMap | create(Locale locale) - Create all
LocaleConverter types for specified locale.
|
void | deregister() - Remove any registered
LocaleConverter .
|
void | deregister(Class clazz, Locale locale) - Remove any registered
LocaleConverter for the specified locale and Class.
|
void | deregister(Locale locale) - Remove any registered
LocaleConverter for the specified locale
|
boolean | getApplyLocalized() - getter for applyLocalized
|
Locale | getDefaultLocale() - getter for defaultLocale
|
static LocaleConvertUtilsBean | getInstance() - Gets singleton instance.
|
LocaleConverter | lookup(Class clazz, Locale locale) - Look up and return any registered
LocaleConverter for the specified
destination class and locale; if there is no registered Converter, return
null .
|
protected FastHashMap | lookup(Locale locale) - Look up and return any registered FastHashMap instance for the specified locale;
if there is no registered one, return
null .
|
void | register(LocaleConverter converter, Class clazz, Locale locale) - Register a custom
LocaleConverter for the specified destination
Class , replacing any previously registered converter.
|
void | setApplyLocalized(boolean newApplyLocalized) - setter for applyLocalized
|
void | setDefaultLocale(Locale locale) - setter for defaultLocale
|
applyLocalized
private boolean applyLocalized
Indicate whether the pattern is localized or not
defaultLocale
private Locale defaultLocale
The locale - default for convertion.
log
private Log log
The Log
instance for this class.
mapConverters
private FastHashMap mapConverters
Every entry of the mapConverters is:
key = locale
value = FastHashMap of converters for the certain locale.
LocaleConvertUtilsBean
public LocaleConvertUtilsBean()
Makes the state by default (deregisters all converters for all locales)
and then registers default locale converters.
convert
public String convert(Object value)
Convert the specified locale-sensitive value into a String.
value
- The Value to be converted
convert
public String convert(Object value,
Locale locale,
String pattern)
Convert the specified locale-sensitive value into a String
using the paticular convertion pattern.
value
- The Value to be convertedlocale
- The localepattern
- The convertion pattern
convert
public String convert(Object value,
String pattern)
Convert the specified locale-sensitive value into a String
using the convertion pattern.
value
- The Value to be convertedpattern
- The convertion pattern
convert
public Object convert(String value,
Class clazz)
Convert the specified value to an object of the specified class (if
possible). Otherwise, return a String representation of the value.
value
- The String scalar value to be convertedclazz
- The Data type to which this value should be converted.
convert
public Object convert(String value,
Class clazz,
Locale locale,
String pattern)
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.
value
- The String scalar value to be convertedclazz
- The Data type to which this value should be converted.locale
- The localepattern
- The convertion pattern
convert
public Object convert(String value,
Class clazz,
String pattern)
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.
value
- The String scalar value to be convertedclazz
- The Data type to which this value should be converted.pattern
- The convertion pattern
convert
public Object convert(values[] ,
Class clazz)
Convert an array of specified values to an array of objects of the
specified class (if possible) .
clazz
- Java array or element class to be converted to
convert
public Object convert(values[] ,
Class clazz,
Locale locale,
String pattern)
Convert an array of specified values to an array of objects of the
specified class (if possible) using the convertion pattern.
clazz
- Java array or element class to be converted tolocale
- The localepattern
- The convertion pattern
convert
public Object convert(values[] ,
Class clazz,
String pattern)
Convert an array of specified values to an array of objects of the
specified class (if possible) using the convertion pattern.
clazz
- Java array or element class to be converted topattern
- The convertion pattern
create
protected FastHashMap create(Locale locale)
- The FastHashMap instance contains the all
LocaleConverter
types
for the specified locale.
deregister
public void deregister()
deregister
public void deregister(Class clazz,
Locale locale)
clazz
- Class for which to remove a registered Converterlocale
- The locale
deregister
public void deregister(Locale locale)
getApplyLocalized
public boolean getApplyLocalized()
getter for applyLocalized
getDefaultLocale
public Locale getDefaultLocale()
getter for defaultLocale
lookup
public LocaleConverter lookup(Class clazz,
Locale locale)
Look up and return any registered
LocaleConverter
for the specified
destination class and locale; if there is no registered Converter, return
null
.
clazz
- Class for which to return a registered Converterlocale
- The Locale
lookup
protected FastHashMap lookup(Locale locale)
Look up and return any registered FastHashMap instance for the specified locale;
if there is no registered one, return null
.
- The FastHashMap instance contains the all
LocaleConverter
types for
the specified locale.
register
public void register(LocaleConverter converter,
Class clazz,
Locale locale)
Register a custom
LocaleConverter
for the specified destination
Class
, replacing any previously registered converter.
converter
- The LocaleConverter to be registeredclazz
- The Destination class for conversions performed by this
Converterlocale
- The locale
setApplyLocalized
public void setApplyLocalized(boolean newApplyLocalized)
setter for applyLocalized
setDefaultLocale
public void setDefaultLocale(Locale locale)
setter for defaultLocale
Copyright (c) 2001-2004 - Apache Software Foundation