Class LocaleBeanUtilsBean
java.lang.Object
org.apache.commons.beanutils2.BeanUtilsBean
org.apache.commons.beanutils2.locale.LocaleBeanUtilsBean
Utility methods for populating JavaBeans properties via reflection in a locale-dependent manner.
- Since:
- 1.7
-
Constructor Summary
ConstructorDescriptionConstructs instance with standard conversion beanLocaleBeanUtilsBean
(LocaleConvertUtilsBean localeConvertUtils) Constructs instance that uses given locale conversionLocaleBeanUtilsBean
(LocaleConvertUtilsBean localeConvertUtils, ConvertUtilsBean convertUtilsBean, PropertyUtilsBean propertyUtilsBean) Constructs instance that uses given locale conversion -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
Convert the specified value to the required type.protected Object
Convert the specified value to the required type using the specified conversion pattern.protected Class<?>
definePropertyType
(Object target, String name, String propName) Calculate the property type.boolean
Is the pattern to be applied localized (Indicate whether the pattern is localized or not)Gets the default LocalegetIndexedProperty
(Object bean, String name) Gets the value of the specified locale-sensitive indexed property of the specified bean, as a String using the default conversion pattern of the correspondingLocaleConverter
.getIndexedProperty
(Object bean, String name, int index) Gets the value of the specified locale-sensetive indexed property of the specified bean, as a String using the default conversion pattern of the correspondingLocaleConverter
.getIndexedProperty
(Object bean, String name, int index, String pattern) Gets the value of the specified locale-sensetive indexed property of the specified bean, as a String using the specified conversion pattern.getIndexedProperty
(Object bean, String name, String pattern) Gets the value of the specified locale-sensitive indexed property of the specified bean, as a String.static LocaleBeanUtilsBean
Gets singleton instanceGets the bean instance used for conversionsgetMappedProperty
(Object bean, String name) Gets the value of the specified locale-sensitive mapped property of the specified bean, as a String using the default conversion pattern of the correspondingLocaleConverter
.getMappedProperty
(Object bean, String name, String key) Gets 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 expressiongetMappedProperty
(Object bean, String name, String key, String pattern) Gets the value of the specified mapped locale-sensitive property of the specified bean, as a String using the specified conversion pattern.getMappedPropertyLocale
(Object bean, String name, String pattern) Gets the value of the specified locale-sensitive mapped property of the specified bean, as a String using the specified pattern.getNestedProperty
(Object bean, String name) Gets the value of the (possibly nested) locale-sensitive property of the specified name, for the specified bean, as a String using the default conversion pattern of the correspondingLocaleConverter
.getNestedProperty
(Object bean, String name, String pattern) Gets the value of the (possibly nested) locale-sensitive property of the specified name, for the specified bean, as a String using the specified pattern.getProperty
(Object bean, String name) Gets 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 conversion pattern of the correspondingLocaleConverter
.getProperty
(Object bean, String name, String pattern) Gets 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 conversion pattern.getSimpleProperty
(Object bean, String name) Gets the value of the specified simple locale-sensitive property of the specified bean, converted to a String using the default conversion pattern of the correspondingLocaleConverter
.getSimpleProperty
(Object bean, String name, String pattern) Gets the value of the specified simple locale-sensitive property of the specified bean, converted to a String using the specified conversion pattern.protected void
invokeSetter
(Object target, String propName, String key, int index, Object newValue) Invoke the setter method.void
setApplyLocalized
(boolean newApplyLocalized) Sets whether the pattern is applied localized (Indicate whether the pattern is localized or not)void
setDefaultLocale
(Locale locale) Sets the default Locale.static void
setInstance
(LocaleBeanUtilsBean newInstance) Sets the instance which provides the functionality forLocaleBeanUtils
.void
setProperty
(Object bean, String name, Object value) Sets the specified locale-sensitive property value, performing type conversions as required to conform to the type of the destination property using the default conversion pattern of the correspondingLocaleConverter
.void
setProperty
(Object bean, String name, Object value, String pattern) Sets the specified locale-sensitive property value, performing type conversions as required to conform to the type of the destination property using the specified conversion pattern.Methods inherited from class org.apache.commons.beanutils2.BeanUtilsBean
cloneBean, convert, copyProperties, copyProperty, describe, getArrayProperty, getConvertUtils, getInstance, getPropertyUtils, populate, setInstance
-
Constructor Details
-
LocaleBeanUtilsBean
public LocaleBeanUtilsBean()Constructs instance with standard conversion bean -
LocaleBeanUtilsBean
Constructs instance that uses given locale conversion- Parameters:
localeConvertUtils
- use thislocaleConvertUtils
to perform conversions
-
LocaleBeanUtilsBean
public LocaleBeanUtilsBean(LocaleConvertUtilsBean localeConvertUtils, ConvertUtilsBean convertUtilsBean, PropertyUtilsBean propertyUtilsBean) Constructs instance that uses given locale conversion- Parameters:
localeConvertUtils
- use thislocaleConvertUtils
to perform conversionsconvertUtilsBean
- use this for standard conversionspropertyUtilsBean
- use this for property conversions
-
-
Method Details
-
getLocaleBeanUtilsInstance
Gets singleton instance- Returns:
- the singleton instance
-
setInstance
Sets the instance which provides the functionality forLocaleBeanUtils
. 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.- Parameters:
newInstance
- a new singleton instance
-
convert
Convert the specified value to the required type.- Parameters:
type
- The Java type of target propertyindex
- The indexed subscript value (if any)value
- The value to be converted- Returns:
- The converted value
-
convert
Convert the specified value to the required type using the specified conversion pattern.- Parameters:
type
- The Java type of target propertyindex
- The indexed subscript value (if any)value
- The value to be convertedpattern
- The conversion pattern- Returns:
- The converted value
-
definePropertyType
protected Class<?> definePropertyType(Object target, String name, String propName) throws IllegalAccessException, InvocationTargetException Calculate the property type.- Parameters:
target
- The beanname
- The property namepropName
- The Simple name of target property- Returns:
- The property's type
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exception
-
getApplyLocalized
Is the pattern to be applied localized (Indicate whether the pattern is localized or not)- Returns:
true
if pattern is localized, otherwisefalse
-
getDefaultLocale
Gets the default Locale- Returns:
- the default locale
-
getIndexedProperty
public String getIndexedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets the value of the specified locale-sensitive indexed property of the specified bean, as a String using the default conversion pattern of the correspondingLocaleConverter
. The zero-relative index of the required value must be included (in square brackets) as a suffix to the property name, orIllegalArgumentException
will be thrown.- Overrides:
getIndexedProperty
in classBeanUtilsBean
- Parameters:
bean
- Bean whose property is to be extractedname
-propertyname[index]
of the property value to be extracted- Returns:
- The indexed property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getIndexedProperty
public String getIndexedProperty(Object bean, String name, int index) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets the value of the specified locale-sensetive indexed property of the specified bean, as a String using the default conversion pattern of the correspondingLocaleConverter
. The index is specified as a method parameter and must *not* be included in the property name expression- Overrides:
getIndexedProperty
in classBeanUtilsBean
- Parameters:
bean
- Bean whose property is to be extractedname
- Simple property name of the property value to be extractedindex
- Index of the property value to be extracted- Returns:
- The indexed property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getIndexedProperty
public String getIndexedProperty(Object bean, String name, int index, String pattern) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets the value of the specified locale-sensetive indexed property of the specified bean, as a String using the specified conversion 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 extractedname
- Simple property name of the property value to be extractedindex
- Index of the property value to be extractedpattern
- The conversion pattern- Returns:
- The indexed property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getIndexedProperty
public String getIndexedProperty(Object bean, String name, String pattern) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets 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, orIllegalArgumentException
will be thrown.- Parameters:
bean
- Bean whose property is to be extractedname
-propertyname[index]
of the property value to be extractedpattern
- The conversion pattern- Returns:
- The indexed property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getLocaleConvertUtils
Gets the bean instance used for conversions- Returns:
- the locale converter bean instance
-
getMappedProperty
public String getMappedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets the value of the specified locale-sensitive mapped property of the specified bean, as a String using the default conversion pattern of the correspondingLocaleConverter
. The String-valued key of the required value must be included (in parentheses) as a suffix to the property name, orIllegalArgumentException
will be thrown.- Overrides:
getMappedProperty
in classBeanUtilsBean
- Parameters:
bean
- Bean whose property is to be extractedname
-propertyname(index)
of the property value to be extracted- Returns:
- The mapped property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getMappedProperty
public String getMappedProperty(Object bean, String name, String key) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets 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- Overrides:
getMappedProperty
in classBeanUtilsBean
- Parameters:
bean
- Bean whose property is to be extractedname
- Simple property name of the property value to be extractedkey
- Lookup key of the property value to be extracted- Returns:
- The mapped property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getMappedProperty
public String getMappedProperty(Object bean, String name, String key, String pattern) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets the value of the specified mapped locale-sensitive property of the specified bean, as a String using the specified conversion 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 extractedname
- Simple property name of the property value to be extractedkey
- Lookup key of the property value to be extractedpattern
- The conversion pattern- Returns:
- The mapped property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getMappedPropertyLocale
public String getMappedPropertyLocale(Object bean, String name, String pattern) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets 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, orIllegalArgumentException
will be thrown.- Parameters:
bean
- Bean whose property is to be extractedname
-propertyname(index)
of the property value to be extractedpattern
- The conversion pattern- Returns:
- The mapped property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getNestedProperty
public String getNestedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets the value of the (possibly nested) locale-sensitive property of the specified name, for the specified bean, as a String using the default conversion pattern of the correspondingLocaleConverter
.- Overrides:
getNestedProperty
in classBeanUtilsBean
- Parameters:
bean
- Bean whose property is to be extractedname
- Possibly nested name of the property to be extracted- Returns:
- The nested property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodIllegalArgumentException
- if a nested reference to a property returns nullInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getNestedProperty
public String getNestedProperty(Object bean, String name, String pattern) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets 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 extractedname
- Possibly nested name of the property to be extractedpattern
- The conversion pattern- Returns:
- The nested property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodIllegalArgumentException
- if a nested reference to a property returns nullInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getProperty
public String getProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets 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 conversion pattern of the correspondingLocaleConverter
.- Overrides:
getProperty
in classBeanUtilsBean
- Parameters:
bean
- Bean whose property is to be extractedname
- Possibly indexed and/or nested name of the property to be extracted- Returns:
- The property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getProperty
public String getProperty(Object bean, String name, String pattern) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets 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 conversion pattern.- Parameters:
bean
- Bean whose property is to be extractedname
- Possibly indexed and/or nested name of the property to be extractedpattern
- The conversion pattern- Returns:
- The nested property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getSimpleProperty
public String getSimpleProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets the value of the specified simple locale-sensitive property of the specified bean, converted to a String using the default conversion pattern of the correspondingLocaleConverter
.- Overrides:
getSimpleProperty
in classBeanUtilsBean
- Parameters:
bean
- Bean whose property is to be extractedname
- Name of the property to be extracted- Returns:
- The property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
getSimpleProperty
public String getSimpleProperty(Object bean, String name, String pattern) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Gets the value of the specified simple locale-sensitive property of the specified bean, converted to a String using the specified conversion pattern.- Parameters:
bean
- Bean whose property is to be extractedname
- Name of the property to be extractedpattern
- The conversion pattern- Returns:
- The property's value, converted to a String
- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
invokeSetter
protected void invokeSetter(Object target, String propName, String key, int index, Object newValue) throws IllegalAccessException, InvocationTargetException Invoke the setter method.- Parameters:
target
- The beanpropName
- The Simple name of target propertykey
- 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 methodInvocationTargetException
- if the property accessor method throws an exception
-
setApplyLocalized
Sets whether the pattern is applied localized (Indicate whether the pattern is localized or not)- Parameters:
newApplyLocalized
-true
if pattern is localized, otherwisefalse
-
setDefaultLocale
Sets the default Locale.- Parameters:
locale
- the default locale
-
setProperty
public void setProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException Sets the specified locale-sensitive property value, performing type conversions as required to conform to the type of the destination property using the default conversion pattern of the correspondingLocaleConverter
.- Overrides:
setProperty
in classBeanUtilsBean
- Parameters:
bean
- Bean on which setting is to be performedname
- 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 methodInvocationTargetException
- if the property accessor method throws an exception
-
setProperty
public void setProperty(Object bean, String name, Object value, String pattern) throws IllegalAccessException, InvocationTargetException Sets the specified locale-sensitive property value, performing type conversions as required to conform to the type of the destination property using the specified conversion pattern.- Parameters:
bean
- Bean on which setting is to be performedname
- Property name (can be nested/indexed/mapped/combo)value
- Value to be setpattern
- The conversion pattern- Throws:
IllegalAccessException
- if the caller does not have access to the property accessor methodInvocationTargetException
- if the property accessor method throws an exception
-