Class BeanUtils
- java.lang.Object
-
- ch.systemsx.cisd.common.reflection.BeanUtils
-
public final class BeanUtils extends java.lang.ObjectSome utilities around Java Beans.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceBeanUtils.AnnotationMapA map that provides annotations for given annotation classes.static interfaceBeanUtils.ConverterMarker interface for converter classes.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tclone(T bean)Returns a deeply cloned java bean.static <T> TcreateBean(java.lang.Class<T> beanClass, java.lang.Object sourceBean)Convenience method forcreateBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter)where converter isNULL_CONVERTER.static <T> TcreateBean(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 aPropertiesobject.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> TfillBean(java.lang.Class<T> beanClass, T beanInstance, java.lang.Object sourceBean)Convenience method forcreateBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter)where converter isNULL_CONVERTER.static <T> TfillBean(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 ofPropertyDescriptors keyed byFeatureDescriptor.getName().
-
-
-
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 benull, in which case the method returnsnull.- Returns:
- The new list filled from sourceList or
null, if sourceList isnull.
-
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. SeecreateBeanList()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. SeecreateBeanList()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. SeecreateBeanList()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. SeecreateBeanList()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. SeecreateBeanList()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 benull, in which case the method returnsnull.converter- TheBeanUtils.Converterto use to perform non-standard conversions when filling the bean. Can benull, in which case only standard conversions are allowed.- Returns:
- The new list filled from sourceList or
null, if sourceList isnull.
-
fillBean
public static <T> T fillBean(java.lang.Class<T> beanClass, T beanInstance, java.lang.Object sourceBean)Convenience method forcreateBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter)where converter isNULL_CONVERTER.
-
createBean
public static <T> T createBean(java.lang.Class<T> beanClass, java.lang.Object sourceBean)Convenience method forcreateBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter)where converter isNULL_CONVERTER.
-
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. Ifnulla new instance will be created.sourceBean- The bean to get the values from. Can benull, in which case the method returnsnull.converter- TheBeanUtils.Converterto use to perform non-standard conversions when filling the bean. Can benull, in which case only standard conversions are allowed.- Returns:
- The new bean or
nullif sourceBean isnull.
-
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 aPropertiesobject.- Parameters:
beanClass- The class to create a new instance from.sourceBean- The bean to get the values from. Can benull, in which case the method returnsnull. If this is aPropertiesobject, the bean will be created from the property values. In this case only primitive values and Strings are supported.converter- TheBeanUtils.Converterto use to perform non-standard conversions when filling the bean. Can benull, in which case only standard conversions are allowed.- Returns:
- The new bean or
nullif sourceBean isnull.
-
getPropertyDescriptors
public static final java.util.Map<java.lang.String,java.beans.PropertyDescriptor> getPropertyDescriptors(java.lang.Class<?> clazz)
Returns a map ofPropertyDescriptors keyed byFeatureDescriptor.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.ClassNotFoundExceptionReturns 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.IOExceptionjava.lang.ClassNotFoundException
-
-