Class BeanUtils

java.lang.Object
com.aspectran.utils.BeanUtils

public class BeanUtils extends Object
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 Details

    • BeanUtils

      public BeanUtils()
  • Method Details

    • getProperty

      public static Object getProperty(Class<?> beanClass, String name) throws InvocationTargetException
      Invokes the static method of the specified class to get the bean property value.
      Parameters:
      beanClass - the class for which to lookup
      name - 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 lookup
      name - the property name
      value - the value to which this property is to be set
      Throws:
      InvocationTargetException - if the property accessor method throws an exception
    • hasReadableProperty

      public static boolean hasReadableProperty(Class<?> beanClass, String name)
    • hasWritableProperty

      public static boolean hasWritableProperty(Class<?> beanClass, String name)
    • hasStaticReadableProperty

      public static boolean hasStaticReadableProperty(Class<?> beanClass, String name)
    • hasStaticWritableProperty

      public static boolean hasStaticWritableProperty(Class<?> beanClass, String name)
    • 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 extracted
      name - 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 extracted
      name - 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 modified
      name - possibly indexed and/or nested name of the property to be modified
      value - the value to which this property is to be set
      Throws:
      InvocationTargetException - if the property accessor method throws an exception
      NoSuchMethodException - 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 modified
      name - the name of the property to be modified that does not allow nesting
      value - 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 check
      name - 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 check
      name - 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 check
      name - 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 check
      name - 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 check
      name - 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 check
      name - the name of the property
      Returns:
      the type of the property
      Throws:
      NoSuchMethodException - if an accessor method for this property cannot be found
    • getReadablePropertyNames

      public static String[] getReadablePropertyNames(@NonNull Object bean)
      Returns an array of the readable properties exposed by a bean.
      Parameters:
      bean - the bean
      Returns:
      the readable properties
    • getReadablePropertyNamesWithoutNonSerializable

      public static String[] getReadablePropertyNamesWithoutNonSerializable(@NonNull 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 String[] getWritablePropertyNames(@NonNull Object bean)
      Returns an array of the writable properties exposed by a bean.
      Parameters:
      bean - the bean
      Returns:
      the properties