Package com.aspectran.core.util
Class BeanUtils
- java.lang.Object
-
- com.aspectran.core.util.BeanUtils
-
public class BeanUtils extends java.lang.ObjectBeanUtils 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 Constructor Description BeanUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Class<?>getClassPropertyTypeForGetter(java.lang.Class<?> type, java.lang.String name)Returns the class that the getter will return when reading a property value.static java.lang.Class<?>getClassPropertyTypeForSetter(java.lang.Class<?> type, java.lang.String name)Returns the class that the setter expects to receive as a parameter when setting a property value.static java.lang.ObjectgetIndexedProperty(java.lang.Object bean, java.lang.String indexedName)static java.lang.Class<?>getIndexedType(java.lang.Object bean, java.lang.String indexedName)static java.lang.ObjectgetProperty(java.lang.Class<?> beanClass, java.lang.String name)Invokes the static method of the specified class to get the bean property value.static java.lang.ObjectgetProperty(java.lang.Object bean, java.lang.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 java.lang.Class<?>getPropertyTypeForGetter(java.lang.Object bean, java.lang.String name)Returns the class that the getter will return when reading a property value.static java.lang.Class<?>getPropertyTypeForSetter(java.lang.Object bean, java.lang.String name)Returns the class that the setter expects to receive as a parameter when setting a property value.static java.lang.String[]getReadablePropertyNames(java.lang.Object bean)Returns an array of the readable properties exposed by a bean.static java.lang.String[]getReadablePropertyNamesWithoutNonSerializable(java.lang.Object bean)Returns an array of readable properties exposed by the bean, except those specified by NonSerializable.static java.lang.ObjectgetSimpleProperty(java.lang.Object bean, java.lang.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 java.lang.String[]getWritablePropertyNames(java.lang.Object bean)Returns an array of the writable properties exposed by a bean.static booleanhasReadableProperty(java.lang.Class<?> beanClass, java.lang.String name)static booleanhasReadableProperty(java.lang.Object bean, java.lang.String name)Checks to see if a bean has a readable property be a given name.static booleanhasStaticReadableProperty(java.lang.Class<?> beanClass, java.lang.String name)static booleanhasStaticWritableProperty(java.lang.Class<?> beanClass, java.lang.String name)static booleanhasWritableProperty(java.lang.Class<?> beanClass, java.lang.String name)static booleanhasWritableProperty(java.lang.Object bean, java.lang.String name)Checks to see if a bean has a writable property be a given name.static voidsetIndexedProperty(java.lang.Object bean, java.lang.String indexedName, java.lang.Object value)static voidsetProperty(java.lang.Class<?> beanClass, java.lang.String name, java.lang.Object value)Invokes the static method of the specified class to get the bean property value.static voidsetProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value)Sets the value of the specified property of the specified bean.static voidsetSimpleProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value)Sets the value of the specified property of the specified bean.
-
-
-
Method Detail
-
getProperty
public static java.lang.Object getProperty(java.lang.Class<?> beanClass, java.lang.String name) throws java.lang.reflect.InvocationTargetExceptionInvokes 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:
java.lang.reflect.InvocationTargetException- if the property accessor method throws an exception
-
setProperty
public static void setProperty(java.lang.Class<?> beanClass, java.lang.String name, java.lang.Object value) throws java.lang.reflect.InvocationTargetExceptionInvokes 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:
java.lang.reflect.InvocationTargetException- if the property accessor method throws an exception
-
hasReadableProperty
public static boolean hasReadableProperty(java.lang.Class<?> beanClass, java.lang.String name)
-
hasWritableProperty
public static boolean hasWritableProperty(java.lang.Class<?> beanClass, java.lang.String name)
-
hasStaticReadableProperty
public static boolean hasStaticReadableProperty(java.lang.Class<?> beanClass, java.lang.String name)
-
hasStaticWritableProperty
public static boolean hasStaticWritableProperty(java.lang.Class<?> beanClass, java.lang.String name)
-
getProperty
public static java.lang.Object getProperty(java.lang.Object bean, java.lang.String name) throws java.lang.reflect.InvocationTargetExceptionReturn 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:
java.lang.reflect.InvocationTargetException- if the property accessor method throws an exception
-
getSimpleProperty
public static java.lang.Object getSimpleProperty(java.lang.Object bean, java.lang.String name) throws java.lang.reflect.InvocationTargetExceptionReturn 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:
java.lang.reflect.InvocationTargetException- if the property accessor method throws an exception
-
setProperty
public static void setProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodExceptionSets 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:
java.lang.reflect.InvocationTargetException- if the property accessor method throws an exceptionjava.lang.NoSuchMethodException- if an accessor method for this property cannot be found
-
setSimpleProperty
public static void setSimpleProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value) throws java.lang.reflect.InvocationTargetExceptionSets 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:
java.lang.reflect.InvocationTargetException- if the property accessor method throws an exception
-
getIndexedProperty
public static java.lang.Object getIndexedProperty(java.lang.Object bean, java.lang.String indexedName) throws java.lang.reflect.InvocationTargetException- Throws:
java.lang.reflect.InvocationTargetException
-
getIndexedType
public static java.lang.Class<?> getIndexedType(java.lang.Object bean, java.lang.String indexedName) throws java.lang.reflect.InvocationTargetException- Throws:
java.lang.reflect.InvocationTargetException
-
setIndexedProperty
public static void setIndexedProperty(java.lang.Object bean, java.lang.String indexedName, java.lang.Object value) throws java.lang.reflect.InvocationTargetException- Throws:
java.lang.reflect.InvocationTargetException
-
hasWritableProperty
public static boolean hasWritableProperty(java.lang.Object bean, java.lang.String name) throws java.lang.NoSuchMethodExceptionChecks 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:
java.lang.NoSuchMethodException- if an accessor method for this property cannot be found
-
hasReadableProperty
public static boolean hasReadableProperty(java.lang.Object bean, java.lang.String name) throws java.lang.NoSuchMethodExceptionChecks 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:
java.lang.NoSuchMethodException- if an accessor method for this property cannot be found
-
getPropertyTypeForSetter
public static java.lang.Class<?> getPropertyTypeForSetter(java.lang.Object bean, java.lang.String name) throws java.lang.NoSuchMethodExceptionReturns 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:
java.lang.NoSuchMethodException- if an accessor method for this property cannot be found
-
getPropertyTypeForGetter
public static java.lang.Class<?> getPropertyTypeForGetter(java.lang.Object bean, java.lang.String name) throws java.lang.NoSuchMethodExceptionReturns 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:
java.lang.NoSuchMethodException- if an accessor method for this property cannot be found
-
getClassPropertyTypeForGetter
public static java.lang.Class<?> getClassPropertyTypeForGetter(java.lang.Class<?> type, java.lang.String name) throws java.lang.NoSuchMethodExceptionReturns 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:
java.lang.NoSuchMethodException- if an accessor method for this property cannot be found
-
getClassPropertyTypeForSetter
public static java.lang.Class<?> getClassPropertyTypeForSetter(java.lang.Class<?> type, java.lang.String name) throws java.lang.NoSuchMethodExceptionReturns 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:
java.lang.NoSuchMethodException- if an accessor method for this property cannot be found
-
getReadablePropertyNames
public static java.lang.String[] getReadablePropertyNames(java.lang.Object bean)
Returns an array of the readable properties exposed by a bean.- Parameters:
bean- the bean- Returns:
- the readable properties
-
getReadablePropertyNamesWithoutNonSerializable
public static java.lang.String[] getReadablePropertyNamesWithoutNonSerializable(java.lang.Object bean)
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
public static java.lang.String[] getWritablePropertyNames(java.lang.Object bean)
Returns an array of the writable properties exposed by a bean.- Parameters:
bean- the bean- Returns:
- the properties
-
-