|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.databene.commons.BeanUtil
public final class BeanUtil
Bundles reflection and introspection related operations.
Created: 01.07.2006 08:44:33
| Method Summary | ||
|---|---|---|
static
|
callWithJarClassLoader(java.io.File jarFile,
java.util.concurrent.Callable<T> action)
|
|
static void |
checkJavaBean(java.lang.Class<?> cls)
Checks if a class fulfills the JavaBeans contract. |
|
static
|
clone(T object)
|
|
static
|
cloneAll(T[] input)
|
|
static java.lang.Class<?> |
commonSubType(java.util.Collection<?> objects)
|
|
static java.lang.Class<?> |
commonSuperType(java.util.Collection<?> objects)
|
|
static java.lang.ClassLoader |
createJarClassLoader(java.io.File jarFile)
|
|
static boolean |
deprecated(java.lang.Class<?> type)
Tells if a class is deprecated. |
|
static boolean |
equalsIgnoreType(java.lang.Object o1,
java.lang.Object o2)
Tries to convert both arguments to the same type and then compares them |
|
static
|
extractProperties(java.util.Collection<BEAN> beans,
java.lang.String propertyName)
|
|
static
|
findConstructor(java.lang.Class<T> type,
java.lang.Class<?>... paramTypes)
|
|
static java.lang.reflect.Method |
findMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Class<?>... paramTypes)
Finds a method by reflection. |
|
static java.lang.reflect.Method[] |
findMethodsByAnnotation(java.lang.Class<?> owner,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
|
|
static java.lang.reflect.Method[] |
findMethodsByName(java.lang.Class<?> type,
java.lang.String methodName)
|
|
static
|
forName(java.lang.String name)
Instantiates the specified class. |
|
static java.lang.Object |
getAttributeValue(java.lang.Object obj,
java.lang.String attributeName)
Returns an object's attribute value |
|
static java.lang.ClassLoader |
getContextClassLoader()
|
|
static java.lang.reflect.Field |
getField(java.lang.Class<?> type,
java.lang.String name)
Returns a Field object that represents an attribute of a class |
|
static java.lang.Object |
getFieldValue(java.lang.reflect.Field field,
java.lang.Object target,
boolean strict)
|
|
static java.lang.Object |
getFieldValue(java.lang.Object target,
java.lang.String name,
boolean strict)
|
|
static
|
getGenericInterfaceParams(java.lang.Class<C> checkedClass,
java.lang.Class<I> searchedInterface)
|
|
static java.lang.Class<?>[] |
getGenericTypes(java.lang.reflect.Field field)
Returns the generic type information of an attribute. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Class<?>... paramTypes)
Finds a method by reflection. |
|
static java.beans.PropertyDescriptor |
getPropertyDescriptor(java.lang.Class<?> beanClass,
java.lang.String propertyName)
Returns the bean property descriptor of an attribute |
|
static java.beans.PropertyDescriptor |
getPropertyDescriptor(java.lang.Class<?> type,
java.lang.String propertyName,
boolean required)
|
|
static java.beans.PropertyDescriptor[] |
getPropertyDescriptors(java.lang.Class<?> type)
Finds all property descriptors of a bean class |
|
static java.lang.Object |
getPropertyValue(java.lang.Object bean,
java.lang.String propertyName)
Queries a property value on a JavaBean instance |
|
static java.lang.Object |
getPropertyValue(java.lang.Object bean,
java.lang.String propertyName,
boolean strict)
|
|
static java.lang.Object |
getStaticAttributeValue(java.lang.Class<?> objectType,
java.lang.String attributeName)
Returns a class' static attribute value |
|
static java.lang.Class<?> |
getWrapper(java.lang.String primitiveClassName)
|
|
static boolean |
hasProperty(java.lang.Class<?> beanClass,
java.lang.String propertyName)
|
|
static java.lang.Object |
invoke(boolean strict,
java.lang.Object target,
java.lang.String methodName,
java.lang.Object... args)
|
|
static
|
invoke(java.lang.Object target,
java.lang.reflect.Method method,
boolean strict,
java.lang.Object... args)
|
|
static java.lang.Object |
invoke(java.lang.Object target,
java.lang.reflect.Method method,
java.lang.Object... args)
Invokes a method on a bean |
|
static java.lang.Object |
invoke(java.lang.Object target,
java.lang.String methodName,
java.lang.Object... args)
Invokes a method on a bean. |
|
static java.lang.Object |
invokeStatic(java.lang.Class<?> targetClass,
java.lang.String methodName,
java.lang.Object... args)
|
|
static boolean |
isCollectionType(java.lang.Class<?> type)
Tells if the specified class is a collection type. |
|
static boolean |
isDecimalNumberType(java.lang.Class<?> type)
|
|
static boolean |
isDecimalNumberType(java.lang.String className)
|
|
static boolean |
isIntegralNumberType(java.lang.Class<?> type)
|
|
static boolean |
isIntegralNumberType(java.lang.String className)
|
|
static boolean |
isNumberType(java.lang.Class<?> type)
|
|
static boolean |
isPrimitiveNumberType(java.lang.String className)
|
|
static boolean |
isPrimitiveType(java.lang.String className)
|
|
static boolean |
isSimpleType(java.lang.String className)
Tells if the provided class name is the name of a simple Java type |
|
static
|
newInstance(java.lang.Class<T> type,
boolean strict,
java.lang.Object... parameters)
|
|
static
|
newInstance(java.lang.Class<T> type,
java.lang.Object... parameters)
Creates an object of the specified type. |
|
static
|
newInstance(java.lang.reflect.Constructor<T> constructor,
boolean strict,
java.lang.Object... parameters)
|
|
static
|
newInstance(java.lang.reflect.Constructor<T> constructor,
java.lang.Object... params)
Creates a new instance of a Class. |
|
static java.lang.Object |
newInstance(java.lang.String className)
Instantiates a class by the default constructor. |
|
static void |
printClassInfo(java.lang.Object object,
java.io.PrintWriter printer)
Prints information about a class' parents and methods to a PrintWriter |
|
static java.lang.String |
readMethodName(java.lang.String propertyName,
java.lang.Class<?> propertyType)
returns the name of a property read method. |
|
static void |
runWithJarClassLoader(java.io.File jarFile,
java.lang.Runnable action)
|
|
static void |
setAttributeValue(java.lang.Object obj,
java.lang.String fieldName,
java.lang.Object value)
Sets an attribute value of an object. |
|
static void |
setPropertyValue(java.lang.Object bean,
java.lang.String propertyName,
java.lang.Object propertyValue)
sets a property value on a JavaBean instance. |
|
static void |
setPropertyValue(java.lang.Object bean,
java.lang.String propertyName,
java.lang.Object propertyValue,
boolean strict)
|
|
static void |
setPropertyValue(java.lang.Object bean,
java.lang.String propertyName,
java.lang.Object propertyValue,
boolean required,
boolean autoConvert)
|
|
static void |
setStaticAttributeValue(java.lang.Class<?> objectType,
java.lang.String fieldName,
java.lang.Object value)
Sets a static attribute value of a class. |
|
static
|
simpleClassName(java.lang.Object o)
|
|
static java.lang.String |
toString(java.lang.Object bean)
|
|
static java.lang.String |
toString(java.lang.Object bean,
boolean simple)
|
|
static boolean |
typesMatch(java.lang.Class<?>[] foundTypes,
java.lang.Class<?>[] expectedTypes)
|
|
static java.lang.String |
writeMethodName(java.lang.String propertyName)
returns the name of a property write method. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static java.lang.Class<?> commonSuperType(java.util.Collection<?> objects)
public static java.lang.Class<?> commonSubType(java.util.Collection<?> objects)
public static boolean isSimpleType(java.lang.String className)
className - the name to check
public static boolean isPrimitiveType(java.lang.String className)
public static boolean isPrimitiveNumberType(java.lang.String className)
public static boolean isNumberType(java.lang.Class<?> type)
public static boolean isIntegralNumberType(java.lang.Class<?> type)
public static boolean isIntegralNumberType(java.lang.String className)
public static boolean isDecimalNumberType(java.lang.Class<?> type)
public static boolean isDecimalNumberType(java.lang.String className)
public static java.lang.Class<?> getWrapper(java.lang.String primitiveClassName)
public static boolean isCollectionType(java.lang.Class<?> type)
type - the class to check
public static java.lang.Object getAttributeValue(java.lang.Object obj,
java.lang.String attributeName)
obj - the object to queryattributeName - the name of the attribute
public static void setAttributeValue(java.lang.Object obj,
java.lang.String fieldName,
java.lang.Object value)
obj - the object to modifyfieldName - the name of the attribute to setvalue - the value to assign to the field
public static java.lang.Object getStaticAttributeValue(java.lang.Class<?> objectType,
java.lang.String attributeName)
objectType - the class to queryattributeName - the name of the attribute
public static void setStaticAttributeValue(java.lang.Class<?> objectType,
java.lang.String fieldName,
java.lang.Object value)
objectType - the class to modifyfieldName - the name of the attribute to setvalue - the value to assign to the fieldpublic static java.lang.Class<?>[] getGenericTypes(java.lang.reflect.Field field)
field - the field representation of the attribute.
public static <T> java.lang.Class<T> forName(java.lang.String name)
name - the name of the class to instantiate
public static java.lang.ClassLoader getContextClassLoader()
public static java.lang.ClassLoader createJarClassLoader(java.io.File jarFile)
throws java.net.MalformedURLException
java.net.MalformedURLException
public static void runWithJarClassLoader(java.io.File jarFile,
java.lang.Runnable action)
throws java.net.MalformedURLException
java.net.MalformedURLException
public static <T> T callWithJarClassLoader(java.io.File jarFile,
java.util.concurrent.Callable<T> action)
throws java.lang.Exception
java.lang.Exceptionpublic static java.lang.Object newInstance(java.lang.String className)
className - the name of the class to instantiate
public static <T> T newInstance(java.lang.Class<T> type,
java.lang.Object... parameters)
type - the class to instantiateparameters - the constructor parameters
public static <T> T newInstance(java.lang.Class<T> type,
boolean strict,
java.lang.Object... parameters)
public static <T> T newInstance(java.lang.reflect.Constructor<T> constructor,
java.lang.Object... params)
constructor - params -
public static <T> T newInstance(java.lang.reflect.Constructor<T> constructor,
boolean strict,
java.lang.Object... parameters)
public static <T> T clone(T object)
public static <T> T[] cloneAll(T[] input)
public static java.lang.reflect.Method getMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Class<?>... paramTypes)
type - methodName - paramTypes -
public static <T> java.lang.reflect.Constructor<T> findConstructor(java.lang.Class<T> type,
java.lang.Class<?>... paramTypes)
public static java.lang.reflect.Method findMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Class<?>... paramTypes)
type - methodName - paramTypes -
public static java.lang.reflect.Method[] findMethodsByName(java.lang.Class<?> type,
java.lang.String methodName)
public static java.lang.Object invoke(java.lang.Object target,
java.lang.String methodName,
java.lang.Object... args)
target - methodName - args -
public static java.lang.Object invoke(boolean strict,
java.lang.Object target,
java.lang.String methodName,
java.lang.Object... args)
public static java.lang.Object invokeStatic(java.lang.Class<?> targetClass,
java.lang.String methodName,
java.lang.Object... args)
public static java.lang.Object invoke(java.lang.Object target,
java.lang.reflect.Method method,
java.lang.Object... args)
target - method - args -
public static <T> T invoke(java.lang.Object target,
java.lang.reflect.Method method,
boolean strict,
java.lang.Object... args)
public static boolean typesMatch(java.lang.Class<?>[] foundTypes,
java.lang.Class<?>[] expectedTypes)
public static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Class<?> beanClass,
java.lang.String propertyName)
beanClass - the class that holds the attributepropertyName - the name of the property
public static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Class<?> type,
java.lang.String propertyName,
boolean required)
public static boolean hasProperty(java.lang.Class<?> beanClass,
java.lang.String propertyName)
public static java.lang.String readMethodName(java.lang.String propertyName,
java.lang.Class<?> propertyType)
propertyName - the name of the propertypropertyType - the type of the property
public static java.lang.String writeMethodName(java.lang.String propertyName)
propertyName - the name of the property
public static java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Class<?> type)
type - the class to check
public static java.lang.Object getPropertyValue(java.lang.Object bean,
java.lang.String propertyName)
bean - propertyName -
public static java.lang.Object getPropertyValue(java.lang.Object bean,
java.lang.String propertyName,
boolean strict)
public static void setPropertyValue(java.lang.Object bean,
java.lang.String propertyName,
java.lang.Object propertyValue)
bean - propertyName - propertyValue -
public static void setPropertyValue(java.lang.Object bean,
java.lang.String propertyName,
java.lang.Object propertyValue,
boolean strict)
public static void setPropertyValue(java.lang.Object bean,
java.lang.String propertyName,
java.lang.Object propertyValue,
boolean required,
boolean autoConvert)
public static <BEAN,PROP_TYPE> java.util.List<PROP_TYPE> extractProperties(java.util.Collection<BEAN> beans,
java.lang.String propertyName)
public static void printClassInfo(java.lang.Object object,
java.io.PrintWriter printer)
object - printer - public static void checkJavaBean(java.lang.Class<?> cls)
cls - the class to checkpublic static boolean deprecated(java.lang.Class<?> type)
type - the class to check for deprecation
public static java.lang.Object getFieldValue(java.lang.Object target,
java.lang.String name,
boolean strict)
public static java.lang.Object getFieldValue(java.lang.reflect.Field field,
java.lang.Object target,
boolean strict)
public static java.lang.reflect.Field getField(java.lang.Class<?> type,
java.lang.String name)
type - the class that holds the attributename - the name of the attribute
public static java.lang.reflect.Method[] findMethodsByAnnotation(java.lang.Class<?> owner,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
public static <C,I> java.lang.reflect.Type[] getGenericInterfaceParams(java.lang.Class<C> checkedClass,
java.lang.Class<I> searchedInterface)
public static java.lang.String toString(java.lang.Object bean)
public static java.lang.String toString(java.lang.Object bean,
boolean simple)
public static <T> java.lang.String simpleClassName(java.lang.Object o)
public static boolean equalsIgnoreType(java.lang.Object o1,
java.lang.Object o2)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||