01: package org.gui4j.core.util;
02:
03: import java.io.IOException;
04: import java.io.ObjectInputStream;
05: import java.io.ObjectOutputStream;
06: import java.lang.reflect.InvocationTargetException;
07: import java.lang.reflect.Method;
08:
09: /**
10: * Entspricht der Klasse {@link java.lang.reflect.Method}, ausser
11: * dass diese Klasse serialisierbar ist.
12: */
13: final public class MethodCallReflection implements MethodCall {
14: private Method method;
15:
16: /**
17: * Constructor for MethodCall.
18: * @param method
19: */
20: private MethodCallReflection(Method method) {
21: this .method = method;
22: }
23:
24: public static MethodCall getInstance(Method method) {
25: return method == null ? null : new MethodCallReflection(method);
26: }
27:
28: public Object invoke(Object base, Object[] args)
29: throws InvocationTargetException, IllegalAccessException {
30: return method.invoke(base, args);
31: }
32:
33: public int getModifiers() {
34: return method.getModifiers();
35: }
36:
37: public Class getReturnType() {
38: return method.getReturnType();
39: }
40:
41: private void writeObject(ObjectOutputStream out) throws IOException {
42: out.writeObject(method.getDeclaringClass());
43: out.writeObject(method.getName());
44: out.writeObject(method.getParameterTypes());
45: }
46:
47: private void readObject(ObjectInputStream in) throws IOException,
48: ClassNotFoundException {
49: Class c = (Class) in.readObject();
50: String name = (String) in.readObject();
51: Class[] argTypes = (Class[]) in.readObject();
52: try {
53: method = c.getMethod(name, argTypes);
54: } catch (NoSuchMethodException e) {
55: // should not happen
56: e.printStackTrace();
57: assert false;
58: }
59: }
60:
61: public String toString() {
62: return method.toString();
63: }
64:
65: }
|