org.apache.commons.beanutils.locale
Class LocaleBeanUtils

java.lang.Object
  extended by org.apache.commons.beanutils.BeanUtils
      extended by org.apache.commons.beanutils.locale.LocaleBeanUtils

public class LocaleBeanUtils
extends BeanUtils

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

The implementations for these methods are provided by LocaleBeanUtilsBean. For more details see LocaleBeanUtilsBean.

Author:
Craig R. McClanahan, Ralph Schaer, Chris Audley, Rey Francois, Gregor Rayman, Yauheny Mikulski

Nested Class Summary
protected static class LocaleBeanUtils.Descriptor
          Deprecated. moved into LocaleBeanUtils
 
Constructor Summary
LocaleBeanUtils()
           
 
Method Summary
protected static LocaleBeanUtils.Descriptor calculate(Object bean, String name)
          Deprecated. moved into LocaleBeanUtilsBean
protected static Object convert(Class type, int index, Object value)
          Convert the specified value to the required type.
protected static Object convert(Class type, int index, Object value, String pattern)
          Convert the specified value to the required type using the specified conversion pattern.
protected static Class definePropertyType(Object target, String name, String propName)
          Calculate the property type.
static boolean getApplyLocalized()
          Gets whether the pattern is localized or not.
static Locale getDefaultLocale()
          Gets the locale used when no locale is passed.
static 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 conversion pattern of the corresponding LocaleConverter.
static 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 conversion pattern of the corresponding LocaleConverter.
static 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 conversion pattern.
static 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.
static 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 conversion pattern of the corresponding LocaleConverter.
static 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.
static 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 conversion pattern.
static 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.
static String getNestedProperty(Object bean, String name)
          Return the value of the (possibly nested) locale-sensitive property of the specified name.
static 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.
static String getProperty(Object bean, String name)
          Return the value of the specified locale-sensitive property of the specified bean.
static String getProperty(Object bean, String name, String pattern)
          Return the value of the specified locale-sensitive property of the specified bean.
static 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 conversion pattern of the corresponding LocaleConverter.
static 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 conversion pattern.
protected static void invokeSetter(Object target, String propName, String key, int index, Object newValue)
          Invoke the setter method.
static void setApplyLocalized(boolean newApplyLocalized)
          Sets whether the pattern is localized or not.
static void setDefaultLocale(Locale locale)
          Sets the locale used when no locale is passed.
static 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 conversion pattern of the corresponding LocaleConverter.
static 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 conversion pattern.
 
Methods inherited from class org.apache.commons.beanutils.BeanUtils
cloneBean, copyProperties, copyProperty, createCache, describe, getArrayProperty, getCacheFast, getDebug, initCause, populate, setCacheFast, setDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocaleBeanUtils

public LocaleBeanUtils()
Method Detail

getDefaultLocale

public static Locale getDefaultLocale()

Gets the locale used when no locale is passed.

For more details see LocaleBeanUtilsBean

Returns:
the default locale
See Also:
LocaleBeanUtilsBean.getDefaultLocale()

setDefaultLocale

public static void setDefaultLocale(Locale locale)

Sets the locale used when no locale is passed.

For more details see LocaleBeanUtilsBean

Parameters:
locale - the default locale
See Also:
LocaleBeanUtilsBean.setDefaultLocale(Locale)

getApplyLocalized

public static boolean getApplyLocalized()

Gets whether the pattern is localized or not.

For more details see LocaleBeanUtilsBean

Returns:
true if pattern is localized, otherwise false
See Also:
LocaleBeanUtilsBean.getApplyLocalized()

setApplyLocalized

public static void setApplyLocalized(boolean newApplyLocalized)

Sets whether the pattern is localized or not.

For more details see LocaleBeanUtilsBean

Parameters:
newApplyLocalized - true if pattern is localized, otherwise false
See Also:
LocaleBeanUtilsBean.setApplyLocalized(boolean)

getIndexedProperty

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

For more details see LocaleBeanUtilsBean

Parameters:
bean - Bean whose property is to be extracted
name - propertyname[index] of the property value to be extracted
pattern - 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getIndexedProperty(Object, String, String)

getIndexedProperty

public static 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 conversion pattern of the corresponding LocaleConverter.

For more details see LocaleBeanUtilsBean

Parameters:
bean - Bean whose property is to be extracted
name - 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getIndexedProperty(Object, String)

getIndexedProperty

public static 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 conversion pattern.

For more details see LocaleBeanUtilsBean

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 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getIndexedProperty(Object, String, int, String)

getIndexedProperty

public static 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 conversion pattern of the corresponding LocaleConverter.

For more details see LocaleBeanUtilsBean

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
Returns:
The indexed property's value, converted to a String
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
See Also:
LocaleBeanUtilsBean.getIndexedProperty(Object, String, int)

getSimpleProperty

public static 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 conversion pattern.

For more details see LocaleBeanUtilsBean

Parameters:
bean - Bean whose property is to be extracted
name - Name of the property to be extracted
pattern - 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getSimpleProperty(Object, String, String)

getSimpleProperty

