1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 package org.melati.poem.prepro;
47
48
49
50
51
52
53
54
55
56
57 public class TableNamingInfo {
58
59 static final String POEM = "org.melati.poem";
60
61
62 public String packageName = null;
63
64
65 public String objectFQName = null;
66
67
68 public String capitalisedShortName = null;
69
70
71
72
73 public TableNamingInfo superclass = null;
74
75
76
77
78
79
80
81
82
83
84
85 public boolean hidesOther = false;
86
87
88
89
90
91
92
93
94
95
96
97
98 public boolean hidden = false;
99
100 public String projectName;
101
102 public TableNamingInfo extended;
103
104
105
106
107
108
109
110 public TableNamingInfo(String packageNameIn, String projectNameIn, String nameFromDsd) {
111 packageName = packageNameIn;
112 projectName = projectNameIn;
113 capitalisedShortName = nameFromDsd.substring(0,1).toUpperCase() + nameFromDsd.substring(1);
114 objectFQName = packageName + "." + capitalisedShortName;
115 superclass = null;
116 hidesOther = false;
117 hidden = false;
118 }
119
120
121
122
123
124
125 public String superclassMainUnambiguous() {
126 return (superclass == null)
127 ? "JdbcPersistent"
128 : superclass.mainClassUnambiguous();
129 }
130
131
132
133
134
135
136 public String superclassMainFQName() {
137 return (superclass == null)
138 ? "org.melati.poem.JdbcPersistent"
139 : superclass.mainClassFQName();
140 }
141
142
143
144
145
146
147 public String superclassMainShortName() {
148 return (superclass == null)
149 ? "JdbcPersistent"
150 : superclass.mainClassShortName();
151 }
152
153
154
155
156
157
158 public String superclassTableUnambiguous() {
159 return (superclass == null)
160 ? getTableClassName()
161 : superclass.tableMainClassUnambiguous();
162 }
163
164 private String getTableClassName() {
165 return projectName + "Table";
166 }
167
168
169
170
171
172
173 public String superclassTableFQName() {
174 return (superclass == null)
175 ? packageName + "." + getTableClassName()
176 : superclass.tableMainClassFQName();
177 }
178
179
180
181
182
183 public String superclassTableShortName() {
184 return (superclass == null)
185 ? getTableClassName()
186 : superclass.tableMainClassShortName();
187 }
188
189 String importMainString() {
190
191
192 return "import " + mainClassFQName() + ";\n";
193 }
194
195 String importTableString() {
196
197
198 return "import " + tableMainClassFQName() + ";\n";
199 }
200 String importPersistentString() {
201 return (hidden) ?
202 "// hidden import " + mainClassFQName() + ";\n"
203 : "import " + mainClassFQName() + ";\n" ;
204 }
205
206 String baseClassFQName() {
207 return packageName + ".generated." + capitalisedShortName + "Base";
208 }
209
210 String baseClassShortName() {
211 return capitalisedShortName + "Base";
212 }
213
214 String baseClassUnambiguous() {
215 return (hidden)
216 ? baseClassFQName()
217 : baseClassShortName();
218 }
219
220
221
222
223 public String mainClassFQName() {
224 return objectFQName;
225 }
226
227
228
229
230 public String mainClassShortName() {
231 return StringUtils.capitalised(capitalisedShortName);
232 }
233
234
235
236
237
238 public String mainClassUnambiguous() {
239 return (hidden || hidesOther)
240 ? mainClassFQName()
241 : mainClassShortName();
242 }
243
244
245
246
247
248
249
250
251
252 public String mainClassRootReturnClass() {
253 TableNamingInfo root = getRootSameNamedSuperclass();
254 return (root != null)
255 ? root.mainClassUnambiguous()
256 : mainClassUnambiguous();
257 }
258
259 String tableBaseClassFQName() {
260 return packageName + ".generated." + capitalisedShortName + "TableBase";
261 }
262 String tableBaseClassShortName() {
263 return capitalisedShortName + "TableBase";
264 }
265
266 String tableBaseClassUnambiguous() {
267 return (hidden)
268 ? tableBaseClassFQName()
269 : tableBaseClassShortName();
270 }
271
272 String tableMainClassFQName() {
273 return objectFQName + "Table";
274 }
275 String tableMainClassShortName() {
276 return capitalisedShortName + "Table";
277 }
278 String subclassedTableMainClassShortName() {
279 return projectName + capitalisedShortName + "Table";
280 }
281
282 String tableMainClassUnambiguous() {
283 return (hidden || hidesOther)
284 ? tableMainClassFQName()
285 : tableMainClassShortName();
286 }
287
288
289
290
291
292
293
294
295
296
297
298
299 public String tableMainClassRootReturnClass() {
300 TableNamingInfo root = getRootSameNamedSuperclass();
301 return (root != null)
302 ? root.tableMainClassUnambiguous()
303 : tableMainClassUnambiguous();
304 }
305
306 String rootTableAccessorName() {
307 return "get" + tableMainClassShortName();
308 }
309 public String leafTableAccessorName() {
310 if (hidesOther)
311 return "get" + projectName + tableMainClassShortName();
312 else
313 return "get" + tableMainClassShortName();
314 }
315
316
317
318
319
320 protected TableNamingInfo getRootSameNamedSuperclass() {
321 TableNamingInfo curr = this;
322 while (curr != null && curr.superclass != null &&
323 curr.capitalisedShortName.equals(curr.superclass.capitalisedShortName))
324 curr = curr.superclass;
325 return (curr != this) ? curr : null;
326 }
327
328 }
329