1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package com.mjh.switchrmi;
27
28 import java.lang.reflect.*;
29
30 import java.util.*;
31
32 import org.apache.log4j.*;
33
34 public abstract class RmiInvocationHandlerBase
35 implements InvocationHandler
36 {
37 private static final Logger log =
38 Logger.getLogger(RmiInvocationHandlerBase.class.getName());
39 private static HashMap illegalMethods = new HashMap();
40
41 static
42 {
43 illegalMethods.put("toString", "x");
44 illegalMethods.put("wait", "x");
45 illegalMethods.put("clone", "x");
46 illegalMethods.put("getClass", "x");
47 illegalMethods.put("notify", "x");
48 illegalMethods.put("hashCode", "x");
49 illegalMethods.put("finalize", "x");
50 illegalMethods.put("equals", "x");
51 }
52
53 private Class[] interfaces;
54
55 public RmiInvocationHandlerBase(Class[] interfaces)
56 {
57 this.interfaces = interfaces;
58 }
59
60
63 public Object invoke(Object target, Method method, Object[] args)
64 throws Throwable
65 {
66 Object result = null;
67
68 if ((illegalMethods.get(method.getName()) != null)
69 || !methodIsInInterfaces(method))
70 {
71 return method.invoke(this, args);
72 }
73
74 return rmiInvoke(target, method, args);
75 }
76
77 public abstract Object rmiInvoke(Object target, Method method,
78 Object[] args)
79 throws Throwable;
80
81 private boolean methodIsInInterfaces(Method method)
82 {
83 boolean result = false;
84 Class declaringClass = method.getDeclaringClass();
85
86 for (int i = 0; i < interfaces.length; i++)
87 {
88 Class interfaze = interfaces[i];
89
90 result = interfaze.getName().equals(declaringClass.getName());
91
92 if (result == true)
93 {
94 break;
95 }
96 }
97
98 return result;
99 }
100 }