01: package net.sf.mockcreator.utils;
02:
03: import java.lang.reflect.Method;
04:
05: public class ReflectionUtils {
06: public static boolean methodExists(Class clz, String name,
07: Class[] params) {
08: try {
09: clz.getMethod(name, params);
10: return true;
11: } catch (SecurityException e) {
12: return false;
13: } catch (NoSuchMethodException e) {
14: return false;
15: }
16: }
17:
18: public static Object callMethod(Object obj, String name,
19: Class[] types, Object[] params) {
20: try {
21: Method m = obj.getClass().getMethod(name, types);
22: return m.invoke(obj, params);
23: } catch (Exception ex) {
24: throw new RuntimeException(ex);
25: }
26: }
27: }
|