public class LocaleConvertUtilsBean extends 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:
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).
Constructor and Description |
---|
LocaleConvertUtilsBean()
Makes the state by default (deregisters all converters for all locales)
and then registers default locale converters.
|
Modifier and Type | Method and Description |
---|---|
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 conversion pattern.
|
Object |
convert(String[] values,
Class<?> clazz)
Convert an array of specified values to an array of objects of the
specified class (if possible) .
|
Object |
convert(String[] 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(String[] 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.
|
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.
|
protected org.apache.commons.collections.FastHashMap |
create(Locale locale)
Deprecated.
This method will be modified to return a Map in the next release.
|
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 org.apache.commons.collections.FastHashMap |
lookup(Locale locale)
Deprecated.
This method will be modified to return a Map in the next release.
|
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.
|
public LocaleConvertUtilsBean()
public static LocaleConvertUtilsBean getInstance()
LocaleBeanUtilsBean
singleton.public Locale getDefaultLocale()
public void setDefaultLocale(Locale locale)
locale
- the default localepublic boolean getApplyLocalized()
true
if pattern is localized,
otherwise false
public void setApplyLocalized(boolean newApplyLocalized)
newApplyLocalized
- true
if pattern is localized,
otherwise false
public String convert(Object value)
value
- The Value to be convertedConversionException
- if thrown by an
underlying Converterpublic String convert(Object value, String pattern)
value
- The Value to be convertedpattern
- The convertion patternConversionException
- if thrown by an
underlying Converterpublic String convert(Object value, Locale locale, String pattern)
value
- The Value to be convertedlocale
- The localepattern
- The convertion patternConversionException
- if thrown by an
underlying Converterpublic Object convert(String value, Class<?> clazz)
value
- The String scalar value to be convertedclazz
- The Data type to which this value should be converted.ConversionException
- if thrown by an
underlying Converterpublic Object convert(String value, Class<?> clazz, String pattern)
value
- The String scalar value to be convertedclazz
- The Data type to which this value should be converted.pattern
- The convertion patternConversionException
- if thrown by an
underlying Converterpublic Object convert(String value, Class<?> clazz, Locale locale, String pattern)
value
- The String scalar value to be convertedclazz
- The Data type to which this value should be converted.locale
- The localepattern
- The convertion patternConversionException
- if thrown by an
underlying Converterpublic Object convert(String[] values, Class<?> clazz, String pattern)
values
- Value to be converted (may be null)clazz
- Java array or element class to be converted topattern
- The convertion patternConversionException
- if thrown by an
underlying Converterpublic Object convert(String[] values, Class<?> clazz)
values
- Value to be converted (may be null)clazz
- Java array or element class to be converted toConversionException
- if thrown by an
underlying Converterpublic Object convert(String[] values, Class<?> clazz, Locale locale, String pattern)
values
- Value to be converted (may be null)clazz
- Java array or element class to be converted tolocale
- The localepattern
- The convertion patternConversionException
- if thrown by an
underlying Converterpublic void register(LocaleConverter converter, Class<?> clazz, Locale locale)
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 localepublic void deregister()
LocaleConverter
.public void deregister(Locale locale)
LocaleConverter
for the specified localelocale
- The localepublic void deregister(Class<?> clazz, Locale locale)
LocaleConverter
for the specified locale and Class.clazz
- Class for which to remove a registered Converterlocale
- The localepublic LocaleConverter lookup(Class<?> clazz, Locale locale)
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@Deprecated protected org.apache.commons.collections.FastHashMap lookup(Locale locale)
null
.locale
- The LocaleLocaleConverter
types for
the specified locale.@Deprecated protected org.apache.commons.collections.FastHashMap create(Locale locale)
LocaleConverter
types for specified locale.locale
- The LocaleLocaleConverter
types
for the specified locale.Copyright © 2000–2019 The Apache Software Foundation. All rights reserved.