org.apache.commons.beanutils.locale

Class LocaleBeanUtilsBean

public class LocaleBeanUtilsBean extends BeanUtilsBean

Utility methods for populating JavaBeans properties via reflection in a locale-dependent manner.

Since: 1.7

Author: Craig R. McClanahan Ralph Schaer Chris Audley Rey François Gregor Raýman Yauheny Mikulski

Nested Class Summary
protected classLocaleBeanUtilsBean.Descriptor
Field Summary
static ContextClassLoaderLocallocaleBeansByClassLoader
Contains LocaleBeanUtilsBean instances indexed by context classloader.
LocaleConvertUtilsBeanlocaleConvertUtils
Convertor used by this class
static Loglog
All logging goes through this logger
Constructor Summary
LocaleBeanUtilsBean()
Construct instance with standard conversion bean
LocaleBeanUtilsBean(LocaleConvertUtilsBean localeConvertUtils, ConvertUtilsBean convertUtilsBean, PropertyUtilsBean propertyUtilsBean)
Construct instance that uses given locale conversion
LocaleBeanUtilsBean(LocaleConvertUtilsBean localeConvertUtils)
Construct instance that uses given locale conversion
Method Summary
protected LocaleBeanUtilsBean.Descriptorcalculate(Object bean, String name)
Resolve any nested expression to get the actual target bean.
protected Objectconvert(Class type, int index, Object value, String pattern)
Convert the specified value to the required type using the specified convertion pattern.
protected Objectconvert(Class type, int index, Object value)
Convert the specified value to the required type.
protected ClassdefinePropertyType(Object target, String name, String propName)
Calculate the property type.
booleangetApplyLocalized()
Is the pattern to be applied localized (Indicate whether the pattern is localized or not)
LocalegetDefaultLocale()
Gets the default Locale
StringgetIndexedProperty(Object bean, String name, String pattern)
Return the value of the specified locale-sensitive indexed property of the specified bean, as a String.
StringgetIndexedProperty(Object bean, String name)
Return the value of the specified locale-sensitive indexed property of the specified bean, as a String using the default convertion pattern of the corresponding {@link LocaleConverter}.
StringgetIndexedProperty(Object bean, String name, int index, String pattern)
Return the value of the specified locale-sensetive indexed property of the specified bean, as a String using the specified convertion pattern.
StringgetIndexedProperty(Object bean, String name, int index)
Return the value of the specified locale-sensetive indexed property of the specified bean, as a String using the default convertion pattern of the corresponding {@link LocaleConverter}.
static LocaleBeanUtilsBeangetLocaleBeanUtilsInstance()
Gets singleton instance
LocaleConvertUtilsBeangetLocaleConvertUtils()
Gets the bean instance used for conversions
StringgetMappedProperty(Object bean, String name, String key, String pattern)
Return the value of the specified mapped locale-sensitive property of the specified bean, as a String using the specified convertion pattern.
StringgetMappedProperty(Object bean, String name, String key)
Return the value of the specified mapped locale-sensitive property of the specified bean, as a String The key is specified as a method parameter and must *not* be included in the property name expression
StringgetMappedProperty(Object bean, String name)
Return the value of the specified locale-sensitive mapped property of the specified bean, as a String using the default convertion pattern of the corresponding {@link LocaleConverter}.
StringgetMappedPropertyLocale(Object bean, String name, String pattern)
Return the value of the specified locale-sensitive mapped property of the specified bean, as a String using the specified pattern.
StringgetNestedProperty(Object bean, String name, String pattern)
Return the value of the (possibly nested) locale-sensitive property of the specified name, for the specified bean, as a String using the specified pattern.
StringgetNestedProperty(Object bean, String name)
Return the value of the (possibly nested) locale-sensitive property of the specified name, for the specified bean, as a String using the default convertion pattern of the corresponding {@link LocaleConverter}.
StringgetProperty(Object bean, String name, String pattern)
Return the value of the specified locale-sensitive property of the specified bean, no matter which property reference format is used, as a String using the specified convertion pattern.
StringgetProperty(Object bean, String name)
Return the value of the specified locale-sensitive property of the specified bean, no matter which property reference format is used, as a String using the default convertion pattern of the corresponding {@link LocaleConverter}.
StringgetSimpleProperty(Object bean, String name, String pattern)
Return the value of the specified simple locale-sensitive property of the specified bean, converted to a String using the specified convertion pattern.
StringgetSimpleProperty(Object bean, String name)
Return the value of the specified simple locale-sensitive property of the specified bean, converted to a String using the default convertion pattern of the corresponding {@link LocaleConverter}.
protected voidinvokeSetter(Object target, String propName, String key, int index, Object newValue)
Invoke the setter method.
voidsetApplyLocalized(boolean newApplyLocalized)
Sets whether the pattern is applied localized (Indicate whether the pattern is localized or not)
voidsetDefaultLocale(Locale locale)
Sets the default Locale
static voidsetInstance(LocaleBeanUtilsBean newInstance)
Sets the instance which provides the functionality for {@link LocaleBeanUtils}.
voidsetProperty(Object bean, String name, Object value)
Set the specified locale-sensitive property value, performing type conversions as required to conform to the type of the destination property using the default convertion pattern of the corresponding {@link LocaleConverter}.
voidsetProperty(Object bean, String name, Object value, String pattern)
Set the specified locale-sensitive property value, performing type conversions as required to conform to the type of the destination property using the specified convertion pattern.

