|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.crosswire.common.util.ReflectionUtil
public final class ReflectionUtil
Various utilities for calling constructors and methods via introspection.
The GNU Lesser General Public License for details.| Constructor Summary | |
|---|---|
private |
ReflectionUtil()
Prevent instantiation |
| Method Summary | ||
|---|---|---|
static
|
construct(Class<T> clazz,
Object... params)
Build an object using the supplied parameters. |
|
static
|
construct(String className)
Build an object using its default constructor. |
|
static
|
construct(String className,
Object... params)
Build an object using the supplied parameters. |
|
static
|
construct(String className,
Object[] params,
Class<?>[] paramTypes)
Build an object using the supplied parameters. |
|
private static Class<?>[] |
describeParameters(Object... params)
Construct a parallel array of class objects for each element in params. |
|
private static
|
getMethod(Class<T> clazz,
String methodName,
Class<?>[] calledTypes)
|
|
static
|
invoke(Class<T> clazz,
Object obj,
String methodName,
Object... params)
Call a method on an object, or statically, with the supplied parameters. |
|
static
|
invoke(Class<T> clazz,
Object obj,
String methodName,
Object[] params,
Class<?>[] paramTypes)
Call a method on an object, or statically, with the supplied parameters. |
|
static Object |
invoke(Object base,
String methodName,
Object... params)
Call a method on a class given a sting |
|
static Object |
invoke(String call,
Object... params)
Call a static method on a class given a string |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
private ReflectionUtil()
| Method Detail |
|---|
public static <T> T construct(String className)
throws ClassNotFoundException,
InstantiationException,
IllegalAccessException
T - the type of the object to constructclassName - the full class name of the object
ClassNotFoundException - if the class is not found
InstantiationException - if this data represents an abstract class,
an interface, an array class, a primitive type, or void;
or if the class has no nullary constructor;
or if the instantiation fails for some other reason.
IllegalAccessException - if the class or its nullary
constructor is not accessible.
public static <T> T construct(String className,
Object... params)
throws ClassNotFoundException,
NoSuchMethodException,
IllegalAccessException,
InvocationTargetException,
InstantiationException
T - the type of the object to constructclassName - the full class name of the objectparams - the constructor's arguments
ClassNotFoundException - if the class is not found
NoSuchMethodException - the method does not exist
InstantiationException - if this data represents an abstract class,
an interface, an array class, a primitive type, or void;
or if the class has no nullary constructor;
or if the instantiation fails for some other reason.
IllegalAccessException - if the class or its nullary
constructor is not accessible.
InvocationTargetException - if the underlying constructor
throws an exception.
InstantiationException - if the class that declares the
underlying constructor represents an abstract class.
public static <T> T construct(Class<T> clazz,
Object... params)
throws NoSuchMethodException,
InstantiationException,
IllegalAccessException,
InvocationTargetException
T - the type of the object to constructclazz - the class of the objectparams - the constructor's arguments
NoSuchMethodException - the method does not exist
InstantiationException - if the class that declares the
underlying constructor represents an abstract class.
IllegalAccessException - if this Constructor object
is enforcing Java language access control and the underlying
constructor is inaccessible.
InvocationTargetException - if the underlying constructor
throws an exception.
public static <T> T construct(String className,
Object[] params,
Class<?>[] paramTypes)
throws ClassNotFoundException,
NoSuchMethodException,
IllegalAccessException,
InvocationTargetException,
InstantiationException
T - the type of the object to constructclassName - the full class name of the objectparams - the constructor's argumentsparamTypes - the types of the parameters
ClassNotFoundException - if the class is not found
NoSuchMethodException - the method does not exist
InstantiationException - if the class that declares the
underlying constructor represents an abstract class.
IllegalAccessException - if this Constructor object
is enforcing Java language access control and the underlying
constructor is inaccessible.
InvocationTargetException - if the underlying constructor
throws an exception.
public static Object invoke(Object base,
String methodName,
Object... params)
throws NoSuchMethodException,
IllegalAccessException,
InvocationTargetException
base - The object to invoke a method onmethodName - The text of the invocation, for example "getName"params - For example new Object[] { ...}
NoSuchMethodException - the method does not exist
IllegalAccessException - if this Constructor object
is enforcing Java language access control and the underlying
constructor is inaccessible.
InvocationTargetException - if the underlying constructor
throws an exception.
public static Object invoke(String call,
Object... params)
throws ClassNotFoundException,
NoSuchMethodException,
IllegalAccessException,
InvocationTargetException
call - The text of the invocation, for example
"java.lang.String.getName"params - For example new Object[] { ...}
ClassNotFoundException - if the class is not found
NoSuchMethodException - the method does not exist
IllegalAccessException - if this Constructor object
is enforcing Java language access control and the underlying
constructor is inaccessible.
InvocationTargetException - if the underlying constructor
throws an exception.
public static <T> Object invoke(Class<T> clazz,
Object obj,
String methodName,
Object... params)
throws NoSuchMethodException,
IllegalAccessException,
InvocationTargetException
T - the type of the object to constructclazz - the class of the objectobj - the object having the method, or null to call a static methodmethodName - the method to be calledparams - the parameters
NoSuchMethodException - the method does not exist
IllegalAccessException - if this Constructor object
is enforcing Java language access control and the underlying
constructor is inaccessible.
InvocationTargetException - if the underlying constructor
throws an exception.
public static <T> Object invoke(Class<T> clazz,
Object obj,
String methodName,
Object[] params,
Class<?>[] paramTypes)
throws NoSuchMethodException,
IllegalAccessException,
InvocationTargetException
T - the type of the object to constructclazz - the class of the objectobj - the object having the method, or null to call a static methodmethodName - the method to be calledparams - the parametersparamTypes - the types of each of the parameters
NoSuchMethodException - the method does not exist
IllegalAccessException - if this Constructor object
is enforcing Java language access control and the underlying
constructor is inaccessible.
InvocationTargetException - if the underlying constructor
throws an exception.private static Class<?>[] describeParameters(Object... params)
params - the types to describe
private static <T> Method getMethod(Class<T> clazz,
String methodName,
Class<?>[] calledTypes)
throws NoSuchMethodException
NoSuchMethodException
|
Copyright ยจ 2003-2015 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||