public static 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 conversion pattern of the corresponding LocaleConverter.

For more details see LocaleBeanUtilsBean

Parameters:
bean - Bean whose property is to be extracted
name - 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getSimpleProperty(Object, String)

getMappedProperty

public static 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 conversion pattern.

For more details see LocaleBeanUtilsBean

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 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getMappedProperty(Object, String, String, String)

getMappedProperty

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

For more details see LocaleBeanUtilsBean

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
Returns:
The mapped property's value, converted to a String
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
See Also:
LocaleBeanUtilsBean.getMappedProperty(Object, String, String)

getMappedPropertyLocale

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

For more details see LocaleBeanUtilsBean

Parameters:
bean - Bean whose property is to be extracted
name - propertyname(index) of the property value to be extracted
pattern - 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getMappedPropertyLocale(Object, String, String)

getMappedProperty

public static 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 conversion pattern of the corresponding LocaleConverter.

For more details see LocaleBeanUtilsBean

Parameters:
bean - Bean whose property is to be extracted
name - 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getMappedProperty(Object, String)

getNestedProperty

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

For more details see LocaleBeanUtilsBean

Parameters:
bean - Bean whose property is to be extracted
name - Possibly nested name of the property to be extracted
pattern - 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getNestedProperty(Object, String, String)

getNestedProperty

public static 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 more details see LocaleBeanUtilsBean

Parameters:
bean - Bean whose property is to be extracted
name - 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getNestedProperty(Object, String)

getProperty

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

For more details see LocaleBeanUtilsBean

Parameters:
bean - Bean whose property is to be extracted
name - Possibly indexed and/or nested name of the property to be extracted
pattern - 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getProperty(Object, String, String)

getProperty

public static String getProperty(Object bean,
                                 String name)
                          throws IllegalAccessException,
                                 InvocationTargetException,
                                 NoSuchMethodException

Return the value of the specified locale-sensitive property of the specified bean.

For more details see LocaleBeanUtilsBean

Parameters:
bean - Bean whose property is to be extracted
name - 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 method
InvocationTargetException - if the property accessor method throws an exception
NoSuchMethodException - if an accessor method for this propety cannot be found
See Also:
LocaleBeanUtilsBean.getProperty(Object, String)

setProperty

public static 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 conversion pattern of the corresponding LocaleConverter.

For more details see LocaleBeanUtilsBean

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
See Also:
LocaleBeanUtilsBean.setProperty(Object, String, Object)

setProperty

public static 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 conversion pattern.

For more details see LocaleBeanUtilsBean

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 conversion pattern
Throws:
IllegalAccessException - if the caller does not have access to the property accessor method
InvocationTargetException - if the property accessor method throws an exception
See Also:
LocaleBeanUtilsBean.setProperty(Object, String, Object, String)

definePropertyType

protected static Class definePropertyType(Object target,
                                          String name,
                                          String propName)
                                   throws IllegalAccessException,
                                          InvocationTargetException

Calculate the property type.

For more details see LocaleBeanUtilsBean

Parameters:
target - The bean
name - The property name
propName - The Simple name of target property
Returns:
The property's type
Throws:
IllegalAccessException - if the caller does not have access to the property accessor method
InvocationTargetException - if the property accessor method throws an exception
See Also:
LocaleBeanUtilsBean.definePropertyType(Object, String, String)

convert

protected static Object convert(Class type,
                                int index,
                                Object value,
                                String pattern)

Convert the specified value to the required type using the specified conversion pattern.

For more details see LocaleBeanUtilsBean

Parameters:
type - The Java type of target property
index - The indexed subscript value (if any)
value - The value to be converted
pattern - The conversion pattern
Returns:
The converted value
See Also:
LocaleBeanUtilsBean.convert(Class, int, Object, String)

convert

protected static Object convert(Class type,
                                int index,
                                Object value)

Convert the specified value to the required type.

For more details see LocaleBeanUtilsBean

Parameters:
type - The Java type of target property
index - The indexed subscript value (if any)
value - The value to be converted
Returns:
The converted value
See Also:
LocaleBeanUtilsBean.convert(Class, int, Object)

invokeSetter

protected static void invokeSetter(Object target,
                                   String propName,
                                   String key,
                                   int index,
                                   Object newValue)
                            throws IllegalAccessException,
                                   InvocationTargetException

Invoke the setter method.

For more details see LocaleBeanUtilsBean

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
See Also:
LocaleBeanUtilsBean.invokeSetter(Object, String, String, int, Object)

calculate

protected static LocaleBeanUtils.Descriptor calculate(Object bean,
                                                      String name)
                                               throws IllegalAccessException,
                                                      InvocationTargetException
Deprecated. moved into LocaleBeanUtilsBean

Resolve any nested expression to get the actual target bean.

Parameters:
bean - The bean
name - The property name
Returns:
The property's descriptor
Throws:
IllegalAccessException - if the caller does not have access to the property accessor method
InvocationTargetException - if the property accessor method throws an exception


Copyright © 2000-2009 The Apache Software Foundation. All Rights Reserved.