1 package nl.tudelft.simulation.language.reflection;
2
3 import java.io.IOException;
4 import java.io.ObjectOutputStream;
5 import java.io.Serializable;
6 import java.lang.reflect.Method;
7
8 import org.djutils.reflection.ClassUtil;
9 import org.djutils.reflection.MethodSignature;
10
11
12
13
14
15
16
17
18
19
20
21
22 public class SerializableMethod implements Serializable
23 {
24
25 private Method method = null;
26
27
28
29
30
31 public SerializableMethod(final Method method)
32 {
33 super();
34 this.method = method;
35 }
36
37
38
39
40
41
42
43
44 public SerializableMethod(final Class<?> clazz, final String methodName, final Class<?>... parameterTypes)
45 throws NoSuchMethodException
46 {
47 this.method = ClassUtil.resolveMethod(clazz, methodName, parameterTypes);
48 }
49
50
51
52
53
54 public Method deSerialize()
55 {
56 return this.method;
57 }
58
59
60
61
62
63
64 private void writeObject(final ObjectOutputStream out) throws IOException
65 {
66 try
67 {
68 out.writeObject(this.method.getDeclaringClass());
69 out.writeObject(this.method.getName());
70 out.writeObject(new MethodSignature(this.method));
71 }
72 catch (Exception exception)
73 {
74 throw new IOException(exception.getMessage());
75 }
76 }
77
78
79
80
81
82
83 private void readObject(final java.io.ObjectInputStream in) throws IOException
84 {
85 try
86 {
87 Class<?> declaringClass = (Class<?>) in.readObject();
88 String methodName = (String) in.readObject();
89 MethodSignature signature = (MethodSignature) in.readObject();
90 this.method = ClassUtil.resolveMethod(declaringClass, methodName, signature.getParameterTypes());
91 }
92 catch (Exception exception)
93 {
94 throw new IOException(exception.getMessage());
95 }
96 }
97 }