Utility methods for populating JavaBeans properties
via reflection in a locale-dependent manner.
calculate
protected LocaleBeanUtilsBean.Descriptor calculate(Object bean,
String name)
throws IllegalAccessException,
InvocationTargetException
Resolve any nested expression to get the actual target bean.
bean
- The beanname
- The property name
convert
protected Object convert(Class type,
int index,
Object value)
Convert the specified value to the required type.
type
- The Java type of target propertyindex
- The indexed subscript value (if any)value
- The value to be converted
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.
type
- The Java type of target propertyindex
- The indexed subscript value (if any)value
- The value to be convertedpattern
- The convertion pattern
definePropertyType
protected Class definePropertyType(Object target,
String name,
String propName)
throws IllegalAccessException,
InvocationTargetException
Calculate the property type.
target
- The beanname
- The property namepropName
- The Simple name of target property
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)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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
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.
- getIndexedProperty in interface BeanUtilsBean
bean
- Bean whose property is to be extractedname
- propertyname[index]
of the property value
to be extracted
getIndexedProperty
public String getIndexedProperty(Object bean,
String name,
String pattern)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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.
bean
- Bean whose property is to be extractedname
- propertyname[index]
of the property value
to be extractedpattern
- The convertion pattern
getIndexedProperty
public String getIndexedProperty(Object bean,
String name,
int index)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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
LocaleConverter
.
The index is specified as a method parameter and
must *not* be included in the property name expression
- getIndexedProperty in interface BeanUtilsBean
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
getIndexedProperty
public String getIndexedProperty(Object bean,
String name,
int index,
String pattern)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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
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 convertion pattern
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)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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
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.
- getMappedProperty in interface BeanUtilsBean
bean
- Bean whose property is to be extractedname
- propertyname(index)
of the property value
to be extracted
getMappedProperty
public String getMappedProperty(Object bean,
String name,
String key)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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
- getMappedProperty in interface BeanUtilsBean
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
getMappedProperty
public String getMappedProperty(Object bean,
String name,
String key,
String pattern)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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.
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 convertion pattern
getMappedPropertyLocale
public String getMappedPropertyLocale(Object bean,
String name,
String pattern)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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.
bean
- Bean whose property is to be extractedname
- propertyname(index)
of the property value
to be extractedpattern
- The convertion pattern
getNestedProperty
public String getNestedProperty(Object bean,
String name)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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
LocaleConverter
.
- getNestedProperty in interface BeanUtilsBean
bean
- Bean whose property is to be extractedname
- Possibly nested name of the property to be extracted
getNestedProperty
public String getNestedProperty(Object bean,
String name,
String pattern)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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.
bean
- Bean whose property is to be extractedname
- Possibly nested name of the property to be extractedpattern
- The convertion pattern
getProperty
public String getProperty(Object bean,
String name)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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
LocaleConverter
.
- getProperty in interface BeanUtilsBean
bean
- Bean whose property is to be extractedname
- Possibly indexed and/or nested name of the property
to be extracted
getProperty
public String getProperty(Object bean,
String name,
String pattern)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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.
bean
- Bean whose property is to be extractedname
- Possibly indexed and/or nested name of the property
to be extractedpattern
- The convertion pattern
getSimpleProperty
public String getSimpleProperty(Object bean,
String name)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
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
LocaleConverter
.
- getSimpleProperty in interface BeanUtilsBean
bean
- Bean whose property is to be extractedname
- Name of the property to be extracted
getSimpleProperty
public String getSimpleProperty(Object bean,
String name,
String pattern)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
Return the value of the specified simple locale-sensitive property
of the specified bean, converted to a String using the specified
convertion pattern.
bean
- Bean whose property is to be extractedname
- Name of the property to be extractedpattern
- The convertion pattern
invokeSetter
protected void invokeSetter(Object target,
String propName,
String key,
int index,
Object newValue)
throws IllegalAccessException,
InvocationTargetException
Invoke the setter method.
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
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
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)
throws IllegalAccessException,
InvocationTargetException
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
LocaleConverter
.
- setProperty in interface BeanUtilsBean
bean
- Bean on which setting is to be performedname
- Property name (can be nested/indexed/mapped/combo)value
- Value to be set
setProperty
public void setProperty(Object bean,
String name,
Object value,
String pattern)
throws IllegalAccessException,
InvocationTargetException
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.
bean
- Bean on which setting is to be performedname
- Property name (can be nested/indexed/mapped/combo)value
- Value to be setpattern
- The convertion pattern