|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectInvoker
Invoker lets you invoke protected and private methods in any object.
Examples:
public class TestInvoker {
public TestInvoker() {
Invoker.addPath("C:/AADev/examples/");
VeryPrivate vp = new VeryPrivate();
try {
Invoker.invoke(VeryPrivate.class, vp, "test1", new Object[]{});
Invoker.invoke(VeryPrivate.class, vp, "test2", new Object[]{"Hello!"});
Invoker.invoke(VeryPrivate.class, vp, "test3", new Class[]{Integer.TYPE}, new Object[]{new Integer(555)});
Invoker.invoke(VeryPrivate.class, vp, "test4", new Class[]{String.class, Integer.TYPE}, new Object[]{"Hello again!", new Integer(555)});
}
catch (Exception e) {
System.out.println("Problem: " + e);
}
}
public static void main(String[] args) {
new TestInvoker();
}
}
class VeryPrivate {
private void test1() {
System.out.println("Test1: no parameters");
}
private void test2(String s) {
System.out.println("Test2: a String: " + s);
}
private void test3(int i) {
System.out.println("Test3: an integer: " + i);
}
private void test4(String s, int i) {
System.out.println("Test4: a String: " + s + ", and an Integer: " + i);
}
}
| Method Summary | |
static void |
addPath(String path)
Invokes the protected addURL method from the
URLClassLoader class, in order to bypass the fact that it is
not possible to modify the classpath during runtime. |
static void |
invoke(Class className,
Object obj,
String method,
Class[] paramClass,
Object[] param)
Invokes a method containing primitive types. |
static void |
invoke(Class className,
Object obj,
String method,
Object[] param)
Invokes a method containing no primitive types. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public static void invoke(Class className,
Object obj,
String method,
Object[] param)
throws Exception
invoke(Class, Object, String, Class[], Object[]) method.
className - the class of the object, for example
URLClassLoader.classobj - the object containing the method to invokemethod - the name of the method to invoke, for example
"addURL"param - the parameters, for example new Object[]{url}
Exception - the following exceptions can be thrown from this method:
NoSuchMethodException,
NullPointerException,
SecurityException,
IllegalAccessException,
IllegalArgumentException,
InvocationTargetException,
ExceptionInInitializerError.invoke(Class, Object, String, Class[], Object[])
public static void invoke(Class className,
Object obj,
String method,
Class[] paramClass,
Object[] param)
throws Exception
invoke(Class, Object, String, Object[]) method.
className - the class of the object, for example
MyProgram.classobj - the object containing the method to invokemethod - the name of the method to invoke, for example
"testMethod"paramClass - the classes of the parameters, for exemple
new Class[]{Integer.TYPE}param - the parameters, for example new Object[]{new
Integer(555)}
Exception - the following exceptions can be thrown from this method:
NoSuchMethodException,
NullPointerException,
SecurityException,
IllegalAccessException,
IllegalArgumentException,
InvocationTargetException,
ExceptionInInitializerError.invoke(Class, Object, String, Object[])public static void addPath(String path)
addURL method from the
URLClassLoader class, in order to bypass the fact that it is
not possible to modify the classpath during runtime.
path - the path to add
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||