01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.com
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package org.huihoo.jfox.jmx;
09:
10: import java.lang.reflect.Method;
11:
12: /**
13: *
14: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
15: */
16:
17: public class MethodHelper {
18: public static boolean isGetterMethod(Method method) {
19: if (method == null)
20: return false;
21: String name = method.getName();
22: Class retType = method.getReturnType();
23: Class[] params = method.getParameterTypes();
24: if (retType != Void.TYPE && params.length == 0) {
25: if (name.startsWith("get") && name.length() > 3) {
26: return true;
27: }
28: if (name.startsWith("is")
29: && name.length() > 2
30: && (retType == Boolean.TYPE || retType
31: .equals(Boolean.class))) {
32: return true;
33: }
34: }
35: return false;
36: }
37:
38: public static boolean isSetterMethod(Method method) {
39: if (method == null) {
40: return false;
41: }
42: String name = method.getName();
43: Class retType = method.getReturnType();
44: Class[] params = method.getParameterTypes();
45: if (retType == Void.TYPE && params.length == 1
46: && name.startsWith("set") && name.length() > 3) {
47: return true;
48: }
49: return false;
50: }
51:
52: public static boolean maybeGetterMethod(String method,
53: String[] signature) {
54: if (signature == null || signature.length == 0) {
55: if ((method.startsWith("get") && method.length() > 3)
56: || (method.startsWith("is") && method.length() > 2)) {
57: return true;
58: }
59: }
60: return false;
61: }
62:
63: public static boolean maybeSetterMethod(String method,
64: String[] signature) {
65: if (signature != null && signature.length == 1) {
66: if (method.startsWith("set") && method.length() > 3) {
67: return true;
68: }
69: }
70: return false;
71: }
72: }
|