public final class ClassUtility extends Object implements UtilMessages
| Modifier and Type | Field and Description |
|---|---|
private static String |
CASE_SEPARATOR
The separator use in upper case to simulate a acamleCase change.
|
private static JRLogger |
LOGGER
The class logger.
|
static String |
SEPARATOR
The separator used for serialization.
|
ARGUMENT_DETAIL, ARGUMENT_LIST, BAD_CANONICAL_PATH, BROKEN_API_NO_METHOD, BROKEN_API_WRONG_PARAMETERS, BROKEN_WAVE_BAD_ITEM_LIST, BROKEN_WAVE_SENT, CANT_READ_CACHED_JAR_FILE, FILE_UNREADABLE, GENERIC_TYPE_ERROR_1, GENERIC_TYPE_ERROR_2, NO_ANNOTATION_PROPERTY, NO_ANNOTATION_PROPERTY_VALUE, NO_CONSTRUCTOR, PARSE_CACHED_JAR_FILE, RESOURCE_IGNORED, USE_DEFAULT_CLASSLOADER, USE_JNLP_CLASSLOADER, WAVE_HANDLER_METHOD_REQUIRED| Modifier | Constructor and Description |
|---|---|
private |
ClassUtility()
Private Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static Object |
buildGenericType(Class<?> mainClass,
Class<?>[] assignableClasses,
Object... parameters)
Build the nth generic type of a class.
|
static Object |
buildGenericType(Class<?> mainClass,
Class<?> assignableClass,
Object... parameters)
Build the nth generic type of a class.
|
static Object |
callMethod(Method method,
Object instance,
Object... parameters)
Call the given method for the instance object even if its visibility is private or protected.
|
static String |
camelCaseToUnderscore(String camelCaseString)
Convert aStringUnderscored into A_STRING_UNDESCORED.
|
static Class<?> |
findGenericClass(Class<?> mainClass,
Class<?> assignableClass)
Return the generic class for the given parent class and index.
|
static Class<?> |
findGenericClass(Class<?> mainClass,
Class<?>[] excludedClasses)
Return the generic class for the given parent class and index.
|
static Field |
findProperty(Class<?> sourceClass,
String itemName,
Class<?> searchedClass)
Retrieve a field according to the item name first, then according to searched class.
|
static List<Field> |
getAnnotatedFields(Class<?> cls,
Class<? extends Annotation> annotationClass)
Retrieve all annotation of the given type from the given class.
|
static List<Method> |
getAnnotatedMethods(Class<?> cls,
Class<? extends Annotation> annotationClass)
Retrieve all annotation of the given type from the given class.
|
static Object |
getAnnotationAttribute(Annotation annotation,
String attributeName)
Retrieve an annotation property dynamically by reflection.
|
static Class<? extends Application> |
getClassFromStaticMethod(int classDeepLevel)
Return the class used by the Nth level of the current call stack.
|
static Class<?> |
getClassFromType(Type type)
Return the Class object for the given type.
|
private static Constructor<?> |
getConstructor(Class<?> genericClass,
Class<?>[] parameterTypes)
Retrieve the constructor of a Type.
|
static <A extends Annotation> |
getLastClassAnnotation(Class<?> sourceClass,
Class<A> annotationClass)
Extract the last annotation requested found into the class hierarchy.
|
static Method |
getMethodByName(Class<?> cls,
String action)
Return the method that exactly match the action name.
|
static List<Method> |
retrieveMethodList(Class<?> cls,
String methodName)
Check if the given method exists in the given class.
|
static List<Field> |
retrievePropertyList(Class<?> cls)
List all properties for the given class.
|
static void |
setFieldValue(Field field,
Object instance,
Object value)
Update an object field even if it has a private or protected visibility.
|
static String |
underscoreToCamelCase(String undescoredString)
Convert A_STRING_UNDESCORED into aStringUnderscored.
|
public static final String SEPARATOR
private static final String CASE_SEPARATOR
private static final JRLogger LOGGER
public static Object buildGenericType(Class<?> mainClass, Class<?> assignableClass, Object... parameters) throws CoreException
mainClass - The main class used (that contain at least one generic type)assignableClass - the parent type of the generic to buildparameters - used by the constructor of the generic typeCoreException - if the instantiation failspublic static Object buildGenericType(Class<?> mainClass, Class<?>[] assignableClasses, Object... parameters) throws CoreException
mainClass - The main class used (that contain at least one generic type)assignableClasses - if the array contains only one class it define the type of the generic to build, otherwise it defines the types to skip to find the obejct to buildparameters - used by the constructor of the generic typeCoreException - if the instantiation failsprivate static Constructor<?> getConstructor(Class<?> genericClass, Class<?>[] parameterTypes)
genericClass - the type of the objectparameterTypes - an array of parameters' typepublic static Class<?> findGenericClass(Class<?> mainClass, Class<?> assignableClass)
mainClass - the parent classassignableClass - the parent type of the generic to buildpublic static Class<?> findGenericClass(Class<?> mainClass, Class<?>[] excludedClasses)
mainClass - the parent classexcludedClasses - if the array contains only one class it define the type of the generic to build, otherwise it defines the types to skip to find the object to buildpublic static String underscoreToCamelCase(String undescoredString)
undescoredString - the string to convertpublic static String camelCaseToUnderscore(String camelCaseString)
camelCaseString - the string to convertpublic static Method getMethodByName(Class<?> cls, String action) throws NoSuchMethodException
cls - the class which contain the searched methodaction - the name of the method to findNoSuchMethodException - if no method was methodpublic static List<Field> retrievePropertyList(Class<?> cls)
cls - the class to inspect by reflectionpublic static Field findProperty(Class<?> sourceClass, String itemName, Class<?> searchedClass)
sourceClass - the class to inspectitemName - the item name to find (LIKE_THIS)searchedClass - the property class to find if item name query has failedpublic static List<Method> retrieveMethodList(Class<?> cls, String methodName)
cls - the class to search intomethodName - the name of the method to check (camelCased or in upper case with underscore separator)public static Class<?> getClassFromType(Type type)
type - the given type to cast into Classpublic static <A extends Annotation> A getLastClassAnnotation(Class<?> sourceClass, Class<A> annotationClass)
A - the type of the requested annotationsourceClass - the class (wit its parent classes) to inspectannotationClass - the annotation to findpublic static Object getAnnotationAttribute(Annotation annotation, String attributeName)
annotation - the annotation to exploreattributeName - the name of the method to callpublic static Class<? extends Application> getClassFromStaticMethod(int classDeepLevel)
classDeepLevel - the deep level to use to find the right classpublic static List<Method> getAnnotatedMethods(Class<?> cls, Class<? extends Annotation> annotationClass)
cls - the class that we want to inspectannotationClass - the type of Annaotion to findpublic static List<Field> getAnnotatedFields(Class<?> cls, Class<? extends Annotation> annotationClass)
cls - the class that we want to inspectannotationClass - the type of Annotation to findpublic static Object callMethod(Method method, Object instance, Object... parameters) throws CoreException
method - the method to callinstance - the object instance to useparameters - the list of method parameters to useCoreException - if the method call has failedpublic static void setFieldValue(Field field, Object instance, Object value) throws CoreException
field - the field to updateinstance - the object instance that hold this fieldvalue - the value to set into this fieldCoreException - if the new value cannot be setCopyright © 2011–2014 JRebirth OSS. All rights reserved.