1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.core;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.springframework.util.MethodInvoker;
20 import org.springframework.util.ReflectionUtils;
21
22 import java.lang.reflect.Method;
23
24
25
26
27
28
29
30 public class MethodInvokerConfig extends MethodInvoker {
31
32 private String staticMethod;
33 private Class[] argumentTypes;
34
35
36
37
38
39
40
41 @Override
42 public void setStaticMethod(String staticMethod) {
43 super.setStaticMethod(staticMethod);
44 }
45
46
47
48
49
50
51
52 public Class[] getArgumentTypes() {
53 if (argumentTypes == null) {
54 return getMethodArgumentTypes();
55 }
56
57 return argumentTypes;
58 }
59
60
61
62
63
64
65 public void setArgumentTypes(Class[] argumentTypes) {
66 this.argumentTypes = argumentTypes;
67 }
68
69
70
71
72
73
74
75 protected Class[] getMethodArgumentTypes() {
76 if (StringUtils.isNotBlank(staticMethod)) {
77 int lastDotIndex = this.staticMethod.lastIndexOf('.');
78 if (lastDotIndex == -1 || lastDotIndex == this.staticMethod.length()) {
79 throw new IllegalArgumentException("staticMethod must be a fully qualified class plus method name: " +
80 "e.g. 'example.MyExampleClass.myExampleMethod'");
81 }
82 String className = this.staticMethod.substring(0, lastDotIndex);
83 String methodName = this.staticMethod.substring(lastDotIndex + 1);
84 try {
85 setTargetClass(resolveClassName(className));
86 } catch (ClassNotFoundException e) {
87 throw new RuntimeException("Unable to get class for name: " + className);
88 }
89 setTargetMethod(methodName);
90 }
91
92 Method[] candidates = ReflectionUtils.getAllDeclaredMethods(getTargetClass());
93 for (Method candidate : candidates) {
94 if (candidate.getName().equals(getTargetMethod())) {
95 return candidate.getParameterTypes();
96 }
97 }
98
99 return null;
100 }
101 }