org.apache.commons.beanutils.locale

Class LocaleConvertUtilsBean

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 {@link LocaleConvertUtils}.

The actual {@link LocaleConverter} instance to be used can be registered for each possible destination Class. Unless you override them, standard {@link 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 {@link LocaleConverter} thrown instead, replace the standard {@link LocaleConverter} instances with ones created with the one of the appropriate constructors. It's important that {@link LocaleConverter} should be registered for the specified locale and Class (or primitive type).

Since: 1.7

Author: Yauheny Mikulski

Field Summary
booleanapplyLocalized
Indicate whether the pattern is localized or not
LocaledefaultLocale
The locale - default for convertion.
Loglog
The Log instance for this class.
FastHashMapmapConverters
Every entry of the mapConverters is: key = locale value = FastHashMap of converters for the certain locale.
Constructor Summary
LocaleConvertUtilsBean()
Makes the state by default (deregisters all converters for all locales) and then registers default locale converters.
Method Summary
Stringconvert(Object value)
Convert the specified locale-sensitive value into a String.
Stringconvert(Object value, String pattern)
Convert the specified locale-sensitive value into a String using the convertion pattern.
Stringconvert(Object value, Locale locale, String pattern)
Convert the specified locale-sensitive value into a String using the paticular convertion pattern.
Objectconvert(String value, Class clazz)
Convert the specified value to an object of the specified class (if possible).
Objectconvert(String value, Class clazz, String pattern)
Convert the specified value to an object of the specified class (if possible) using the convertion pattern.
Objectconvert(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.
Objectconvert(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.
Objectconvert(String[] values, Class clazz)
Convert an array of specified values to an array of objects of the specified class (if possible) .
Objectconvert(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.
protected FastHashMapcreate(Locale locale)
Create all {@link LocaleConverter} types for specified locale.
voidderegister()
Remove any registered {@link LocaleConverter}.
voidderegister(Locale locale)
Remove any registered {@link LocaleConverter} for the specified locale
voidderegister(Class clazz, Locale locale)
Remove any registered {@link LocaleConverter} for the specified locale and Class.
booleangetApplyLocalized()
getter for applyLocalized
LocalegetDefaultLocale()
getter for defaultLocale
static LocaleConvertUtilsBeangetInstance()
Gets singleton instance.
LocaleConverterlookup(Class clazz, Locale locale)
Look up and return any registered {@link LocaleConverter} for the specified destination class and locale; if there is no registered Converter, return null.
protected FastHashMaplookup(Locale locale)
Look up and return any registered FastHashMap instance for the specified locale; if there is no registered one, return null.
voidregister(LocaleConverter converter, Class clazz, Locale locale)
Register a custom {@link LocaleConverter} for the specified destination Class, replacing any previously registered converter.
voidsetApplyLocalized(boolean newApplyLocalized)
setter for applyLocalized
voidsetDefaultLocale(Locale locale)
setter for defaultLocale

Field Detail

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.

Constructor Detail

LocaleConvertUtilsBean

public LocaleConvertUtilsBean()
Makes the state by default (deregisters all converters for all locales) and then registers default locale converters.

Method Detail

convert

public String convert(Object value)
Convert the specified locale-sensitive value into a String.

Parameters: value The Value to be converted

Throws: org.apache.commons.beanutils.ConversionException if thrown by an underlying Converter

convert

public String convert(Object value, String pattern)
Convert the specified locale-sensitive value into a String using the convertion pattern.

Parameters: value The Value to be converted pattern The convertion pattern

Throws: ConversionException if thrown by an underlying Converter

convert

public String convert(Object value, Locale locale, String pattern)
Convert the specified locale-sensitive value into a String using the paticular convertion pattern.

Parameters: value The Value to be converted locale The locale pattern The convertion pattern

Throws: ConversionException if thrown by an underlying Converter

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.

Parameters: value The String scalar value to be converted clazz The Data type to which this value should be converted.

Throws: ConversionException if thrown by an underlying Converter

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.

Parameters: value The String scalar value to be converted clazz The Data type to which this value should be converted. pattern The convertion pattern

Throws: ConversionException if thrown by an underlying Converter

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.

Parameters: value The String scalar value to be converted clazz The Data type to which this value should be converted. locale The locale pattern The convertion pattern

Throws: ConversionException if thrown by an underlying Converter

convert

public 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.

Parameters: values Value to be converted (may be null) clazz Java array or element class to be converted to pattern The convertion pattern

Throws: ConversionException if thrown by an underlying Converter

convert

public Object convert(String[] values, Class clazz)
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

Throws: ConversionException if thrown by an underlying Converter

convert

public 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.

Parameters: values Value to be converted (may be null) clazz Java array or element class to be converted to locale The locale pattern The convertion pattern

Throws: ConversionException if thrown by an underlying Converter

create

protected FastHashMap create(Locale locale)
Create all {@link LocaleConverter} types for specified locale.

Parameters: locale The Locale

Returns: The FastHashMap instance contains the all {@link LocaleConverter} types for the specified locale.

deregister

public void deregister()
Remove any registered {@link LocaleConverter}.

deregister

public void deregister(Locale locale)
Remove any registered {@link LocaleConverter} for the specified locale

Parameters: locale The locale

deregister

public void deregister(Class clazz, Locale locale)
Remove any registered {@link LocaleConverter} for the specified locale and Class.

Parameters: clazz Class for which to remove a registered Converter locale The locale

getApplyLocalized

public boolean getApplyLocalized()
getter for applyLocalized

getDefaultLocale

public Locale getDefaultLocale()
getter for defaultLocale

getInstance

public static LocaleConvertUtilsBean getInstance()
Gets singleton instance. This is the same as the instance used by the default {@link LocaleBeanUtilsBean} singleton.

lookup

public LocaleConverter lookup(Class clazz, Locale locale)
Look up and return any registered {@link LocaleConverter} for the specified destination class and locale; if there is no registered Converter, return null.

Parameters: clazz Class for which to return a registered Converter locale 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.

Parameters: locale The Locale

Returns: The FastHashMap instance contains the all {@link LocaleConverter} types for the specified locale.

register

public void register(LocaleConverter converter, Class clazz, Locale locale)
Register a custom {@link LocaleConverter} for the specified destination Class, replacing any previously registered converter.

Parameters: converter The LocaleConverter to be registered clazz The Destination class for conversions performed by this Converter locale 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