1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.devtools.generators.mo;
17
18 import java.util.Arrays;
19 import java.util.List;
20
21
22
23
24
25
26
27 final class Util {
28
29 static final String VERSION_NUMBER_FIELD = "versionNumber";
30 static final String OBJECT_ID_FIELD = "objectId";
31
32 static final String CONSTANTS_CLASS_NAME = "Constants";
33 static final String ROOT_ELEMENT_NAME_FIELD = "ROOT_ELEMENT_NAME";
34 static final String TYPE_NAME_FIELD = "TYPE_NAME";
35 static final String TYPE_NAME_SUFFIX = "Type";
36 static final String HASH_CODE_EQUALS_EXCLUDE_FIELD = "HASH_CODE_EQUALS_EXCLUDE";
37 static final String COMMON_ELEMENTS_CLASS = "CommonElements";
38 static final String FUTURE_ELEMENTS_FIELD = "FUTURE_ELEMENTS";
39 static final String CONSTANTS_CLASS_JAVADOC = "Defines some internal constants used on this class.";
40
41 static final String ELEMENTS_CLASS_NAME = "Elements";
42 static final String ELEMENTS_CLASS_JAVADOC = "A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.";
43 static final List<String> COMMON_ELEMENTS = Arrays.asList(VERSION_NUMBER_FIELD, OBJECT_ID_FIELD);
44
45 static final String BUILDER_CLASS_NAME = "Builder";
46
47 static String toLowerCaseFirstLetter(String value) {
48 return value.substring(0, 1).toLowerCase() + value.substring(1);
49 }
50
51 static String toUpperCaseFirstLetter(String value) {
52 return value.substring(0, 1).toUpperCase() + value.substring(1);
53 }
54
55 static String toConstantsVariable(String fieldName) {
56 StringBuilder constantVariable = new StringBuilder();
57
58 fieldName = toLowerCaseFirstLetter(fieldName);
59 StringBuilder segAccum = new StringBuilder();
60 for (char character : fieldName.toCharArray()) {
61 if (Character.isUpperCase(character)) {
62 constantVariable.append(segAccum.toString().toUpperCase());
63 constantVariable.append("_");
64 segAccum = new StringBuilder();
65 }
66 segAccum.append(character);
67 }
68
69 constantVariable.append(segAccum.toString().toUpperCase());
70 return constantVariable.toString();
71 }
72
73 static String generateGetterName(String fieldName, boolean is) {
74 return (is ? "is" : "get") + Util.toUpperCaseFirstLetter(fieldName);
75 }
76
77 static String generateGetter(String fieldName, boolean is) {
78 return generateGetterName(fieldName, is) + "()";
79 }
80
81 static String generateSetterName(String fieldName) {
82 return "set" + Util.toUpperCaseFirstLetter(fieldName);
83 }
84
85 static String generateSetter(String fieldName, String valueToSet) {
86 return generateSetterName(fieldName) + "(" + valueToSet + ")";
87 }
88
89
90 static boolean isCommonElement(String fieldName) {
91 return COMMON_ELEMENTS.contains(fieldName);
92 }
93
94 static String generateBuilderJavadoc(String simpleClassName, String simpleContractClassName) {
95 return "A builder which can be used to construct {@link " + simpleClassName + "} instances. " +
96 "Enforces the constraints of the {@link " + simpleContractClassName + "}.";
97 }
98
99 }