Package com.aspectran.utils
Class BeanUtils
java.lang.Object
com.aspectran.utils.BeanUtils
BeanUtils provides methods that allow simple, reflective access to
JavaBeans style properties. Methods are provided for all simple types as
well as object types.
Created: 2008. 04. 22 PM 3:47:15
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>
getClassPropertyTypeForGetter
(Class<?> type, String name) Returns the class that the getter will return when reading a property value.static Class<?>
getClassPropertyTypeForSetter
(Class<?> type, String name) Returns the class that the setter expects to receive as a parameter when setting a property value.static Object
getIndexedProperty
(Object bean, String indexedName) static Class<?>
getIndexedType
(Object bean, String indexedName) static Object
getProperty
(Class<?> beanClass, String name) Invokes the static method of the specified class to get the bean property value.static Object
getProperty
(Object bean, String name) Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.static Class<?>
getPropertyTypeForGetter
(Object bean, String name) Returns the class that the getter will return when reading a property value.static Class<?>
getPropertyTypeForSetter
(Object bean, String name) Returns the class that the setter expects to receive as a parameter when setting a property value.static String[]
Returns an array of the readable properties exposed by a bean.static String[]
Returns an array of readable properties exposed by the bean, except those specified by NonSerializable.static Object
getSimpleProperty
(Object bean, String name) Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.static String[]
Returns an array of the writable properties exposed by a bean.static boolean
hasReadableProperty
(Class<?> beanClass, String name) static boolean
hasReadableProperty
(Object bean, String name) Checks to see if a bean has a readable property be a given name.static boolean
hasStaticReadableProperty
(Class<?> beanClass, String name) static boolean
hasStaticWritableProperty
(Class<?> beanClass, String name) static boolean
hasWritableProperty
(Class<?> beanClass, String name) static boolean
hasWritableProperty
(Object bean, String name) Checks to see if a bean has a writable property be a given name.static void
setIndexedProperty
(Object bean, String indexedName, Object value) static void
setProperty
(Class<?> beanClass, String name, Object value) Invokes the static method of the specified class to get the bean property value.static void
setProperty
(Object bean, String name, Object value) Sets the value of the specified property of the specified bean.static void
setSimpleProperty
(Object bean, String name, Object value) Sets the value of the specified property of the specified bean.
-
Constructor Details
-
BeanUtils
public BeanUtils()
-
-
Method Details
-
getProperty
Invokes the static method of the specified class to get the bean property value.- Parameters:
beanClass
- the class for which to lookupname
- the property name- Returns:
- the property value (as an Object)
- Throws:
InvocationTargetException
- if the property accessor method throws an exception
-
setProperty
public static void setProperty(Class<?> beanClass, String name, Object value) throws InvocationTargetException Invokes the static method of the specified class to get the bean property value.- Parameters:
beanClass
- the class for which to lookupname
- the property namevalue
- the value to which this property is to be set- Throws:
InvocationTargetException
- if the property accessor method throws an exception
-
hasReadableProperty
-
hasWritableProperty
-
hasStaticReadableProperty
-
hasStaticWritableProperty
-
getProperty
public static Object getProperty(Object bean, @NonNull String name) throws InvocationTargetException Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.- Parameters:
bean
- the bean whose property is to be extractedname
- possibly indexed and/or nested name of the property to be extracted- Returns:
- the property value (as an Object)
- Throws:
InvocationTargetException
- if the property accessor method throws an exception
-
getSimpleProperty
public static Object getSimpleProperty(Object bean, @NonNull String name) throws InvocationTargetException Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.- Parameters:
bean
- the bean whose property is to be extractedname
- the name of the property to be extracted that does not allow nesting- Returns:
- the property value (as an Object)
- Throws:
InvocationTargetException
- if the property accessor method throws an exception
-
setProperty
public static void setProperty(Object bean, @NonNull String name, Object value) throws InvocationTargetException, NoSuchMethodException Sets the value of the specified property of the specified bean.- Parameters:
bean
- the bean whose property is to be modifiedname
- possibly indexed and/or nested name of the property to be modifiedvalue
- the value to which this property is to be set- Throws:
InvocationTargetException
- if the property accessor method throws an exceptionNoSuchMethodException
- if an accessor method for this property cannot be found
-
setSimpleProperty
public static void setSimpleProperty(Object bean, @NonNull String name, Object value) throws InvocationTargetException Sets the value of the specified property of the specified bean.- Parameters:
bean
- the bean whose property is to be modifiedname
- the name of the property to be modified that does not allow nestingvalue
- the value to which this property is to be set- Throws:
InvocationTargetException
- if the property accessor method throws an exception
-
getIndexedProperty
public static Object getIndexedProperty(Object bean, @NonNull String indexedName) throws InvocationTargetException - Throws:
InvocationTargetException
-
getIndexedType
public static Class<?> getIndexedType(Object bean, @NonNull String indexedName) throws InvocationTargetException - Throws:
InvocationTargetException
-
setIndexedProperty
public static void setIndexedProperty(Object bean, @NonNull String indexedName, Object value) throws InvocationTargetException - Throws:
InvocationTargetException
-
hasWritableProperty
public static boolean hasWritableProperty(Object bean, @NonNull String name) throws NoSuchMethodException Checks to see if a bean has a writable property be a given name.- Parameters:
bean
- the bean to checkname
- the property name to check for- Returns:
- true if the property exists and is writable
- Throws:
NoSuchMethodException
- if an accessor method for this property cannot be found
-
hasReadableProperty
public static boolean hasReadableProperty(Object bean, @NonNull String name) throws NoSuchMethodException Checks to see if a bean has a readable property be a given name.- Parameters:
bean
- the bean to checkname
- the property name to check for- Returns:
- true if the property exists and is readable
- Throws:
NoSuchMethodException
- if an accessor method for this property cannot be found
-
getPropertyTypeForSetter
public static Class<?> getPropertyTypeForSetter(@NonNull Object bean, String name) throws NoSuchMethodException Returns the class that the setter expects to receive as a parameter when setting a property value.- Parameters:
bean
- the bean to checkname
- the name of the property- Returns:
- the type of the property
- Throws:
NoSuchMethodException
- if an accessor method for this property cannot be found
-
getPropertyTypeForGetter
public static Class<?> getPropertyTypeForGetter(@NonNull Object bean, String name) throws NoSuchMethodException Returns the class that the getter will return when reading a property value.- Parameters:
bean
- the bean to checkname
- the name of the property- Returns:
- the type of the property
- Throws:
NoSuchMethodException
- if an accessor method for this property cannot be found
-
getClassPropertyTypeForGetter
public static Class<?> getClassPropertyTypeForGetter(Class<?> type, @NonNull String name) throws NoSuchMethodException Returns the class that the getter will return when reading a property value.- Parameters:
type
- the class to checkname
- the name of the property- Returns:
- the type of the property
- Throws:
NoSuchMethodException
- if an accessor method for this property cannot be found
-
getClassPropertyTypeForSetter
public static Class<?> getClassPropertyTypeForSetter(Class<?> type, @NonNull String name) throws NoSuchMethodException Returns the class that the setter expects to receive as a parameter when setting a property value.- Parameters:
type
- The class to checkname
- the name of the property- Returns:
- the type of the property
- Throws:
NoSuchMethodException
- if an accessor method for this property cannot be found
-
getReadablePropertyNames
Returns an array of the readable properties exposed by a bean.- Parameters:
bean
- the bean- Returns:
- the readable properties
-
getReadablePropertyNamesWithoutNonSerializable
Returns an array of readable properties exposed by the bean, except those specified by NonSerializable.- Parameters:
bean
- the bean- Returns:
- the readable properties without non-serializable
-
getWritablePropertyNames
Returns an array of the writable properties exposed by a bean.- Parameters:
bean
- the bean- Returns:
- the properties
-