org.springframework.beans
Class BeanUtils

java.lang.Object
  extended byorg.springframework.beans.BeanUtils

public abstract class BeanUtils
extends java.lang.Object

Static convenience methods for JavaBeans, for instantiating beans, copying bean properties, etc.

Mainly for use within the framework, but to some degree also useful for application classes.

Version:
$Id: BeanUtils.java,v 1.15 2004/03/18 02:46:12 trisberg Exp $
Author:
Rod Johnson, Juergen Hoeller

Constructor Summary
BeanUtils()
           
 
Method Summary
static void copyProperties(java.lang.Object source, java.lang.Object target)
          Copy the property values of the given source bean into the target bean.
static void copyProperties(java.lang.Object source, java.lang.Object target, java.lang.String[] ignoreProperties)
          Copy the property values of the given source bean into the given target bean, ignoring the given ignoreProperties.
static java.lang.Object instantiateClass(java.lang.Class clazz)
          Convenience method to instantiate a class using its no-arg constructor.
static java.lang.Object instantiateClass(java.lang.reflect.Constructor constructor, java.lang.Object[] arguments)
          Convenience method to instantiate a class using the given constructor.
static boolean isAssignable(java.lang.Class type, java.lang.Object value)
          Determine if the given type is assignable from the given value, assuming setting by reflection.
static boolean isPrimitiveArray(java.lang.Class clazz)
          Check if the given class represents a primitive array, i.e. boolean, byte, char, short, int, long, float, or double.
static boolean isPrimitiveWrapperArray(java.lang.Class clazz)
          Check if the given class represents an array of primitive wrappers, i.e.
static boolean isSimpleProperty(java.lang.Class clazz)
          Check if the given class represents a "simple" property, i.e. a primitive, a String, a Class, or a corresponding array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanUtils

public BeanUtils()
Method Detail

instantiateClass

public static java.lang.Object instantiateClass(java.lang.Class clazz)
                                         throws BeansException
Convenience method to instantiate a class using its no-arg constructor. As this method doesn't try to load classes by name, it should avoid class-loading issues.

Parameters:
clazz - class to instantiate
Returns:
the new instance
Throws:
BeansException

instantiateClass

public static java.lang.Object instantiateClass(java.lang.reflect.Constructor constructor,
                                                java.lang.Object[] arguments)
                                         throws BeansException
Convenience method to instantiate a class using the given constructor. As this method doesn't try to load classes by name, it should avoid class-loading issues.

Parameters:
constructor - constructor to instantiate
Returns:
the new instance
Throws:
BeansException

isAssignable

public static boolean isAssignable(java.lang.Class type,
                                   java.lang.Object value)
Determine if the given type is assignable from the given value, assuming setting by reflection. Considers primitive wrapper classes as assignable to the corresponding primitive types.

For example used in a bean factory's constructor resolution.

Parameters:
type - the target type
value - the value that should be assigned to the type
Returns:
if the type is assignable from the value

isSimpleProperty

public static boolean isSimpleProperty(java.lang.Class clazz)
Check if the given class represents a "simple" property, i.e. a primitive, a String, a Class, or a corresponding array. Used to determine properties to check for a "simple" dependency-check.

See Also:
RootBeanDefinition.DEPENDENCY_CHECK_SIMPLE, AbstractAutowireCapableBeanFactory.dependencyCheck(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, org.springframework.beans.BeanWrapper, org.springframework.beans.PropertyValues)

isPrimitiveArray

public static boolean isPrimitiveArray(java.lang.Class clazz)
Check if the given class represents a primitive array, i.e. boolean, byte, char, short, int, long, float, or double.


isPrimitiveWrapperArray

public static boolean isPrimitiveWrapperArray(java.lang.Class clazz)
Check if the given class represents an array of primitive wrappers, i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.


copyProperties

public static void copyProperties(java.lang.Object source,
                                  java.lang.Object target)
                           throws java.lang.IllegalArgumentException,
                                  BeansException
Copy the property values of the given source bean into the target bean.

Parameters:
source - source bean
target - target bean
Throws:
java.lang.IllegalArgumentException - if the classes of source and target do not match
BeansException

copyProperties

public static void copyProperties(java.lang.Object source,
                                  java.lang.Object target,
                                  java.lang.String[] ignoreProperties)
                           throws java.lang.IllegalArgumentException,
                                  BeansException
Copy the property values of the given source bean into the given target bean, ignoring the given ignoreProperties.

Parameters:
source - source bean
target - target bean
ignoreProperties - array of property names to ignore
Throws:
java.lang.IllegalArgumentException - if the classes of source and target do not match
BeansException


Copyright (C) 2003-2004 The Spring Framework Project.