|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jsefa.common.util.ReflectionUtil
public final class ReflectionUtil
Utility class for reflection.
Method Summary | ||
---|---|---|
static
|
callMethod(Object object,
Method method,
Object... parameters)
Calls the given method with the given parameters on the given object. |
|
static
|
callMethod(Object object,
String methodName)
Calls the parameterless method with the given name on the given object. |
|
static
|
createInstance(Class<T> objectType)
Creates a new instance of the given object type using the default constructor. |
|
static Class<?> |
getActualTypeParameter(Field field,
int index)
Returns the actual type parameter with the given index of the given field or null if it does not exist. |
|
static Collection<Field> |
getAllFields(Class<?> objectType)
Returns the fields of the given class. |
|
static Class<?> |
getClass(String clazz)
Returns a Class object which represents the class with the given name. |
|
static Constructor<?> |
getDefaultConstructor(Class<?> objectType)
Returns the default constructor of the given object type. |
|
static Method |
getMethod(Class<?> objectType,
String methodName,
Class<?>... parameterTypes)
Returns the method on the objectType with the given name and given parameter types. |
|
static
|
getNearest(Class<?> objectType,
Map<Class<?>,T> map)
Returns the value mapped to the given object type or one of its supertypes (classes or interfaces) using a nearest match algorithm. |
|
static List<Class<?>> |
getTypesInReverseOrder(Class<?> objectType)
Returns the path of classes to the given object type in reverse order. |
|
static boolean |
hasClass(String clazz)
Checks whether a given Class is available on the current platform. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Constructor<?> getDefaultConstructor(Class<?> objectType)
objectType
- the object type
public static <T> T createInstance(Class<T> objectType)
T
- the type of the object to createobjectType
- the object type
public static Collection<Field> getAllFields(Class<?> objectType)
objectType
- the class
public static List<Class<?>> getTypesInReverseOrder(Class<?> objectType)
Object
is not included.
objectType
- the object type
public static Method getMethod(Class<?> objectType, String methodName, Class<?>... parameterTypes)
objectType
- the object typemethodName
- the method nameparameterTypes
- the parameter types
public static <T> T callMethod(Object object, String methodName)
T
- the expected type of the return valueobject
- the object to invoke the method onmethodName
- the name of the method
public static <T> T callMethod(Object object, Method method, Object... parameters)
T
- the expected type of the return valueobject
- the object to invoke the method onmethod
- the methodparameters
- the parameters
public static Class<?> getActualTypeParameter(Field field, int index)
field
- the fieldindex
- the index of the requested actual type parameter
public static <T> T getNearest(Class<?> objectType, Map<Class<?>,T> map)
The used "nearest" relation has the following properties:
1. An object type is the nearest object type to itself.
2. Any direct super type (class or interface) is nearer to a given type then any indirect super type.
3. A direct super class of a class A is nearer than any interface implemented by A.
4. For two interfaces I1 and I2 directly implemented by a given class A, I1 is nearer to A than I2 if I1 is
mentioned before I2 in the the implements
clause of the declaration of the class.
T
- the expected type of the return valueobjectType
- the object typemap
- the map
public static boolean hasClass(String clazz)
clazz
- The full qualified name of the class to check.
true
if class is available, false
otherwise.public static Class<?> getClass(String clazz)
clazz
- The full qualified name of the class.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |