Class BeanUtils
java.lang.Object
ch.systemsx.cisd.common.reflection.BeanUtils
Some utilities around Java Beans.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA map that provides annotations for given annotation classes.static interfaceMarker interface for converter classes. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tclone(T bean) Returns a deeply cloned java bean.static <T> TcreateBean(Class<T> beanClass, Object sourceBean) Convenience method forcreateBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter)where converter isNULL_CONVERTER.static <T> TcreateBean(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 aPropertiesobject.static <T,S> T[] createBeanArray(Class<T> clazz, Iterable<S> source, BeanUtils.Converter converter) Creates a new array of Beans of type clazz.static final <T,S> T[] createBeanArray(Class<T> clazz, Collection<S> source) Creates a new array of Beans of type clazz.static final <T,S> T[] createBeanArray(Class<T> clazz, Collection<S> source, BeanUtils.Converter converter) Creates a new array of Beans of type clazz.static final <T,S> T[] createBeanArray(Class<T> clazz, S[] source) Creates a new array of Beans of type clazz.static final <T,S> T[] createBeanArray(Class<T> clazz, S[] source, BeanUtils.Converter converter) Creates a new array of Beans of type clazz.static final <T,S> List <T> createBeanList(Class<T> clazz, Iterable<S> source) Creates a new list of Beans of type clazz.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.static <T> TConvenience method forcreateBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter)where converter isNULL_CONVERTER.static <T> TfillBean(Class<T> beanClass, T beanInstance, Object sourceBean, BeanUtils.Converter converter) Fills a new bean beanInstance of type beanClass with values from sourceBean.static final Map<String, PropertyDescriptor> getPropertyDescriptors(Class<?> clazz) Returns a map ofPropertyDescriptors keyed byFeatureDescriptor.getName().
-
Method Details
-
createBeanList
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
Creates a new array of Beans of type clazz. SeecreateBeanList()for parameter specification. -
createBeanArray
Creates a new array of Beans of type clazz. SeecreateBeanList()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. SeecreateBeanList()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. SeecreateBeanList()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. SeecreateBeanList()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 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
Convenience method forcreateBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter)where converter isNULL_CONVERTER. -
createBean
Convenience method forcreateBean(Class, Object, ch.systemsx.cisd.common.reflection.BeanUtils.Converter)where converter isNULL_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. 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(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 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
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
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:
IOExceptionClassNotFoundException
-