1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.reflexiveframework.proxy;
25
26 import org.apache.commons.lang.Validate;
27
28 /***
29 * Common static utility class.
30 * To be used internally only
31 *
32 * @author Andries Inze
33 *
34 */
35 final class ReflexiveUtils {
36
37 /***
38 * Utility methods need private constructors.
39 */
40 private ReflexiveUtils() {
41
42 }
43
44 /***
45 * Converts a getter into the property name.
46 * e.g.
47 * 'getNickName' will be converted into 'nickName'
48 *
49 * @param methodName the full methodName
50 * @return the propertyName
51 */
52 public static String convertMethodNameToPropertyName(
53 final String methodName) {
54 Validate.notNull(methodName, "The methodName can not be null");
55 Validate.isTrue(methodName.startsWith("get")
56 || methodName.startsWith("is"), "Only getters are supported");
57
58 StringBuilder sb = new StringBuilder(methodName);
59 if (methodName.startsWith("get")) {
60 sb.delete(0, 3);
61 } else {
62 sb.delete(0, 2);
63 }
64 sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
65 return sb.toString();
66
67 }
68
69 /***
70 * @return
71 */
72 public static String createRandomString() {
73 return "" + System.currentTimeMillis();
74 }
75
76 public static String makeNestedPath(String[] propertyNames) {
77 StringBuilder sb = new StringBuilder();
78
79 for (int i = 0; i < propertyNames.length; i++) {
80 sb.append(propertyNames[i]);
81 if(i < propertyNames.length-1) {
82 sb.append(".");
83 }
84 }
85
86 return sb.toString();
87 }
88
89 public static String makeNestedPath(String propertyName) {
90 return makeNestedPath(new String[] { propertyName });
91 }
92 }