Class BeanHelper


  • public class BeanHelper
    extends java.lang.Object
    This is a thin wrapper around BeanInfo, which has some more helpful conveniences for calling getters and setters without all the syntax noise
    • Constructor Summary

      Constructors 
      Constructor Description
      BeanHelper​(java.lang.Class<?> clazz)
      Create a BeanHelper for the given class.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<java.beans.PropertyDescriptor> findAllProperties()  
      <T extends java.lang.annotation.Annotation>
      T
      findAnnotation​(java.lang.String property, java.lang.Class<T> annotationClass)
      Searches both the read method and the write method (in that order) for the annotation of the given class
      java.beans.PropertyDescriptor findProperty​(java.lang.String property)
      Finds the property with a given name.
      static BeanHelper forClass​(java.lang.Class<?> clazz)
      Using this static getter will make use of a static cache internally
      java.lang.Object get​(java.lang.Object self, java.lang.String property)
      Reads the value of the given property from the object
      java.lang.Object getQuiet​(java.lang.Object self, java.lang.String property, LoggerEx log)
      Gets the value of a property on a bean.
      java.lang.Class<?> getType()  
      void set​(java.lang.Object self, java.lang.String property, java.lang.Object value)  
      void setQuiet​(java.lang.Object self, java.lang.String property, java.lang.Object value, LoggerEx log)
      Sets a value for the bean.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BeanHelper

        public BeanHelper​(java.lang.Class<?> clazz)
        Create a BeanHelper for the given class.
    • Method Detail

      • forClass

        public static BeanHelper forClass​(java.lang.Class<?> clazz)
        Using this static getter will make use of a static cache internally
      • getType

        public java.lang.Class<?> getType()
      • findAllProperties

        public java.util.List<java.beans.PropertyDescriptor> findAllProperties()
      • findProperty

        public java.beans.PropertyDescriptor findProperty​(java.lang.String property)
        Finds the property with a given name. If the property doesn't exist, an IllegalArgumentException will be thrown
      • findAnnotation

        public <T extends java.lang.annotation.Annotation> T findAnnotation​(java.lang.String property,
                                                                            java.lang.Class<T> annotationClass)
        Searches both the read method and the write method (in that order) for the annotation of the given class
      • get

        public java.lang.Object get​(java.lang.Object self,
                                    java.lang.String property)
                             throws java.lang.IllegalAccessException,
                                    java.lang.IllegalArgumentException,
                                    java.lang.reflect.InvocationTargetException
        Reads the value of the given property from the object
        Throws:
        java.lang.IllegalAccessException
        java.lang.IllegalArgumentException
        java.lang.reflect.InvocationTargetException
      • getQuiet

        public java.lang.Object getQuiet​(java.lang.Object self,
                                         java.lang.String property,
                                         LoggerEx log)
        Gets the value of a property on a bean. Upon error, messages are logged to the logger and null is returned, except for IllegalAccessExceptions, which are thrown in RuntimeException wrappers.
      • set

        public void set​(java.lang.Object self,
                        java.lang.String property,
                        java.lang.Object value)
                 throws java.lang.reflect.InvocationTargetException,
                        java.lang.IllegalAccessException,
                        java.lang.IllegalArgumentException
        Throws:
        java.lang.reflect.InvocationTargetException
        java.lang.IllegalAccessException
        java.lang.IllegalArgumentException
      • setQuiet

        public void setQuiet​(java.lang.Object self,
                             java.lang.String property,
                             java.lang.Object value,
                             LoggerEx log)
        Sets a value for the bean. Errors are logged to the logger for this BeanHelper, except for IllegalAccessExceptions, which are thrown in RuntimeException wrappers.