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