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