Package com.vaadin.cdi.util
Class ClassUtils
java.lang.Object
com.vaadin.cdi.util.ClassUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsMethod(Class<?> targetClass, Method method) Checks if the given class contains a method with the same signature.static booleancontainsPossiblyGenericMethod(Class<?> targetClass, Method method) Checks if the given class has a method with the same signature, taking in to account generic typesstatic MethodextractMethod(Class<?> clazz, Method sourceMethod) Extracts a method with same signature as the source method.static MethodextractMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) Extract a method with the given name and parameterTypes.static MethodextractPossiblyGenericMethod(Class<?> clazz, Method sourceMethod) Extracts a method matching the source method, allowing generic type parameters to be substituted as long as they are properly castable.static ClassLoaderDetect the right ClassLoader.static StringgetJarVersion(Class targetClass) Reads the version of the jar which contains the given classstatic StringgetRevision(Class targetClass) Reads the VCS revision which was used for creating the jarstatic ObjectinstantiateClassForName(String className) Creates an instance for the given class-namestatic booleanisProxyableClass(Type type) Checks whether the CDI rules for proxyable beans are met.static ClassloadClassForName(String name) Loads class for the given namestatic booleanstatic <T> TtryToInstantiateClass(Class<T> targetClass) Instantiates a given class via the default constructorstatic ObjecttryToInstantiateClassForName(String className) Tries to instantiate a class for the given name via the default constructorstatic <T> TtryToInstantiateClassForName(String className, Class<T> targetType) Tries to instantiate a class for the given name and type via the default constructorstatic ClasstryToLoadClassForName(String name) Tries to load a class based on the given namestatic <T> Class<T>tryToLoadClassForName(String name, Class<T> targetType) Tries to load a class based on the given name and interface or abstract class.static <T> Class<T>tryToLoadClassForName(String name, Class<T> targetType, ClassLoader classLoader) Tries to load a class based on the given name and interface or abstract class.static ClasstryToLoadClassForName(String name, ClassLoader classLoader) Tries to load a class based on the given name
-
Method Details
-
getClassLoader
Detect the right ClassLoader. The lookup order is determined by:- ContextClassLoader of the current Thread
- ClassLoader of the given Object 'o'
- ClassLoader of this very ClassUtils class
- Parameters:
o- if notnullit may get used to detect the classloader.- Returns:
- The
ClassLoaderwhich should get used to create new instances
-
isProxyableClass
Checks whether the CDI rules for proxyable beans are met. See CDI spec unproxyable bean types- Parameters:
type-- Returns:
trueif all proxy conditions are met,falseotherwise
-
tryToLoadClassForName
Tries to load a class based on the given name and interface or abstract class.- Type Parameters:
T- current type- Parameters:
name- name of the concrete classtargetType- target type (interface or abstract class)- Returns:
- loaded class or null if it isn't in the classpath
-
tryToLoadClassForName
public static <T> Class<T> tryToLoadClassForName(String name, Class<T> targetType, ClassLoader classLoader) Tries to load a class based on the given name and interface or abstract class.- Type Parameters:
T- current type- Parameters:
name- name of the concrete classtargetType- target type (interface or abstract class)classLoader- TheClassLoader.- Returns:
- loaded class or null if it isn't in the classpath
-
tryToLoadClassForName
Tries to load a class based on the given name- Parameters:
name- name of the class- Returns:
- loaded class or
nullif it isn't in the classpath
-
tryToLoadClassForName
Tries to load a class based on the given name- Parameters:
name- name of the classclassLoader- TheClassLoader.- Returns:
- loaded class or
nullif it isn't in the classpath
-
loadClassForName
Loads class for the given name- Parameters:
name- name of the class- Returns:
- loaded class
- Throws:
ClassNotFoundException- if the class can't be loaded
-
tryToInstantiateClass
Instantiates a given class via the default constructor- Type Parameters:
T- current type- Parameters:
targetClass- class which should be instantiated- Returns:
- created instance or null if the instantiation failed
-
tryToInstantiateClassForName
Tries to instantiate a class for the given name and type via the default constructor- Type Parameters:
T- current type- Parameters:
className- name of the classtargetType- target type- Returns:
- created instance or null if the instantiation failed
-
tryToInstantiateClassForName
Tries to instantiate a class for the given name via the default constructor- Parameters:
className- name of the class- Returns:
- created instance or null if the instantiation failed
-
instantiateClassForName
public static Object instantiateClassForName(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException Creates an instance for the given class-name- Parameters:
className- name of the class which should be instantiated- Returns:
- created instance
- Throws:
ClassNotFoundException- if the instantiation failedIllegalAccessException- if the instantiation failedInstantiationException- if the instantiation failed
-
getJarVersion
Reads the version of the jar which contains the given class- Parameters:
targetClass- class within the jar- Returns:
- version-string which has been found in the manifest or null if there is no version information available
-
getRevision
Reads the VCS revision which was used for creating the jar- Parameters:
targetClass- class within the jar- Returns:
- revision-string which has been found in the manifest or null if there is no information available
-
containsMethod
Checks if the given class contains a method with the same signature.- Parameters:
targetClass- The class to checkmethod- The source method- Returns:
- if it contains a method with the same signature.
-
extractMethod
Extracts a method with same signature as the source method.- Parameters:
clazz- The target classsourceMethod- The source method.- Returns:
- the extracted method or
null
-
extractMethod
Extract a method with the given name and parameterTypes. Returnnullif no such visible method exists on the given class.- Parameters:
clazz-methodName-parameterTypes-- Returns:
-
containsPossiblyGenericMethod
Checks if the given class has a method with the same signature, taking in to account generic types- Parameters:
targetClass-method-- Returns:
- if it contains a method with the same signature.
-
extractPossiblyGenericMethod
Extracts a method matching the source method, allowing generic type parameters to be substituted as long as they are properly castable.- Parameters:
clazz- The target classsourceMethod- The source method.- Returns:
- the extracted method or
null
-
returns
-