java.lang.Object | |
↳ | org.springframework.beans.BeanUtils |
Static convenience methods for JavaBeans: for instantiating beans, checking bean property types, copying bean properties, etc.
Mainly for use within the framework, but to some degree also useful for application classes.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Copy the property values of the given source bean into the target bean.
| |||||||||||
Copy the property values of the given source bean into the given target bean,
ignoring the given "ignoreProperties".
| |||||||||||
Copy the property values of the given source bean into the given target bean,
only setting properties defined in the given "editable" class (or interface).
| |||||||||||
Find a method with the given method name and the given parameter types,
declared on the given class or one of its superclasses.
| |||||||||||
Find a method with the given method name and minimal parameters (best case: none),
declared on the given class or one of its superclasses.
| |||||||||||
Find a JavaBeans PropertyEditor following the 'Editor' suffix convention
(e.g.
| |||||||||||
Find a method with the given method name and the given parameter types,
declared on the given class or one of its superclasses.
| |||||||||||
Find a method with the given method name and minimal parameters (best case: none),
declared on the given class or one of its superclasses.
| |||||||||||
Find a method with the given method name and minimal parameters (best case: none)
in the given list of methods.
| |||||||||||
Find a JavaBeans
PropertyDescriptor for the given method,
with the method either being the read method or the write method for
that bean property. | |||||||||||
Determine the bean property type for the given property from the
given classes/interfaces, if possible.
| |||||||||||
Retrieve the JavaBeans
PropertyDescriptors for the given property. | |||||||||||
Retrieve the JavaBeans
PropertyDescriptor s of a given class. | |||||||||||
Obtain a new MethodParameter object for the write method of the
specified property.
| |||||||||||
Convenience method to instantiate a class using its no-arg constructor.
| |||||||||||
Convenience method to instantiate a class using the given constructor.
| |||||||||||
Instantiate a class using its no-arg constructor.
| |||||||||||
Instantiate a class using its no-arg constructor and return the new instance
as the the specified assignable type.
| |||||||||||
Check if the given type represents a "simple" property:
a primitive, a String or other CharSequence, a Number, a Date,
a URI, a URL, a Locale, a Class, or a corresponding array.
| |||||||||||
Check if the given type represents a "simple" value type:
a primitive, a String or other CharSequence, a Number, a Date,
a URI, a URL, a Locale or a Class.
| |||||||||||
Parse a method signature in the form
methodName[([arg_list])] ,
where arg_list is an optional, comma-separated list of fully-qualified
type names, and attempts to resolve that signature against the supplied Class . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Copy the property values of the given source bean into the target bean.
Note: The source and target classes do not have to match or even be derived from each other, as long as the properties match. Any bean properties that the source bean exposes but the target bean does not will silently be ignored.
This is just a convenience method. For more complex transfer needs, consider using a full BeanWrapper.
source | the source bean |
---|---|
target | the target bean |
BeansException | if the copying failed |
---|
Copy the property values of the given source bean into the given target bean, ignoring the given "ignoreProperties".
Note: The source and target classes do not have to match or even be derived from each other, as long as the properties match. Any bean properties that the source bean exposes but the target bean does not will silently be ignored.
This is just a convenience method. For more complex transfer needs, consider using a full BeanWrapper.
source | the source bean |
---|---|
target | the target bean |
ignoreProperties | array of property names to ignore |
BeansException | if the copying failed |
---|
Copy the property values of the given source bean into the given target bean, only setting properties defined in the given "editable" class (or interface).
Note: The source and target classes do not have to match or even be derived from each other, as long as the properties match. Any bean properties that the source bean exposes but the target bean does not will silently be ignored.
This is just a convenience method. For more complex transfer needs, consider using a full BeanWrapper.
source | the source bean |
---|---|
target | the target bean |
editable | the class (or interface) to restrict property setting to |
BeansException | if the copying failed |
---|
Find a method with the given method name and the given parameter types, declared on the given class or one of its superclasses. Will return a public, protected, package access, or private method.
Checks Class.getDeclaredMethod
, cascading upwards to all superclasses.
clazz | the class to check |
---|---|
methodName | the name of the method to find |
paramTypes | the parameter types of the method to find |
null
if not foundFind a method with the given method name and minimal parameters (best case: none), declared on the given class or one of its superclasses. Will return a public, protected, package access, or private method.
Checks Class.getDeclaredMethods
, cascading upwards to all superclasses.
clazz | the class to check |
---|---|
methodName | the name of the method to find |
null
if not foundIllegalArgumentException | if methods of the given name were found but could not be resolved to a unique method with minimal parameters |
---|
Find a JavaBeans PropertyEditor following the 'Editor' suffix convention (e.g. "mypackage.MyDomainClass" -> "mypackage.MyDomainClassEditor").
Compatible to the standard JavaBeans convention as implemented by java.beans.PropertyEditorManager but isolated from the latter's registered default editors for primitive types.
targetType | the type to find an editor for |
---|
null
if none found
Find a method with the given method name and the given parameter types, declared on the given class or one of its superclasses. Prefers public methods, but will return a protected, package access, or private method too.
Checks Class.getMethod
first, falling back to
findDeclaredMethod
. This allows to find public methods
without issues even in environments with restricted Java security settings.
clazz | the class to check |
---|---|
methodName | the name of the method to find |
paramTypes | the parameter types of the method to find |
null
if not foundFind a method with the given method name and minimal parameters (best case: none), declared on the given class or one of its superclasses. Prefers public methods, but will return a protected, package access, or private method too.
Checks Class.getMethods
first, falling back to
findDeclaredMethodWithMinimalParameters
. This allows for finding public
methods without issues even in environments with restricted Java security settings.
clazz | the class to check |
---|---|
methodName | the name of the method to find |
null
if not foundIllegalArgumentException | if methods of the given name were found but could not be resolved to a unique method with minimal parameters |
---|
Find a method with the given method name and minimal parameters (best case: none) in the given list of methods.
methods | the methods to check |
---|---|
methodName | the name of the method to find |
null
if not foundIllegalArgumentException | if methods of the given name were found but could not be resolved to a unique method with minimal parameters |
---|
Find a JavaBeans PropertyDescriptor
for the given method,
with the method either being the read method or the write method for
that bean property.
method | the method to find a corresponding PropertyDescriptor for |
---|
null
if noneBeansException | if PropertyDescriptor lookup fails |
---|
Determine the bean property type for the given property from the given classes/interfaces, if possible.
propertyName | the name of the bean property |
---|---|
beanClasses | the classes to check against |
Object.class
as fallback
Retrieve the JavaBeans PropertyDescriptors
for the given property.
clazz | the Class to retrieve the PropertyDescriptor for |
---|---|
propertyName | the name of the property |
null
if noneBeansException | if PropertyDescriptor lookup fails |
---|
Retrieve the JavaBeans PropertyDescriptor
s of a given class.
clazz | the Class to retrieve the PropertyDescriptors for |
---|
PropertyDescriptors
for the given classBeansException | if PropertyDescriptor look fails |
---|
Obtain a new MethodParameter object for the write method of the specified property.
pd | the PropertyDescriptor for the property |
---|
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.
clazz | class to instantiate |
---|
BeanInstantiationException | if the bean cannot be instantiated |
---|
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.
Note that this method tries to set the constructor accessible if given a non-accessible (that is, non-public) constructor.
ctor | the constructor to instantiate |
---|---|
args | the constructor arguments to apply |
BeanInstantiationException | if the bean cannot be instantiated |
---|
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.
Note that this method tries to set the constructor accessible if given a non-accessible (that is, non-public) constructor.
clazz | class to instantiate |
---|
BeanInstantiationException | if the bean cannot be instantiated |
---|
Instantiate a class using its no-arg constructor and return the new instance as the the specified assignable type.
Useful in cases where the type of the class to instantiate (clazz) is not available, but the type desired (assignableTo) is known.
As this method doesn't try to load classes by name, it should avoid class-loading issues.
Note that this method tries to set the constructor accessible if given a non-accessible (that is, non-public) constructor.
clazz | class to instantiate |
---|---|
assignableTo | type that clazz must be assignableTo |
BeanInstantiationException | if the bean cannot be instantiated |
---|
Check if the given type represents a "simple" property: a primitive, a String or other CharSequence, a Number, a Date, a URI, a URL, a Locale, a Class, or a corresponding array.
Used to determine properties to check for a "simple" dependency-check.
clazz | the type to check |
---|
Check if the given type represents a "simple" value type: a primitive, a String or other CharSequence, a Number, a Date, a URI, a URL, a Locale or a Class.
clazz | the type to check |
---|
Parse a method signature in the form methodName[([arg_list])]
,
where arg_list
is an optional, comma-separated list of fully-qualified
type names, and attempts to resolve that signature against the supplied Class
.
When not supplying an argument list (methodName
) the method whose name
matches and has the least number of parameters will be returned. When supplying an
argument type list, only the method whose name and argument types match will be returned.
Note then that methodName
and methodName()
are not
resolved in the same way. The signature methodName
means the method called
methodName
with the least number of arguments, whereas methodName()
means the method called methodName
with exactly 0 arguments.
If no method can be found, then null
is returned.
signature | the method signature as String representation |
---|---|
clazz | the class to resolve the method signature against |