Class BeanUtils


  • public final class BeanUtils
    extends java.lang.Object
    Some utilities around Java Beans.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  BeanUtils.AnnotationMap
      A map that provides annotations for given annotation classes.
      static interface  BeanUtils.Converter
      Marker interface for converter classes.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T clone​(T bean)
      Returns a deeply cloned java bean.
      static <T> T createBean​(java.lang.Class<T> beanClass, java.lang.Object sourceBean)
      Convenience method for createBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter) where converter is NULL_CONVERTER.
      static <T> T createBean​(java.lang.Class<T> beanClass, java.lang.Object sourceBean, BeanUtils.Converter converter)
      Creates a new bean of type beanClass and fills it with values from sourceBean (which can be a bean or a Properties object.
      static <T,​S>
      T[]
      createBeanArray​(java.lang.Class<T> clazz, java.lang.Iterable<S> source, BeanUtils.Converter converter)
      Creates a new array of Beans of type clazz.
      static <T,​S>
      T[]
      createBeanArray​(java.lang.Class<T> clazz, java.util.Collection<S> source)
      Creates a new array of Beans of type clazz.
      static <T,​S>
      T[]
      createBeanArray​(java.lang.Class<T> clazz, java.util.Collection<S> source, BeanUtils.Converter converter)
      Creates a new array of Beans of type clazz.
      static <T,​S>
      T[]
      createBeanArray​(java.lang.Class<T> clazz, S[] source)
      Creates a new array of Beans of type clazz.
      static <T,​S>
      T[]
      createBeanArray​(java.lang.Class<T> clazz, S[] source, BeanUtils.Converter converter)
      Creates a new array of Beans of type clazz.
      static <T,​S>
      java.util.List<T>
      createBeanList​(java.lang.Class<T> clazz, java.lang.Iterable<S> source)
      Creates a new list of Beans of type clazz.
      static <T,​S>
      java.util.List<T>
      createBeanList​(java.lang.Class<T> clazz, java.lang.Iterable<S> source, BeanUtils.Converter converter)
      Creates a new list of Beans of type clazz.
      static <T> T fillBean​(java.lang.Class<T> beanClass, T beanInstance, java.lang.Object sourceBean)
      Convenience method for createBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter) where converter is NULL_CONVERTER.
      static <T> T fillBean​(java.lang.Class<T> beanClass, T beanInstance, java.lang.Object sourceBean, BeanUtils.Converter converter)
      Fills a new bean beanInstance of type beanClass with values from sourceBean.
      static java.util.Map<java.lang.String,​java.beans.PropertyDescriptor> getPropertyDescriptors​(java.lang.Class<?> clazz)
      Returns a map of PropertyDescriptors keyed by FeatureDescriptor.getName().
      • Methods inherited from class java.lang.Object

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

      • createBeanList

        public static final <T,​S> java.util.List<T> createBeanList​(java.lang.Class<T> clazz,
                                                                         java.lang.Iterable<S> source)
        Creates a new list of Beans of type clazz.
        Parameters:
        clazz - element type of the new list.
        source - The iterable to fill the new bean list from. Can be null, in which case the method returns null.
        Returns:
        The new list filled from sourceList or null, if sourceList is null.
      • createBeanArray

        public static final <T,​S> T[] createBeanArray​(java.lang.Class<T> clazz,
                                                            java.util.Collection<S> source)
        Creates a new array of Beans of type clazz. See createBeanList() for parameter specification.
      • createBeanArray

        public static final <T,​S> T[] createBeanArray​(java.lang.Class<T> clazz,
                                                            S[] source)
        Creates a new array of Beans of type clazz. See createBeanList() for parameter specification.
      • createBeanArray

        public static final <T,​S> T[] createBeanArray​(java.lang.Class<T> clazz,
                                                            S[] source,
                                                            BeanUtils.Converter converter)
        Creates a new array of Beans of type clazz. See createBeanList() for parameter specification.
      • createBeanArray

        public static final <T,​S> T[] createBeanArray​(java.lang.Class<T> clazz,
                                                            java.util.Collection<S> source,
                                                            BeanUtils.Converter converter)
        Creates a new array of Beans of type clazz. See createBeanList() for parameter specification.
      • createBeanArray

        public static <T,​S> T[] createBeanArray​(java.lang.Class<T> clazz,
                                                      java.lang.Iterable<S> source,
                                                      BeanUtils.Converter converter)
        Creates a new array of Beans of type clazz. See createBeanList() for parameter specification.
      • createBeanList

        public static final <T,​S> java.util.List<T> createBeanList​(java.lang.Class<T> clazz,
                                                                         java.lang.Iterable<S> source,
                                                                         BeanUtils.Converter converter)
        Creates a new list of Beans of type clazz.
        Parameters:
        clazz - element type of the new list.
        source - The iterable to fill the new bean list from. Can be null, in which case the method returns null.
        converter - The BeanUtils.Converter to use to perform non-standard conversions when filling the bean. Can be null, in which case only standard conversions are allowed.
        Returns:
        The new list filled from sourceList or null, if sourceList is null.
      • fillBean

        public static <T> T fillBean​(java.lang.Class<T> beanClass,
                                     T beanInstance,
                                     java.lang.Object sourceBean,
                                     BeanUtils.Converter converter)
        Fills a new bean beanInstance of type beanClass with values from sourceBean.
        Parameters:
        beanClass - The class to create a new instance from.
        beanInstance - Instance of the bean to be filled. If null a new instance will be created.
        sourceBean - The bean to get the values from. Can be null, in which case the method returns null.
        converter - The BeanUtils.Converter to use to perform non-standard conversions when filling the bean. Can be null, in which case only standard conversions are allowed.
        Returns:
        The new bean or null if sourceBean is null.
      • createBean

        public static <T> T createBean​(java.lang.Class<T> beanClass,
                                       java.lang.Object sourceBean,
                                       BeanUtils.Converter converter)
        Creates a new bean of type beanClass and fills it with values from sourceBean (which can be a bean or a Properties object.
        Parameters:
        beanClass - The class to create a new instance from.
        sourceBean - The bean to get the values from. Can be null, in which case the method returns null. If this is a Properties object, the bean will be created from the property values. In this case only primitive values and Strings are supported.
        converter - The BeanUtils.Converter to use to perform non-standard conversions when filling the bean. Can be null, in which case only standard conversions are allowed.
        Returns:
        The new bean or null if sourceBean is null.
      • getPropertyDescriptors

        public static final java.util.Map<java.lang.String,​java.beans.PropertyDescriptor> getPropertyDescriptors​(java.lang.Class<?> clazz)
        Returns a map of PropertyDescriptors keyed by FeatureDescriptor.getName().

        It introspects given class and remove each (bean) property that does not have a write method (like class).

      • clone

        public static <T> T clone​(T bean)
                           throws java.io.IOException,
                                  java.lang.ClassNotFoundException
        Returns a deeply cloned java bean.

        NOTE: Throws an exception one of the related objects is not serializable.

        Parameters:
        bean - java bean to be cloned.
        Returns:
        a new java bean cloned from fromBean.
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException