|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.alee.utils.ReflectUtils
public final class ReflectUtils
This class provides a set of utilities to simplify work with Reflection API. There is also a few methods to retrieve full JAR archive structure.
Constructor Summary | |
---|---|
ReflectUtils()
|
Method Summary | ||
---|---|---|
static void |
applyFieldValue(java.lang.Object object,
java.lang.String field,
java.lang.Object value)
Applies specified value to object field. |
|
static boolean |
applyFieldValueSafely(java.lang.Object object,
java.lang.String field,
java.lang.Object value)
Applies specified value to object field. |
|
static
|
callMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... arguments)
Calls object's method with the specified name and arguments. |
|
static
|
callMethods(java.util.List objects,
java.lang.String methodName,
java.lang.Object... arguments)
Returns list of results returned by called methods. |
|
static java.lang.Object[] |
callMethods(java.lang.Object[] objects,
java.lang.String methodName,
java.lang.Object... arguments)
Returns an array of results returned by called methods. |
|
static
|
callMethodSafely(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... arguments)
Returns result given by called method. |
|
static
|
callMethodsSafely(java.util.List objects,
java.lang.String methodName,
java.lang.Object... arguments)
Returns list of results returned by called methods. |
|
static java.lang.Object[] |
callMethodsSafely(java.lang.Object[] objects,
java.lang.String methodName,
java.lang.Object... arguments)
Returns an array of results returned by called methods. |
|
static
|
callStaticMethod(java.lang.Class theClass,
java.lang.String methodName,
java.lang.Object... arguments)
Returns result of called static method. |
|
static
|
callStaticMethod(java.lang.String canonicalClassName,
java.lang.String methodName,
java.lang.Object... arguments)
Returns result of called static method. |
|
static
|
callStaticMethodSafely(java.lang.Class theClass,
java.lang.String methodName,
java.lang.Object... arguments)
Returns result of called static method. |
|
static
|
callStaticMethodSafely(java.lang.String canonicalClassName,
java.lang.String methodName,
java.lang.Object... arguments)
Returns result of called static method. |
|
static
|
clone(T object)
Returns cloned object. |
|
static
|
cloneSafely(T object)
Returns cloned object. |
|
static boolean |
containsInClassOrSuperclassName(java.lang.Class theClass,
java.lang.String text)
Returns whether one of superclasses contains specified text in its name or not. |
|
static
|
createInstance(java.lang.Class theClass,
java.lang.Object... arguments)
Returns newly created class instance. |
|
static
|
createInstance(java.lang.String canonicalClassName,
java.lang.Object... arguments)
Returns newly created class instance. |
|
static
|
createInstanceSafely(java.lang.Class theClass,
java.lang.Object... arguments)
Returns newly created class instance. |
|
static
|
createInstanceSafely(java.lang.String canonicalClassName,
java.lang.Object... arguments)
Returns newly created class instance. |
|
static java.lang.Class |
getCallerClass()
Returns method caller class. |
|
static
|
getClass(java.lang.String canonicalName)
Returns class for the specified canonical name. |
|
static java.lang.String |
getClassFileName(java.lang.Class classType)
Returns class name with ".class" extension in the end. |
|
static java.lang.String |
getClassFileName(java.lang.Object classObject)
Returns class name with ".class" extension in the end. |
|
static java.lang.String |
getClassName(java.lang.Class classType)
Returns class name. |
|
static java.lang.String |
getClassName(java.lang.Object classObject)
Returns class name. |
|
static java.lang.String[] |
getClassPackages(java.lang.Class classType)
Returns class packages. |
|
static java.lang.String[] |
getClassPackages(java.lang.Object classObject)
Returns class packages. |
|
static java.lang.Class |
getClassSafely(java.lang.String canonicalName)
Returns class for the specified canonical name. |
|
static java.lang.Class[] |
getClassTypes(java.lang.Object[] arguments)
Returns an array of argument class types. |
|
static java.lang.reflect.Constructor |
getConstructor(java.lang.Class theClass,
java.lang.Class... parameterTypes)
Returns class constructor for the specified argument types. |
|
static java.lang.reflect.Field |
getField(java.lang.Class classType,
java.lang.String fieldName)
Returns specified class field. |
|
static java.lang.reflect.Method |
getFieldGetter(java.lang.Class aClass,
java.lang.String field)
Returns field getter methor by popular method naming pattern. |
|
static java.lang.reflect.Method |
getFieldGetter(java.lang.Object object,
java.lang.String field)
Returns field getter methor by popular method naming pattern. |
|
static java.lang.reflect.Field |
getFieldImpl(java.lang.Class classType,
java.lang.String fieldName)
Returns specified class field. |
|
static java.lang.reflect.Field |
getFieldSafely(java.lang.Class classType,
java.lang.String fieldName)
Returns specified class field. |
|
static java.lang.Class<?> |
getFieldType(java.lang.Class classType,
java.lang.String fieldName)
Returns specified class field's type. |
|
static java.lang.Class<?> |
getFieldTypeSafely(java.lang.Class classType,
java.lang.String fieldName)
Returns specified class field's type. |
|
static java.lang.String |
getGetterMethodName(java.lang.String field)
Returns getter method name for the specified field. |
|
static java.lang.Class |
getInnerClass(java.lang.Class fromClass,
java.lang.String innerClassName)
Returns inner class with the specified name. |
|
static java.lang.String |
getIsGetterMethodName(java.lang.String field)
Returns "is" getter method name for the specified field. |
|
static java.io.File |
getJarLocationFile(java.lang.Class jarClass)
Returns JAR location File for the specified class. |
|
static java.net.URL |
getJarLocationURL(java.lang.Class jarClass)
Returns JAR location URL for the specified class. |
|
static JarStructure |
getJarStructure(java.lang.Class jarClass)
Returns JAR archive structure. |
|
static JarStructure |
getJarStructure(java.lang.Class jarClass,
java.util.List<java.lang.String> allowedExtensions,
java.util.List<java.lang.String> allowedPackgages)
Returns JAR archive structure. |
|
static JarStructure |
getJarStructure(java.lang.Class jarClass,
java.util.List<java.lang.String> allowedExtensions,
java.util.List<java.lang.String> allowedPackgages,
FileDownloadListener listener)
Returns JAR archive structure. |
|
static java.lang.String |
getJavaClassName(java.lang.Class classType)
Returns class name with ".java" extension in the end. |
|
static java.lang.String |
getJavaClassName(java.lang.Object classObject)
Returns class name with ".java" extension in the end. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class aClass,
java.lang.String methodName,
java.lang.Object... arguments)
Returns object's method with the specified name and arguments. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... arguments)
Returns object's method with the specified name and arguments. |
|
protected static java.lang.reflect.Method |
getMethodImpl(java.lang.Class aClass,
java.lang.String methodName,
java.lang.Object[] arguments)
Returns object's method with the specified name and arguments. |
|
static java.lang.reflect.Method |
getMethodSafely(java.lang.Class aClass,
java.lang.String methodName,
java.lang.Object... arguments)
Returns object's method with the specified name and arguments. |
|
static java.lang.reflect.Method |
getMethodSafely(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... arguments)
Calls object's method with the specified name and arguments. |
|
static java.lang.String[] |
getPackages(java.lang.String packageName)
Returns packages names. |
|
static java.lang.String |
getSetterMethodName(java.lang.String field)
Returns setter method name for the specified field. |
|
static
|
getStaticFieldValue(java.lang.Class classType,
java.lang.String fieldName)
Returns static field value from the specified class. |
|
static
|
getStaticFieldValueSafely(java.lang.Class classType,
java.lang.String fieldName)
Returns static field value from the specified class. |
|
static boolean |
isAssignable(java.lang.Class type,
java.lang.Class from)
Returns whether first type is assignable from second one or not. |
|
static java.lang.Class |
loadClass(java.lang.String canonicalClassName)
Returns class loaded for the specified canonical class name. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ReflectUtils()
Method Detail |
---|
public static java.lang.Class<?> getFieldTypeSafely(java.lang.Class classType, java.lang.String fieldName)
classType
- type of the class where field can be locatedfieldName
- field name
public static java.lang.Class<?> getFieldType(java.lang.Class classType, java.lang.String fieldName) throws java.lang.NoSuchFieldException
classType
- type of the class where field can be locatedfieldName
- field name
java.lang.NoSuchFieldException
public static java.lang.reflect.Field getFieldSafely(java.lang.Class classType, java.lang.String fieldName) throws java.lang.NoSuchFieldException
classType
- type of the class where field can be locatedfieldName
- field name
java.lang.NoSuchFieldException
public static java.lang.reflect.Field getField(java.lang.Class classType, java.lang.String fieldName) throws java.lang.NoSuchFieldException
classType
- type of the class where field can be locatedfieldName
- field name
java.lang.NoSuchFieldException
public static java.lang.reflect.Field getFieldImpl(java.lang.Class classType, java.lang.String fieldName) throws java.lang.NoSuchFieldException
classType
- type of the class where field can be locatedfieldName
- field name
java.lang.NoSuchFieldException
public static boolean applyFieldValueSafely(java.lang.Object object, java.lang.String field, java.lang.Object value)
object
- object instancefield
- object fieldvalue
- field value
public static void applyFieldValue(java.lang.Object object, java.lang.String field, java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException
object
- object instancefield
- object fieldvalue
- field value
java.lang.IllegalAccessException
java.lang.NoSuchFieldException
public static java.lang.Class getClassSafely(java.lang.String canonicalName)
canonicalName
- class canonical name
public static <T> java.lang.Class<T> getClass(java.lang.String canonicalName) throws java.lang.ClassNotFoundException
canonicalName
- class canonical name
java.lang.ClassNotFoundException
public static JarStructure getJarStructure(java.lang.Class jarClass)
jarClass
- any class within the JAR
public static JarStructure getJarStructure(java.lang.Class jarClass, java.util.List<java.lang.String> allowedExtensions, java.util.List<java.lang.String> allowedPackgages)
jarClass
- any class within the JARallowedExtensions
- list of extension filtersallowedPackgages
- list of allowed packages
public static JarStructure getJarStructure(java.lang.Class jarClass, java.util.List<java.lang.String> allowedExtensions, java.util.List<java.lang.String> allowedPackgages, FileDownloadListener listener)
jarClass
- any class within the JARallowedExtensions
- list of extension filtersallowedPackgages
- list of allowed packageslistener
- jar download listener
public static java.net.URL getJarLocationURL(java.lang.Class jarClass)
jarClass
- any class from that JAR
public static java.io.File getJarLocationFile(java.lang.Class jarClass)
jarClass
- any class from that JAR
public static java.lang.Class getCallerClass()
public static java.lang.String getJavaClassName(java.lang.Object classObject)
classObject
- object of class type
public static java.lang.String getJavaClassName(java.lang.Class classType)
classType
- class type
public static java.lang.String getClassFileName(java.lang.Object classObject)
classObject
- object of class type
public static java.lang.String getClassFileName(java.lang.Class classType)
classType
- class type
public static java.lang.String getClassName(java.lang.Object classObject)
classObject
- object of class type
public static java.lang.String getClassName(java.lang.Class classType)
classType
- class type
public static java.lang.String[] getClassPackages(java.lang.Object classObject)
classObject
- object of class type
public static java.lang.String[] getClassPackages(java.lang.Class classType)
classType
- class type
public static java.lang.String[] getPackages(java.lang.String packageName)
packageName
- package name
public static <T> T getStaticFieldValueSafely(java.lang.Class classType, java.lang.String fieldName)
classType
- class typefieldName
- class field name
public static <T> T getStaticFieldValue(java.lang.Class classType, java.lang.String fieldName) throws java.lang.NoSuchFieldException, java.lang.IllegalAccessException
classType
- class typefieldName
- class field name
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static java.lang.Class getInnerClass(java.lang.Class fromClass, java.lang.String innerClassName)
fromClass
- class to look for the inner classinnerClassName
- inner class name
public static <T> T createInstanceSafely(java.lang.String canonicalClassName, java.lang.Object... arguments)
canonicalClassName
- canonical class namearguments
- class constructor arguments
public static <T> T createInstance(java.lang.String canonicalClassName, java.lang.Object... arguments) throws java.lang.ClassNotFoundException, java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.NoSuchMethodException
canonicalClassName
- canonical class namearguments
- class constructor arguments
java.lang.ClassNotFoundException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.lang.NoSuchMethodException
public static <T> T createInstanceSafely(java.lang.Class theClass, java.lang.Object... arguments)
theClass
- class to processarguments
- class constructor arguments
public static <T> T createInstance(java.lang.Class theClass, java.lang.Object... arguments) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
theClass
- class to processarguments
- class constructor arguments
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
public static java.lang.reflect.Constructor getConstructor(java.lang.Class theClass, java.lang.Class... parameterTypes) throws java.lang.NoSuchMethodException
theClass
- class to processparameterTypes
- constructor argument types
java.lang.NoSuchMethodException
public static <T> T callStaticMethodSafely(java.lang.String canonicalClassName, java.lang.String methodName, java.lang.Object... arguments)
canonicalClassName
- canonical class namemethodName
- static method namearguments
- method arguments
public static <T> T callStaticMethod(java.lang.String canonicalClassName, java.lang.String methodName, java.lang.Object... arguments) throws java.lang.ClassNotFoundException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException
canonicalClassName
- canonical class namemethodName
- static method namearguments
- method arguments
java.lang.ClassNotFoundException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
public static <T> T callStaticMethodSafely(java.lang.Class theClass, java.lang.String methodName, java.lang.Object... arguments)
theClass
- class to processmethodName
- static method namearguments
- method arguments
public static <T> T callStaticMethod(java.lang.Class theClass, java.lang.String methodName, java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException
theClass
- class to processmethodName
- static method namearguments
- static method arguments
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
public static <T> java.util.List<T> callMethodsSafely(java.util.List objects, java.lang.String methodName, java.lang.Object... arguments)
objects
- objects to call methods onmethodName
- method namearguments
- method arguments
public static <T> java.util.List<T> callMethods(java.util.List objects, java.lang.String methodName, java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException
objects
- objects to call methods onmethodName
- method namearguments
- method arguments
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
public static java.lang.Object[] callMethodsSafely(java.lang.Object[] objects, java.lang.String methodName, java.lang.Object... arguments)
objects
- objects to call methods onmethodName
- method namearguments
- method arguments
public static java.lang.Object[] callMethods(java.lang.Object[] objects, java.lang.String methodName, java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException
objects
- objects to call methods onmethodName
- method namearguments
- method arguments
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
public static <T> T callMethodSafely(java.lang.Object object, java.lang.String methodName, java.lang.Object... arguments)
object
- object instancemethodName
- method namearguments
- method arguments
public static <T> T callMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException
object
- object instancemethodName
- method namearguments
- method arguments
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
public static java.lang.reflect.Method getFieldGetter(java.lang.Object object, java.lang.String field)
object
- objectfield
- field name
public static java.lang.reflect.Method getFieldGetter(java.lang.Class aClass, java.lang.String field)
aClass
- object classfield
- field name
public static java.lang.String getSetterMethodName(java.lang.String field)
field
- field name
public static java.lang.String getGetterMethodName(java.lang.String field)
field
- field name
public static java.lang.String getIsGetterMethodName(java.lang.String field)
field
- field name
public static java.lang.reflect.Method getMethodSafely(java.lang.Object object, java.lang.String methodName, java.lang.Object... arguments)
object
- objectmethodName
- method namearguments
- method arguments
public static java.lang.reflect.Method getMethodSafely(java.lang.Class aClass, java.lang.String methodName, java.lang.Object... arguments)
aClass
- object classmethodName
- method namearguments
- method arguments
public static java.lang.reflect.Method getMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException
object
- objectmethodName
- method namearguments
- method arguments
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
public static java.lang.reflect.Method getMethod(java.lang.Class aClass, java.lang.String methodName, java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException
aClass
- object classmethodName
- method namearguments
- method arguments
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
protected static java.lang.reflect.Method getMethodImpl(java.lang.Class aClass, java.lang.String methodName, java.lang.Object[] arguments) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
aClass
- object classmethodName
- method namearguments
- method arguments
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
public static <T extends java.lang.Cloneable> T clone(T object) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
T
- cloned object typeobject
- object to clone
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static <T extends java.lang.Cloneable> T cloneSafely(T object)
T
- cloned object typeobject
- object to clone
public static java.lang.Class loadClass(java.lang.String canonicalClassName) throws java.lang.ClassNotFoundException
canonicalClassName
- canonical class name
java.lang.ClassNotFoundException
public static java.lang.Class[] getClassTypes(java.lang.Object[] arguments)
arguments
- arguments to process
public static boolean isAssignable(java.lang.Class type, java.lang.Class from)
type
- checked whether is assignable, always not nullfrom
- checked type, might be null
public static boolean containsInClassOrSuperclassName(java.lang.Class theClass, java.lang.String text)
theClass
- class to processtext
- text to search for
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |