org.defne.utility.reflection
Class ReflectionUtils

java.lang.Object
  extended by org.defne.utility.reflection.ReflectionUtils

public final class ReflectionUtils
extends Object

Reflection related utility class.

Version:
$Rev$ $Date$

Field Summary
static Class<?>[] EMPTY
          Empty class array
 
Method Summary
static Object callConstructor(Constructor<?> constructor, Object[] arguments)
           
static Class<?> getClassFromName(String className)
          Load class with the given name and returns it.
static
<T> Constructor<T>
getConstructor(Class<T> clazz, List<Class<?>> arguments)
          Gets class constructor with the given parameters..
static
<T> Object
getNewObject(Class<T> clazz)
          Gets class instance.
static ClassLoader getSystemClassLoader()
          Gets system class loader.
static ClassLoader getThreadClassLoader()
          Gets current thread classloader.
static Object invokeMethod(Object instance, Method method, Object[] arguments)
          Calls the given object's method with supplied arguments.
static void main(String[] args)
           
static void throwDefneExceptionFromPrivilege(PrivilegedActionException e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY

public static final Class<?>[] EMPTY
Empty class array

Method Detail

getThreadClassLoader

public static ClassLoader getThreadClassLoader()
Gets current thread classloader.

This class loader works that is explained in the Java EE specifications.

Returns:
current thread classloader

getNewObject

public static <T> Object getNewObject(Class<T> clazz)
Gets class instance.

Type Parameters:
T - class type
Parameters:
clazz - class of the object
Returns:
the new instance of class

getConstructor

public static <T> Constructor<T> getConstructor(Class<T> clazz,
                                                List<Class<?>> arguments)
Gets class constructor with the given parameters..

Type Parameters:
T - class type
Parameters:
clazz - class of the object
arguments - contructor arguments
Returns:
class constructor

getSystemClassLoader

public static ClassLoader getSystemClassLoader()
Gets system class loader.

Returns:
system class loader

invokeMethod

public static Object invokeMethod(Object instance,
                                  Method method,
                                  Object[] arguments)
Calls the given object's method with supplied arguments.

Parameters:
instance - object instance
method - object method
arguments - method arguments
Returns:
the final result
Throws:
DefneException - if any runtime exception occurs

getClassFromName

public static Class<?> getClassFromName(String className)
Load class with the given name and returns it. If not succesfull, return null.

Parameters:
className - class name
Returns:
the class with the given name

callConstructor

public static Object callConstructor(Constructor<?> constructor,
                                     Object[] arguments)

throwDefneExceptionFromPrivilege

public static void throwDefneExceptionFromPrivilege(PrivilegedActionException e)

main

public static void main(String[] args)


Copyright © 2010 MechSoft Mechanical and Software Solutions. All Rights Reserved.