01: package net.sourceforge.jaxor.tests;
02:
03: import junit.framework.Assert;
04: import net.sourceforge.jaxor.util.NullProxy;
05: import net.sourceforge.jaxor.util.SystemException;
06:
07: import java.lang.reflect.Method;
08:
09: /*
10: * User: Mike
11: * Date: Oct 18, 2002
12: * Time: 9:38:00 PM
13: */
14:
15: public class Invoker {
16:
17: public static void invoke(Object set) {
18: Class[] interfaces = set.getClass().getInterfaces();
19: for (int j = 0; j < interfaces.length; j++) {
20: Class inter = interfaces[j];
21: Method[] methods = inter.getMethods();
22: for (int i = 0; i < methods.length; i++) {
23: Method method = methods[i];
24: Class[] params = method.getParameterTypes();
25: Object[] args = createArgs(params);
26: Assert.assertNotNull("method cannot be null", method);
27: try {
28: method.invoke(set, args);
29: } catch (Exception e) {
30: throw new SystemException(method.getName(), e);
31: }
32: }
33: }
34: }
35:
36: private static Object[] createArgs(Class[] params) {
37: Object[] args = new Object[params.length];
38: for (int i = 0; i < args.length; i++) {
39: Class param = params[i];
40: args[i] = NullProxy.getDefaultInstance(param);
41: }
42: return args;
43: }
44:
45: }
|