Class BeanUtil

java.lang.Object
org.nuiton.util.beans.BeanUtil

public class BeanUtil extends Object
Usefull methods around the PropertyChangeListener.
Since:
1.4.1
Author:
Tony Chemit - chemit@codelutin.com
  • Field Details

    • ADD_PROPERTY_CHANGE_LISTENER

      public static final String ADD_PROPERTY_CHANGE_LISTENER
      See Also:
    • REMOVE_PROPERTY_CHANGE_LISTENER

      public static final String REMOVE_PROPERTY_CHANGE_LISTENER
      See Also:
    • IS_READ_DESCRIPTOR

      public static final com.google.common.base.Predicate<PropertyDescriptor> IS_READ_DESCRIPTOR
      Is a property is readable ?
      Since:
      2.5.11
    • IS_WRITE_DESCRIPTOR

      public static final com.google.common.base.Predicate<PropertyDescriptor> IS_WRITE_DESCRIPTOR
      Is a property is writable ?
      Since:
      2.5.11
    • IS_READ_AND_WRITE_DESCRIPTOR

      public static final com.google.common.base.Predicate<PropertyDescriptor> IS_READ_AND_WRITE_DESCRIPTOR
      Is a property is readable and writable ?
      Since:
      2.5.11
  • Constructor Details

    • BeanUtil

      protected BeanUtil()
  • Method Details

    • isJavaBeanCompiliant

      public static boolean isJavaBeanCompiliant(Class<?> type)
      Test if the given type is JavaBean compiliant, says that it has two public methods :
      • addPropertyChangeListener
      • removePropertyChangeListener
      Parameters:
      type - type to test
      Returns:
      true if type is Javabean compiliant, false otherwise
      Since:
      2.0
    • addPropertyChangeListener

      public static void addPropertyChangeListener(PropertyChangeListener listener, Object bean) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException
      Add the given listener to the given bean using the normalized method named addPropertyChangeListener.
      Parameters:
      listener - the listener to add
      bean - the bean on which the listener is added
      Throws:
      InvocationTargetException - if could not invoke the method addPropertyChangeListener
      NoSuchMethodException - if method addPropertyChangeListener does not exist on given bean
      IllegalAccessException - if an illegal access occurs when invoking the method addPropertyChangeListener
    • removePropertyChangeListener

      public static void removePropertyChangeListener(PropertyChangeListener listener, Object bean) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException
      Remove the given listener from the given bean using the normalized method named removePropertyChangeListener.
      Parameters:
      listener - the listener to remove
      bean - the bean on which the listener is removed
      Throws:
      InvocationTargetException - if could not invoke the method removePropertyChangeListener
      NoSuchMethodException - if method removePropertyChangeListener does not exist on given bean
      IllegalAccessException - if an illegal access occurs when invoking the method removePropertyChangeListener
    • getReadableProperties

      public static Set<String> getReadableProperties(Class<?> beanType)
      Obtains all readable properties from a given type.
      Parameters:
      beanType - the type to seek
      Returns:
      the set of all readable properties for the given type
      Since:
      2.0
    • getWriteableProperties

      public static Set<String> getWriteableProperties(Class<?> beanType)
      Obtains all writeable properties from a given type.
      Parameters:
      beanType - the type to seek
      Returns:
      the set of all writeable properties for the given type
      Since:
      2.0
    • isNestedReadableProperty

      public static boolean isNestedReadableProperty(Class<?> beanType, String propertyName)
      Obtains all readable properties from a given type.
      Parameters:
      beanType - the type to seek
      propertyName - FIXME
      Returns:
      the set of all readable properties for the given type
      Since:
      2.0
    • getReadableType

      public static Class<?> getReadableType(Class<?> beanType, String propertyName)
    • getDescriptors

      public static Set<PropertyDescriptor> getDescriptors(Class<?> beanType, com.google.common.base.Predicate<PropertyDescriptor> predicate)
      Scan the given type and obtain PropertyDescriptor given the (optional) predicate (except the class property of any java object). Note: If no predicate is given, then all descriptors are returned.
      Parameters:
      beanType - the bean type to scan
      predicate - the optional predicate to keep descriptor
      Returns:
      set of all matching descriptors
      Since:
      2.6.11
    • getMutator

      public static Method getMutator(Object bean, String property)
    • getDescriptors

      protected static void getDescriptors(Class<?> beanType, com.google.common.base.Predicate<PropertyDescriptor> predicate, Map<String, PropertyDescriptor> result, Set<Class<?>> exploredTypes)
    • getReadableProperties

      protected static void getReadableProperties(Class<?> beanType, Set<String> result, Set<Class<?>> exploredTypes)
    • getReadableProperties

      protected static void getReadableProperties(Class<?> beanType, Set<String> result)
    • getWriteableProperties

      protected static void getWriteableProperties(Class<?> beanType, Set<String> result, Set<Class<?>> exploredTypes)
    • getWriteableProperties

      protected static void getWriteableProperties(Class<?> beanType, Set<String> result)