public final class BeanUtil
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
configure(java.lang.Object pBean,
java.util.Map<java.lang.String,?> pMapping)
Configures the bean according to the given mapping.
|
static void |
configure(java.lang.Object pBean,
java.util.Map<java.lang.String,?> pMapping,
boolean pLispToCamel)
Configures the bean according to the given mapping.
|
static <T> T |
createInstance(java.lang.Class<T> pClass,
java.lang.Object... pParams)
Creates an object from the given class' constructor that matches
the given paramaters.
|
static <T> T |
createInstance(java.lang.Class<T> pClass,
java.lang.Object pParam)
Creates an object from the given class' single argument constructor.
|
static java.lang.Object |
getPropertyValue(java.lang.Object pObject,
java.lang.String pProperty)
Gets a property value from the given object, using reflection.
|
static java.lang.Object |
invokeStaticMethod(java.lang.Class<?> pClass,
java.lang.String pMethod,
java.lang.Object... pParams)
Gets an object from any given static method, with the given parameter.
|
static java.lang.Object |
invokeStaticMethod(java.lang.Class<?> pClass,
java.lang.String pMethod,
java.lang.Object pParam)
Gets an object from any given static method, with the given parameter.
|
static void |
setPropertyValue(java.lang.Object pObject,
java.lang.String pProperty,
java.lang.Object pValue)
Sets the property value to an object using reflection.
|
public static java.lang.Object getPropertyValue(java.lang.Object pObject,
java.lang.String pProperty)
pObject - The object to get the property frompProperty - The name of the propertynull
if it can not be found.public static void setPropertyValue(java.lang.Object pObject,
java.lang.String pProperty,
java.lang.Object pValue)
throws java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException
pObject - The object to get a property frompProperty - The name of the propertypValue - The property valuejava.lang.NoSuchMethodException - if there's no write method for the
given propertyjava.lang.reflect.InvocationTargetException - if invoking the write method failedjava.lang.IllegalAccessException - if the caller class has no access to the
write methodpublic static <T> T createInstance(java.lang.Class<T> pClass,
java.lang.Object pParam)
throws java.lang.reflect.InvocationTargetException
pClass - The class to create instance frompParam - The parameters to the constructorjava.lang.reflect.InvocationTargetException - if the constructor failedpublic static <T> T createInstance(java.lang.Class<T> pClass,
java.lang.Object... pParams)
throws java.lang.reflect.InvocationTargetException
pClass - The class to create instance frompParams - The parameters to the constructorjava.lang.reflect.InvocationTargetException - if the constructor failedpublic static java.lang.Object invokeStaticMethod(java.lang.Class<?> pClass,
java.lang.String pMethod,
java.lang.Object pParam)
throws java.lang.reflect.InvocationTargetException
pClass - The class to invoke method onpMethod - The name of the method to invokepParam - The parameter to the methodjava.lang.reflect.InvocationTargetException - if the invocation failedpublic static java.lang.Object invokeStaticMethod(java.lang.Class<?> pClass,
java.lang.String pMethod,
java.lang.Object... pParams)
throws java.lang.reflect.InvocationTargetException
pClass - The class to invoke method onpMethod - The name of the method to invokepParams - The parameters to the methodjava.lang.reflect.InvocationTargetException - if the invocation failedpublic static void configure(java.lang.Object pBean,
java.util.Map<java.lang.String,?> pMapping)
throws java.lang.reflect.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 beanjava.lang.NullPointerException - if any of the parameters are null.java.lang.reflect.InvocationTargetException - if an error occurs when invoking the
setter-method.public static void configure(java.lang.Object pBean,
java.util.Map<java.lang.String,?> pMapping,
boolean pLispToCamel)
throws java.lang.reflect.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.java.lang.NullPointerException - if any of the parameters are null.java.lang.reflect.InvocationTargetException - if an error occurs when invoking the
setter-method.StringUtil.lispToCamel(String)Copyright © 2018. All Rights Reserved.