|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.twelvemonkeys.lang.BeanUtil
public final class BeanUtil
A utility class with some useful bean-related functions.
NOTE: This class is not considered part of the public API and may be changed without notice
| Method Summary | ||
|---|---|---|
static void |
configure(Object pBean,
Map<String,?> pMapping)
Configures the bean according to the given mapping. |
|
static void |
configure(Object pBean,
Map<String,?> pMapping,
boolean pLispToCamel)
Configures the bean according to the given mapping. |
|
static
|
createInstance(Class<T> pClass,
Object... pParams)
Creates an object from the given class' constructor that matches the given paramaters. |
|
static
|
createInstance(Class<T> pClass,
Object pParam)
Creates an object from the given class' single argument constructor. |
|
static Object |
getPropertyValue(Object pObject,
String pProperty)
Gets a property value from the given object, using reflection. |
|
static Object |
invokeStaticMethod(Class<?> pClass,
String pMethod,
Object... pParams)
Gets an object from any given static method, with the given parameter. |
|
static Object |
invokeStaticMethod(Class<?> pClass,
String pMethod,
Object pParam)
Gets an object from any given static method, with the given parameter. |
|
static void |
setPropertyValue(Object pObject,
String pProperty,
Object pValue)
Sets the property value to an object using reflection. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Object getPropertyValue(Object pObject,
String pProperty)
pObject - The object to get the property frompProperty - The name of the property
null
if it can not be found.
public static void setPropertyValue(Object pObject,
String pProperty,
Object pValue)
throws NoSuchMethodException,
InvocationTargetException,
IllegalAccessException
pObject - The object to get a property frompProperty - The name of the propertypValue - The property value
NoSuchMethodException - if there's no write method for the
given property
InvocationTargetException - if invoking the write method failed
IllegalAccessException - if the caller class has no access to the
write method
public static <T> T createInstance(Class<T> pClass,
Object pParam)
throws InvocationTargetException
pClass - The class to create instance frompParam - The parameters to the constructor
InvocationTargetException - if the constructor failed
public static <T> T createInstance(Class<T> pClass,
Object... pParams)
throws InvocationTargetException
pClass - The class to create instance frompParams - The parameters to the constructor
InvocationTargetException - if the constructor failed
public static Object invokeStaticMethod(Class<?> pClass,
String pMethod,
Object pParam)
throws InvocationTargetException
pClass - The class to invoke method onpMethod - The name of the method to invokepParam - The parameter to the method
InvocationTargetException - if the invocation failed
public static Object invokeStaticMethod(Class<?> pClass,
String pMethod,
Object... pParams)
throws InvocationTargetException
pClass - The class to invoke method onpMethod - The name of the method to invokepParams - The parameters to the method
InvocationTargetException - if the invocation failed
public static void configure(Object pBean,
Map<String,?> pMapping)
throws InvocationTargetException
Map.Entry in Map.values(),
a method named
set + capitalize(entry.getKey()) is called on the bean,
with entry.getValue() as its argument.
Properties that has no matching set-method in the bean, are simply
discarded.
pBean - The bean to configurepMapping - The mapping for the bean
NullPointerException - if any of the parameters are null.
InvocationTargetException - if an error occurs when invoking the
setter-method.
public static void configure(Object pBean,
Map<String,?> pMapping,
boolean pLispToCamel)
throws InvocationTargetException
Map.Entry in Map.values(),
a method named
set + capitalize(entry.getKey()) is called on the bean,
with entry.getValue() as its argument.
Optionally, lisp-style names are allowed, and automatically converted
to Java-style camel-case names.
Properties that has no matching set-method in the bean, are simply
discarded.
pBean - The bean to configurepMapping - The mapping for the beanpLispToCamel - Allow lisp-style names, and automatically convert
them to Java-style camel-case.
NullPointerException - if any of the parameters are null.
InvocationTargetException - if an error occurs when invoking the
setter-method.StringUtil.lispToCamel(String)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||