01: package org.mockejb;
02:
03: import java.lang.reflect.*;
04: import java.util.*;
05:
06: /**
07: * @author Alexander Ananiev
08: */
09: class MethodContainer {
10: private Class claz;
11:
12: Map methods = new HashMap();
13:
14: MethodContainer(final Class claz) {
15: this .claz = claz;
16: }
17:
18: void add(String name, Class[] argTypes) {
19: try {
20:
21: //Class [] noArg = {};
22: methods.put(name, claz.getMethod(name, argTypes));
23: }
24: // to be able to use this method from the static initializer we must not throw Exception
25: catch (NoSuchMethodException noMethodEx) {
26: throw new RuntimeException(
27: "Fatal error: standard method is not found: "
28: + noMethodEx.getMessage());
29: }
30:
31: }
32:
33: void add(String name) {
34: Class[] noArg = {};
35: add(name, noArg);
36: }
37:
38: // TODO: currently argTypes is ignored
39: Method find(String name, Class[] argTypes) {
40: return (Method) methods.get(name);
41: }
42:
43: Method find(Method method) {
44: return find(method.getName(), method.getParameterTypes());
45: }
46:
47: }
|