org.jcrom.util
Class ReflectionUtils

java.lang.Object
  extended by org.jcrom.util.ReflectionUtils

public class ReflectionUtils
extends java.lang.Object

Various reflection utility methods, used mainly in the Mapper.

Author:
Olafur Gauti Gudmundsson

Constructor Summary
ReflectionUtils()
           
 
Method Summary
static boolean extendsClass(java.lang.Class type, java.lang.Class superClass)
          Check if a class extends a specific class.
static java.util.Set<java.lang.Class<?>> getClasses(java.lang.ClassLoader loader, java.lang.String packageName)
           
static java.util.Set<java.lang.Class<?>> getClasses(java.lang.String packageName)
           
static java.lang.reflect.Field[] getDeclaredAndInheritedFields(java.lang.Class type, boolean returnFinalFields)
          Get an array of all fields declared in the supplied class, and all its superclasses (except java.lang.Object).
static java.util.Set<java.lang.Class<?>> getFromDirectory(java.io.File directory, java.lang.String packageName)
           
static java.util.Set<java.lang.Class<?>> getFromJARFile(java.lang.String jar, java.lang.String packageName)
           
static JcrNode getJcrNodeAnnotation(java.lang.Class c)
           
static java.lang.Class getParameterizedClass(java.lang.Class c)
           
static java.lang.Class getParameterizedClass(java.lang.Class c, int index)
           
static java.lang.Class getParameterizedClass(java.lang.reflect.Field field)
          Get the (first) class that parameterizes the Field supplied.
static java.lang.Class getParameterizedClass(java.lang.reflect.Field field, int index)
          Get the class that parameterizes the Field supplied, at the index supplied (field can be parameterized with multiple param classes).
static java.lang.Class getTypeArgumentOfParameterizedClass(java.lang.reflect.Field field, int index, int typeIndex)
           
static java.util.List<java.lang.reflect.Field> getValidFields(java.lang.reflect.Field[] fields, boolean returnFinalFields)
           
static boolean implementsInterface(java.lang.Class type, java.lang.Class interfaceClass)
          Check if a class implements a specific interface.
static boolean isDateType(java.lang.Class type)
           
static boolean isFieldParameterizedWithClass(java.lang.reflect.Field field, java.lang.Class c)
          Check if a field is parameterized with a specific class.
static boolean isFieldParameterizedWithPropertyType(java.lang.reflect.Field field)
          Check if the field supplied is parameterized with a valid JCR property type.
static boolean isPropertyType(java.lang.Class type)
          Check if the class supplied represents a valid JCR property type.
static boolean isValidMapValueType(java.lang.Class type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtils

public ReflectionUtils()
Method Detail

getDeclaredAndInheritedFields

public static java.lang.reflect.Field[] getDeclaredAndInheritedFields(java.lang.Class type,
                                                                      boolean returnFinalFields)
Get an array of all fields declared in the supplied class, and all its superclasses (except java.lang.Object).

Parameters:
type - the class for which we want to retrieve the Fields
returnFinalFields - specifies whether to return final fields
Returns:
an array of all declared and inherited fields

getValidFields

public static java.util.List<java.lang.reflect.Field> getValidFields(java.lang.reflect.Field[] fields,
                                                                     boolean returnFinalFields)

implementsInterface

public static boolean implementsInterface(java.lang.Class type,
                                          java.lang.Class interfaceClass)
Check if a class implements a specific interface.

Parameters:
type - the class we want to check
interfaceClass - the interface class we want to check against
Returns:
true if type implements interfaceClass, else false

extendsClass

public static boolean extendsClass(java.lang.Class type,
                                   java.lang.Class superClass)
Check if a class extends a specific class.

Parameters:
type - the class we want to check
superClass - the super class we want to check against
Returns:
true if type implements superClass, else false

isPropertyType

public static boolean isPropertyType(java.lang.Class type)
Check if the class supplied represents a valid JCR property type.

Parameters:
type - the class we want to check
Returns:
true if the class represents a valid JCR property type

isValidMapValueType

public static boolean isValidMapValueType(java.lang.Class type)

isDateType

public static boolean isDateType(java.lang.Class type)

getParameterizedClass

public static java.lang.Class getParameterizedClass(java.lang.reflect.Field field)
Get the (first) class that parameterizes the Field supplied.

Parameters:
field - the field
Returns:
the class that parameterizes the field, or null if field is not parameterized

getParameterizedClass

public static java.lang.Class getParameterizedClass(java.lang.reflect.Field field,
                                                    int index)
Get the class that parameterizes the Field supplied, at the index supplied (field can be parameterized with multiple param classes).

Parameters:
field - the field
index - the index of the parameterizing class
Returns:
the class that parameterizes the field, or null if field is not parameterized

getTypeArgumentOfParameterizedClass

public static java.lang.Class getTypeArgumentOfParameterizedClass(java.lang.reflect.Field field,
                                                                  int index,
                                                                  int typeIndex)

getParameterizedClass

public static java.lang.Class getParameterizedClass(java.lang.Class c)

getParameterizedClass

public static java.lang.Class getParameterizedClass(java.lang.Class c,
                                                    int index)

isFieldParameterizedWithClass

public static boolean isFieldParameterizedWithClass(java.lang.reflect.Field field,
                                                    java.lang.Class c)
Check if a field is parameterized with a specific class.

Parameters:
field - the field
c - the class to check against
Returns:
true if the field is parameterized and c is the class that parameterizes the field, or is an interface that the parameterized class implements, else false

isFieldParameterizedWithPropertyType

public static boolean isFieldParameterizedWithPropertyType(java.lang.reflect.Field field)
Check if the field supplied is parameterized with a valid JCR property type.

Parameters:
field - the field
Returns:
true if the field is parameterized with a valid JCR property type, else false

getJcrNodeAnnotation

public static JcrNode getJcrNodeAnnotation(java.lang.Class c)

getFromDirectory

public static java.util.Set<java.lang.Class<?>> getFromDirectory(java.io.File directory,
                                                                 java.lang.String packageName)
                                                          throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

getFromJARFile

public static java.util.Set<java.lang.Class<?>> getFromJARFile(java.lang.String jar,
                                                               java.lang.String packageName)
                                                        throws java.io.IOException,
                                                               java.io.FileNotFoundException,
                                                               java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.io.FileNotFoundException
java.lang.ClassNotFoundException

getClasses

public static java.util.Set<java.lang.Class<?>> getClasses(java.lang.String packageName)
                                                    throws java.io.IOException,
                                                           java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

getClasses

public static java.util.Set<java.lang.Class<?>> getClasses(java.lang.ClassLoader loader,
                                                           java.lang.String packageName)
                                                    throws java.io.IOException,
                                                           java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException


Copyright © 2009. All Rights Reserved.