Package com.attivio.platform.util
Class ReflectionUtils
- java.lang.Object
-
- com.attivio.platform.util.ReflectionUtils
-
public final class ReflectionUtils extends java.lang.ObjectUtility class for performing actions requiring reflection.
-
-
Constructor Summary
Constructors Constructor Description ReflectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.lang.Class<? extends T>forName(java.lang.String className, java.lang.Class<T> type)Lookup a class givenclassNameandtype.static <T extends java.lang.annotation.Annotation>
TgetAnnotation(java.lang.Class<?> clazz, java.lang.Class<T> annotation)Inspects theclazzand returns the Annotation instance if theannotationis present on the clazz.static java.lang.reflect.MethodgetGetter(java.lang.Class<?> beanClass, java.lang.String name)Gets a getter method.static java.lang.reflect.MethodgetSetter(java.lang.Class<?> beanClass, java.lang.String name, java.lang.Class<?> type)Gets a setter method.static java.lang.Objectinvoke(java.lang.Class<?> beanClass, java.lang.Object bean, java.lang.String name, java.lang.Object... args)Invokes a method.static java.lang.Objectinvoke(java.lang.Object bean, java.lang.String name, java.lang.Object... args)Invokes a method.static <T extends java.lang.annotation.Annotation>
booleanisAnnotationPresent(java.lang.Class<?> clazz, java.lang.Class<T> annotation)Inspects theclazzand returnstrueif theannotationis present on the clazz.static booleanisGetter(java.lang.reflect.Method method)Gets ifmethodis a getter method.static booleanisPublic(java.lang.reflect.Method method)Gets ifmethodis declared public.static booleanisSetter(java.lang.reflect.Method method)Gets ifmethodis a setter method.static booleanisSubclass(java.lang.String className, java.lang.Class<?> type)static <T> TnewInstance(java.lang.Class<? extends T> type)Intantiate a new instance oftype.static java.lang.ObjectnewInstance(java.lang.String className)Instantiate a class by name.
-
-
-
Method Detail
-
isPublic
public static boolean isPublic(java.lang.reflect.Method method)
Gets ifmethodis declared public.
-
isGetter
public static boolean isGetter(java.lang.reflect.Method method)
Gets ifmethodis a getter method.
-
isSetter
public static boolean isSetter(java.lang.reflect.Method method)
Gets ifmethodis a setter method.
-
getGetter
public static java.lang.reflect.Method getGetter(java.lang.Class<?> beanClass, java.lang.String name)Gets a getter method.- Parameters:
beanClass- the beanClassname- the getter name- Returns:
- the getter Method (or null if not found)
-
getSetter
public static java.lang.reflect.Method getSetter(java.lang.Class<?> beanClass, java.lang.String name, java.lang.Class<?> type)Gets a setter method.- Parameters:
beanClass- the bean classname- the setter nametype- the type- Returns:
- the setter Method (or null if not found)
-
forName
public static <T> java.lang.Class<? extends T> forName(java.lang.String className, java.lang.Class<T> type) throws AttivioExceptionLookup a class givenclassNameandtype.- Throws:
AttivioException- if the class is not found or if the type of the class is not a subclass oftype
-
isSubclass
public static boolean isSubclass(java.lang.String className, java.lang.Class<?> type) throws AttivioException- Parameters:
className-type-- Returns:
- true if
classNameis a subclass or implementation oftype(which can be an interface). - Throws:
AttivioException- ifclassNamecould not be found
-
newInstance
public static <T> T newInstance(java.lang.Class<? extends T> type) throws AttivioExceptionIntantiate a new instance oftype.- Throws:
AttivioException
-
newInstance
public static java.lang.Object newInstance(java.lang.String className) throws AttivioExceptionInstantiate a class by name.- Throws:
AttivioException
-
invoke
public static java.lang.Object invoke(java.lang.Object bean, java.lang.String name, java.lang.Object... args) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.IllegalAccessExceptionInvokes a method.- Parameters:
bean- the beanname- the method nameargs- the arguments- Returns:
- result of method invokation
- Throws:
java.lang.NoSuchMethodException- if method could not be foundjava.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessException
-
invoke
public static java.lang.Object invoke(java.lang.Class<?> beanClass, java.lang.Object bean, java.lang.String name, java.lang.Object... args) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.IllegalAccessExceptionInvokes a method.- Parameters:
beanClass- the class forbeanbean- the beanname- the method nameargs- the arguments- Returns:
- result of method invokation
- Throws:
java.lang.NoSuchMethodException- if method could not be foundjava.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessException
-
getAnnotation
public static <T extends java.lang.annotation.Annotation> T getAnnotation(java.lang.Class<?> clazz, java.lang.Class<T> annotation)Inspects theclazzand returns the Annotation instance if theannotationis present on the clazz. This method works with classes or interfaces. All implemented interfaces are checked.- Parameters:
clazz-annotation-- Returns:
- the annotation if present on clazz,
nullotherwise.
-
isAnnotationPresent
public static <T extends java.lang.annotation.Annotation> boolean isAnnotationPresent(java.lang.Class<?> clazz, java.lang.Class<T> annotation)Inspects theclazzand returnstrueif theannotationis present on the clazz. This method works with classes or interfaces. All implemented interfaces are checked.- Parameters:
clazz-annotation-- Returns:
trueif the annotation is present on clazz,falseotherwise.
-
-