Field Detail

localeBeansByClassLoader

private static final ContextClassLoaderLocal localeBeansByClassLoader
Contains LocaleBeanUtilsBean instances indexed by context classloader.

localeConvertUtils

private LocaleConvertUtilsBean localeConvertUtils
Convertor used by this class

log

private static Log log
All logging goes through this logger

Constructor Detail

LocaleBeanUtilsBean

public LocaleBeanUtilsBean()
Construct instance with standard conversion bean

LocaleBeanUtilsBean

public LocaleBeanUtilsBean(LocaleConvertUtilsBean localeConvertUtils, ConvertUtilsBean convertUtilsBean, PropertyUtilsBean propertyUtilsBean)
Construct instance that uses given locale conversion

Parameters: localeConvertUtils use this localeConvertUtils to perform conversions convertUtilsBean use this for standard conversions propertyUtilsBean use this for property conversions

LocaleBeanUtilsBean

public LocaleBeanUtilsBean(LocaleConvertUtilsBean localeConvertUtils)
Construct instance that uses given locale conversion

Parameters: localeConvertUtils use this localeConvertUtils to perform conversions

Method Detail

calculate

protected LocaleBeanUtilsBean.Descriptor calculate(Object bean, String name)
Resolve any nested expression to get the actual target bean.

Parameters: bean The bean name The property name

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception

convert

protected Object convert(Class type, int index, Object value, String pattern)
Convert the specified value to the required type using the specified convertion pattern.

Parameters: type The Java type of target property index The indexed subscript value (if any) value The value to be converted pattern The convertion pattern

convert

protected Object convert(Class type, int index, Object value)
Convert the specified value to the required type.

Parameters: type The Java type of target property index The indexed subscript value (if any) value The value to be converted

definePropertyType

protected Class definePropertyType(Object target, String name, String propName)
Calculate the property type.

Parameters: target The bean name The property name propName The Simple name of target property

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception

getApplyLocalized

public boolean getApplyLocalized()
Is the pattern to be applied localized (Indicate whether the pattern is localized or not)

getDefaultLocale

public Locale getDefaultLocale()
Gets the default Locale

getIndexedProperty

public String getIndexedProperty(Object bean, String name, String pattern)
Return the value of the specified locale-sensitive indexed property of the specified bean, as a String. The zero-relative index of the required value must be included (in square brackets) as a suffix to the property name, or IllegalArgumentException will be thrown.

Parameters: bean Bean whose property is to be extracted name propertyname[index] of the property value to be extracted pattern The convertion pattern

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getIndexedProperty

public String getIndexedProperty(Object bean, String name)
Return the value of the specified locale-sensitive indexed property of the specified bean, as a String using the default convertion pattern of the corresponding {@link LocaleConverter}. The zero-relative index of the required value must be included (in square brackets) as a suffix to the property name, or IllegalArgumentException will be thrown.

Parameters: bean Bean whose property is to be extracted name propertyname[index] of the property value to be extracted

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getIndexedProperty

public String getIndexedProperty(Object bean, String name, int index, String pattern)
Return the value of the specified locale-sensetive indexed property of the specified bean, as a String using the specified convertion pattern. The index is specified as a method parameter and must *not* be included in the property name expression

Parameters: bean Bean whose property is to be extracted name Simple property name of the property value to be extracted index Index of the property value to be extracted pattern The convertion pattern

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getIndexedProperty

public String getIndexedProperty(Object bean, String name, int index)
Return the value of the specified locale-sensetive indexed property of the specified bean, as a String using the default convertion pattern of the corresponding {@link LocaleConverter}. The index is specified as a method parameter and must *not* be included in the property name expression

Parameters: bean Bean whose property is to be extracted name Simple property name of the property value to be extracted index Index of the property value to be extracted

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getLocaleBeanUtilsInstance

public static LocaleBeanUtilsBean getLocaleBeanUtilsInstance()
Gets singleton instance

getLocaleConvertUtils

public LocaleConvertUtilsBean getLocaleConvertUtils()
Gets the bean instance used for conversions

getMappedProperty

public String getMappedProperty(Object bean, String name, String key, String pattern)
Return the value of the specified mapped locale-sensitive property of the specified bean, as a String using the specified convertion pattern. The key is specified as a method parameter and must *not* be included in the property name expression.

Parameters: bean Bean whose property is to be extracted name Simple property name of the property value to be extracted key Lookup key of the property value to be extracted pattern The convertion pattern

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getMappedProperty

public String getMappedProperty(Object bean, String name, String key)
Return the value of the specified mapped locale-sensitive property of the specified bean, as a String The key is specified as a method parameter and must *not* be included in the property name expression

Parameters: bean Bean whose property is to be extracted name Simple property name of the property value to be extracted key Lookup key of the property value to be extracted

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getMappedProperty

public String getMappedProperty(Object bean, String name)
Return the value of the specified locale-sensitive mapped property of the specified bean, as a String using the default convertion pattern of the corresponding {@link LocaleConverter}. The String-valued key of the required value must be included (in parentheses) as a suffix to the property name, or IllegalArgumentException will be thrown.

Parameters: bean Bean whose property is to be extracted name propertyname(index) of the property value to be extracted

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getMappedPropertyLocale

public String getMappedPropertyLocale(Object bean, String name, String pattern)
Return the value of the specified locale-sensitive mapped property of the specified bean, as a String using the specified pattern. The String-valued key of the required value must be included (in parentheses) as a suffix to the property name, or IllegalArgumentException will be thrown.

Parameters: bean Bean whose property is to be extracted name propertyname(index) of the property value to be extracted pattern The convertion pattern

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getNestedProperty

public String getNestedProperty(Object bean, String name, String pattern)
Return the value of the (possibly nested) locale-sensitive property of the specified name, for the specified bean, as a String using the specified pattern.

Parameters: bean Bean whose property is to be extracted name Possibly nested name of the property to be extracted pattern The convertion pattern

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if a nested reference to a property returns null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getNestedProperty

public String getNestedProperty(Object bean, String name)
Return the value of the (possibly nested) locale-sensitive property of the specified name, for the specified bean, as a String using the default convertion pattern of the corresponding {@link LocaleConverter}.

Parameters: bean Bean whose property is to be extracted name Possibly nested name of the property to be extracted

Throws: IllegalAccessException if the caller does not have access to the property accessor method IllegalArgumentException if a nested reference to a property returns null InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getProperty

public String getProperty(Object bean, String name, String pattern)
Return the value of the specified locale-sensitive property of the specified bean, no matter which property reference format is used, as a String using the specified convertion pattern.

Parameters: bean Bean whose property is to be extracted name Possibly indexed and/or nested name of the property to be extracted pattern The convertion pattern

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getProperty

public String getProperty(Object bean, String name)
Return the value of the specified locale-sensitive property of the specified bean, no matter which property reference format is used, as a String using the default convertion pattern of the corresponding {@link LocaleConverter}.

Parameters: bean Bean whose property is to be extracted name Possibly indexed and/or nested name of the property to be extracted

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getSimpleProperty

public String getSimpleProperty(Object bean, String name, String pattern)
Return the value of the specified simple locale-sensitive property of the specified bean, converted to a String using the specified convertion pattern.

Parameters: bean Bean whose property is to be extracted name Name of the property to be extracted pattern The convertion pattern

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

getSimpleProperty

public String getSimpleProperty(Object bean, String name)
Return the value of the specified simple locale-sensitive property of the specified bean, converted to a String using the default convertion pattern of the corresponding {@link LocaleConverter}.

Parameters: bean Bean whose property is to be extracted name Name of the property to be extracted

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception NoSuchMethodException if an accessor method for this propety cannot be found

invokeSetter

protected void invokeSetter(Object target, String propName, String key, int index, Object newValue)
Invoke the setter method.

Parameters: target The bean propName The Simple name of target property key The Mapped key value (if any) index The indexed subscript value (if any) newValue The value to be set

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception

setApplyLocalized

public void setApplyLocalized(boolean newApplyLocalized)
Sets whether the pattern is applied localized (Indicate whether the pattern is localized or not)

setDefaultLocale

public void setDefaultLocale(Locale locale)
Sets the default Locale

setInstance

public static void setInstance(LocaleBeanUtilsBean newInstance)
Sets the instance which provides the functionality for {@link LocaleBeanUtils}. This is a pseudo-singleton - an single instance is provided per (thread) context classloader. This mechanism provides isolation for web apps deployed in the same container.

setProperty

public void setProperty(Object bean, String name, Object value)
Set the specified locale-sensitive property value, performing type conversions as required to conform to the type of the destination property using the default convertion pattern of the corresponding {@link LocaleConverter}.

Parameters: bean Bean on which setting is to be performed name Property name (can be nested/indexed/mapped/combo) value Value to be set

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception

setProperty

public void setProperty(Object bean, String name, Object value, String pattern)
Set the specified locale-sensitive property value, performing type conversions as required to conform to the type of the destination property using the specified convertion pattern.

Parameters: bean Bean on which setting is to be performed name Property name (can be nested/indexed/mapped/combo) value Value to be set pattern The convertion pattern

Throws: IllegalAccessException if the caller does not have access to the property accessor method InvocationTargetException if the property accessor method throws an exception

Copyright (c) 2001-2004 - Apache Software Foundation