Class BeanUtils

java.lang.Object
ch.systemsx.cisd.common.reflection.BeanUtils

public final class BeanUtils extends Object
Some utilities around Java Beans.
  • Method Details

    • createBeanList

      public static final <T, S> List<T> createBeanList(Class<T> clazz, 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(Class<T> clazz, 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(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(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(Class<T> clazz, 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(Class<T> clazz, 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> List<T> createBeanList(Class<T> clazz, 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(Class<T> beanClass, T beanInstance, Object sourceBean)
      Convenience method for createBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter) where converter is NULL_CONVERTER.
    • createBean

      public static <T> T createBean(Class<T> beanClass, Object sourceBean)
      Convenience method for createBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter) where converter is NULL_CONVERTER.
    • fillBean

      public static <T> T fillBean(Class<T> beanClass, T beanInstance, 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(Class<T> beanClass, 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 Map<String,PropertyDescriptor> getPropertyDescriptors(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 IOException, 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:
      IOException
      ClassNotFoundException