|
@@ -1,529 +1,529 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.generator; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.aokeyhole.objects.*; |
5 |
|
- |
import org.litesoft.aokeyhole.objects.AttributeMetaData; |
6 |
|
- |
import org.litesoft.aokeyhole.objects.attributes.*; |
7 |
|
- |
import org.litesoft.aokeyhole.objects.properties.*; |
8 |
|
- |
import org.litesoft.aokeyhole.objects.support.*; |
9 |
|
- |
import org.litesoft.bo.*; |
10 |
|
- |
import org.litesoft.bo.attributes.*; |
11 |
|
- |
import org.litesoft.codegen.*; |
12 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
13 |
|
- |
import org.litesoft.commonfoundation.typeutils.Objects; |
14 |
|
- |
import org.litesoft.core.simpletypes.currency.*; |
15 |
|
- |
import org.litesoft.core.simpletypes.temporal.*; |
16 |
|
- |
|
17 |
|
- |
import java.util.*; |
18 |
|
- |
|
19 |
|
- |
public abstract class AbstractTypeFileGenerator extends SourceCodeGenerator { |
20 |
|
- |
protected interface AttributeProxy extends MinimalAttributeMetaData, |
21 |
|
- |
HasValidOptions { |
22 |
|
- |
boolean isInjected(); |
23 |
|
- |
|
24 |
|
- |
String getDerivedFromAttribute(); |
25 |
|
- |
|
26 |
|
- |
String getColumnName(); |
27 |
|
- |
|
28 |
|
- |
Mutability getMutability(); |
29 |
|
- |
|
30 |
|
- |
boolean isSysSetOnly(); |
31 |
|
- |
|
32 |
|
- |
Class getSimpleDataType(); |
33 |
|
- |
|
34 |
|
- |
BoAttribute.AttributeType getBoAttributeType(); |
35 |
|
- |
|
36 |
|
- |
boolean isRequired(); |
37 |
|
- |
|
38 |
|
- |
boolean isQueryView(); |
39 |
|
- |
|
40 |
|
- |
String getToManyFullyQualifiedName(); |
41 |
|
- |
|
42 |
|
- |
boolean isToManyInstantiable(); |
43 |
|
- |
|
44 |
|
- |
String getToManyBackReference(); |
45 |
|
- |
|
46 |
|
- |
AttributeProxy getToManyBackReferenceAttributeProxy(); |
47 |
|
- |
|
48 |
|
- |
String getToOneFullyQualifiedName(); |
49 |
|
- |
|
50 |
|
- |
boolean isToOneInstantiable(); |
51 |
|
- |
|
52 |
|
- |
String getToOneBackReference(); |
53 |
|
- |
|
54 |
|
- |
@SuppressWarnings({"UnusedDeclaration"}) |
55 |
|
- |
AttributeProxy getToOneBackReferenceAttributeProxy(); |
56 |
|
- |
} |
57 |
|
- |
|
58 |
|
- |
protected final ErrorSinc mErrorSinc; |
59 |
|
- |
protected final ObjectRef mObjectRef, mParentObjectRef; |
60 |
|
- |
protected final ObjectMetaData mObjectMetaData; |
61 |
|
- |
protected final String mPackage, mObjectName, mClassName; |
62 |
|
- |
protected final boolean mIsParent; |
63 |
|
- |
|
64 |
|
- |
public AbstractTypeFileGenerator( String pReportingType, ErrorSinc pErrorSinc, ObjectMetaData pObjectMetaData, ObjectRef pObjectRef, String pTypeExtension, |
65 |
|
- |
ObjectRef pParentObjectRef, boolean pIsParent ) { |
66 |
|
- |
super( pReportingType, pObjectRef.getFullFolderPath() + "/" + pObjectMetaData.getName() + pTypeExtension + ".java" ); |
67 |
|
- |
mErrorSinc = pErrorSinc; |
68 |
|
- |
mObjectRef = pObjectRef; |
69 |
|
- |
mParentObjectRef = pParentObjectRef; |
70 |
|
- |
mPackage = pObjectRef.getPackage(); |
71 |
|
- |
mClassName = (mObjectName = (mObjectMetaData = pObjectMetaData).getName()) + pTypeExtension; |
72 |
|
- |
mIsParent = pIsParent; |
73 |
|
- |
setOverwrite( mClassName.endsWith( "GO" ) ); |
74 |
|
- |
} |
75 |
|
- |
|
76 |
|
- |
public final SourceCodeGenerator generate() { |
77 |
|
- |
addPackage( mPackage ); |
78 |
|
- |
|
79 |
|
- |
LLaddImports(); |
80 |
|
- |
|
81 |
|
- |
LLaddClassDefinition(); |
82 |
|
- |
|
83 |
|
- |
LLaddClassBody(); |
84 |
|
- |
|
85 |
|
- |
addClassEnd(); |
86 |
|
- |
|
87 |
|
- |
return this; |
88 |
|
- |
} |
89 |
|
- |
|
90 |
|
- |
protected String getExtends( String pNoParentClassPrefix ) { |
91 |
|
- |
if ( mParentObjectRef == null ) { |
92 |
|
- |
return pNoParentClassPrefix; |
93 |
|
- |
} |
94 |
|
- |
return removePackageIfPossible( mParentObjectRef.getFullyQualifiedName() ); |
95 |
|
- |
} |
96 |
|
- |
|
97 |
|
- |
protected String removePackageIfPossible( String pFullyQualifiedName ) { |
98 |
|
- |
int zDotAt = pFullyQualifiedName.lastIndexOf( '.' ); |
99 |
|
- |
if ( (zDotAt != -1) && mPackage.equals( pFullyQualifiedName.substring( 0, zDotAt ) ) ) { |
100 |
|
- |
pFullyQualifiedName = pFullyQualifiedName.substring( zDotAt + 1 ); |
101 |
|
- |
} |
102 |
|
- |
return pFullyQualifiedName; |
103 |
|
- |
} |
104 |
|
- |
|
105 |
|
- |
protected void LLaddImports() { |
106 |
|
- |
} |
107 |
|
- |
|
108 |
|
- |
abstract protected void LLaddClassDefinition(); |
109 |
|
- |
|
110 |
|
- |
protected void LLaddClassBody() { |
111 |
|
- |
} |
112 |
|
- |
|
113 |
|
- |
abstract protected AttributeProxy[] getAttributes(); |
114 |
|
- |
|
115 |
|
- |
protected static Mutability convertToMutability( AttributeMetaData pAttribute ) { |
116 |
|
- |
AttributeType zType = pAttribute.getAttributeSet().getType(); |
117 |
|
- |
if ( A_ID.TYPE.equals( zType ) ) { |
118 |
|
- |
return Mutability.AddOnly; |
119 |
|
- |
} |
120 |
|
- |
String zChangeable = pAttribute.getPropertyManager().get_String( PMD_Changeable.NAME, "" ).trim(); |
121 |
|
- |
if ( PMD_Changeable.ADD_ONLY.equals( zChangeable ) ) { |
122 |
|
- |
return Mutability.AddOnly; |
123 |
|
- |
} |
124 |
|
- |
if ( PMD_Changeable.READ_ONLY.equals( zChangeable ) ) { |
125 |
|
- |
return Mutability.RO; |
126 |
|
- |
} |
127 |
|
- |
return Mutability.RW; |
128 |
|
- |
} |
129 |
|
- |
|
130 |
|
- |
protected BoAttribute.AttributeType getType( MinimalAttributeMetaData pAttribute ) { |
131 |
|
- |
AttributeType zAttributeType = pAttribute.getAttributeSetType(); |
132 |
|
- |
if ( zAttributeType.getFAT().isSimple() ) { |
133 |
|
- |
Class zTypeClass = zAttributeType.getSimpleDataType(); |
134 |
|
- |
if ( zTypeClass == null ) { |
135 |
|
- |
mErrorSinc.addError( "CurrentlyUnsupportedAttributeType", pAttribute.toString(), mObjectMetaData.toStringForError() ); |
136 |
|
- |
} else { |
137 |
|
- |
String zType = zTypeClass.getName(); |
138 |
|
- |
int zAt = zType.lastIndexOf( '.' ); |
139 |
|
- |
if ( zAt != -1 ) { |
140 |
|
- |
zType = zType.substring( zAt + 1 ); |
141 |
|
- |
} |
142 |
|
- |
try { |
143 |
|
- |
return BoAttribute.AttributeType.valueOf( zType ); |
144 |
|
- |
} |
145 |
|
- |
catch ( IllegalArgumentException e ) { |
146 |
|
- |
mErrorSinc.addError( "CurrentlyUnsupportedAttributeType", "of: " + zType, pAttribute.toString(), mObjectMetaData.toStringForError() ); |
147 |
|
- |
} |
148 |
|
- |
} |
149 |
|
- |
} |
150 |
|
- |
return null; |
151 |
|
- |
} |
152 |
|
- |
|
153 |
|
- |
protected void addNotes( String pNotes ) { |
154 |
|
- |
if ( Strings.isNotNullOrEmpty( pNotes ) ) { |
155 |
|
- |
addLine( "/**" ); |
156 |
|
- |
String[] zLines = Strings.parseChar( Strings.normalizeNewLines( pNotes ), '\n' ); |
157 |
|
- |
for ( String zLine : zLines ) { |
158 |
|
- |
addLine( " " + ("* " + zLine).trim() ); |
159 |
|
- |
} |
160 |
|
- |
addLine( " */" ); |
161 |
|
- |
} |
162 |
|
- |
} |
163 |
|
- |
|
164 |
|
- |
protected String adjustOptionForName( String pOption ) { |
165 |
|
- |
StringBuilder rv = new StringBuilder( pOption ); |
166 |
|
- |
for ( int i = 0; i < rv.length(); i++ ) { |
167 |
|
- |
char c = rv.charAt( i ); |
168 |
|
- |
if ( (c != '_') && !Characters.isAlphaNumeric( c ) ) { |
169 |
|
- |
rv.setCharAt( i, '_' ); |
170 |
|
- |
} |
171 |
|
- |
} |
172 |
|
- |
return rv.toString(); |
173 |
|
- |
} |
174 |
|
- |
|
175 |
|
- |
private static Map<ObjectMetaData, List<AttributeProxy>> sInjectedAttributes = new HashMap<ObjectMetaData, List<AttributeProxy>>(); |
176 |
|
- |
|
177 |
|
- |
protected synchronized List<AttributeProxy> getInjectedAttributes( ObjectMetaData pObjectMetaData ) { |
178 |
|
- |
List<AttributeProxy> zInjectedAttributes = sInjectedAttributes.get( pObjectMetaData ); |
179 |
|
- |
if ( zInjectedAttributes == null ) { |
180 |
|
- |
sInjectedAttributes.put( pObjectMetaData, zInjectedAttributes = createInjectedAttributes( pObjectMetaData ) ); |
181 |
|
- |
} |
182 |
|
- |
return zInjectedAttributes; |
183 |
|
- |
} |
184 |
|
- |
|
185 |
|
- |
protected List<AttributeProxy> createInjectedAttributes( ObjectMetaData pObjectMetaData ) { |
186 |
|
- |
String zTimeTracked = pObjectMetaData.getPropertyManager().get_String( PMD_TimeTracked.NAME, PMD_TimeTracked.NONE ); |
187 |
|
- |
if ( PMD_TimeTracked.NONE.equals( zTimeTracked ) ) { |
188 |
|
- |
return Collections.emptyList(); |
189 |
|
- |
} |
190 |
|
- |
ArrayList<AttributeProxy> zInjected = new ArrayList<AttributeProxy>(); |
191 |
|
- |
if ( PMD_TimeTracked.CREATED.equals( zTimeTracked ) || PMD_TimeTracked.BOTH.equals( zTimeTracked ) ) { |
192 |
|
- |
zInjected.add( IAP_CREATED ); |
193 |
|
- |
} |
194 |
|
- |
if ( PMD_TimeTracked.LAST_MOD.equals( zTimeTracked ) || PMD_TimeTracked.BOTH.equals( zTimeTracked ) ) { |
195 |
|
- |
zInjected.add( IAP_LAST_MOD ); |
196 |
|
- |
} |
197 |
|
- |
return zInjected; |
198 |
|
- |
} |
199 |
|
- |
|
200 |
|
- |
protected MinimalAttributeMetaData getRegularOrInjectedAttribute( ObjectMetaData pObjectMetaData, String pAttrName ) { |
201 |
|
- |
AttributeMetaData zAMD = pObjectMetaData.getAttribute( pAttrName ); |
202 |
|
- |
if ( zAMD != null ) { |
203 |
|
- |
return zAMD; |
204 |
|
- |
} |
205 |
|
- |
List<AttributeProxy> zInjectedAttributes = getInjectedAttributes( pObjectMetaData ); |
206 |
|
- |
for ( AttributeProxy zAttribute : zInjectedAttributes ) { |
207 |
|
- |
if ( zAttribute.getName().equals( pAttrName ) ) { |
208 |
|
- |
return zAttribute; |
209 |
|
- |
} |
210 |
|
- |
} |
211 |
|
- |
return null; |
212 |
|
- |
} |
213 |
|
- |
|
214 |
|
- |
protected MinimalAttributeMetaData getAttribute( ObjectMetaData pObjectMetaData, String pAttrName ) { |
215 |
|
- |
while ( pObjectMetaData != null ) { |
216 |
|
- |
MinimalAttributeMetaData zAMD = getRegularOrInjectedAttribute( pObjectMetaData, pAttrName ); |
217 |
|
- |
if ( zAMD != null ) { |
218 |
|
- |
return zAMD; |
219 |
|
- |
} |
220 |
|
- |
String zParentName = Strings.noEmpty( pObjectMetaData.getParentName() ); |
221 |
|
- |
SystemMetaData zSystemMetaData = pObjectMetaData.getSystemMetaData(); |
222 |
|
- |
pObjectMetaData = ((zSystemMetaData != null) && (zParentName != null)) ? zSystemMetaData.getObject( zParentName ) : null; |
223 |
|
- |
} |
224 |
|
- |
return null; |
225 |
|
- |
} |
226 |
|
- |
|
227 |
|
- |
protected SystemMetaData getSystemMetaData( MetaDataOwner pOwner ) { |
228 |
|
- |
while ( pOwner instanceof AbstractNamedMetaData ) { |
229 |
|
- |
pOwner = ((AbstractNamedMetaData) pOwner).getOwner(); |
230 |
|
- |
} |
231 |
|
- |
return (pOwner instanceof SystemMetaData) ? (SystemMetaData) pOwner : null; |
232 |
|
- |
} |
233 |
|
- |
|
234 |
|
- |
protected void LLaddAttributes( boolean pAddBlank ) { |
235 |
|
- |
for ( AttributeProxy zAttribute : getAttributes() ) { |
236 |
|
- |
if ( pAddBlank ) { |
237 |
|
- |
addBlankLine(); |
238 |
|
- |
} |
239 |
|
- |
pAddBlank = true; |
240 |
|
- |
LLaddAttribute( zAttribute ); |
241 |
|
- |
} |
242 |
|
- |
} |
243 |
|
- |
|
244 |
|
- |
protected void addPSFSattributeValidOptions( AttributeProxy pAttribute, String pPOorVO ) { |
245 |
|
- |
String[] zOptions = pAttribute.getValidOptions(); |
246 |
|
- |
if ( Objects.isNotNullOrEmpty( zOptions ) && (zOptions.length < 10) ) { |
247 |
|
- |
addBlankLine(); |
248 |
|
- |
for ( String zOption : zOptions ) { |
249 |
|
- |
if ( Strings.isNotNullOrEmpty( zOption ) ) { |
250 |
|
- |
addPSFS( pPOorVO + pAttribute.getName() + "_" + adjustOptionForName( zOption ), zOption ); |
251 |
|
- |
} |
252 |
|
- |
} |
253 |
|
- |
} |
254 |
|
- |
} |
255 |
|
- |
|
256 |
|
- |
protected void LLaddAttribute( AttributeProxy zAttribute ) { |
257 |
|
- |
} |
258 |
|
- |
|
259 |
|
- |
protected String createAttributeTypedCall( AttributeProxy pAttribute, String pPOorVO, String pBaseLine, String pLineTerminator ) { |
260 |
|
- |
String zName = pAttribute.getName(); |
261 |
|
- |
|
262 |
|
- |
Mutability zMutability = pAttribute.getMutability(); |
263 |
|
- |
|
264 |
|
- |
String zRequired = pAttribute.isRequired() ? ", true" : ", false"; |
265 |
|
- |
|
266 |
|
- |
BoAttribute.AttributeType zType = pAttribute.getBoAttributeType(); |
267 |
|
- |
if ( zType == null ) { |
268 |
|
- |
mErrorSinc.addError( pPOorVO + " CurrentlyUnsupportedAttributeType", "of: " + pAttribute.getAttributeSetType(), pAttribute.toString(), |
269 |
|
- |
mObjectMetaData.toStringForError() ); |
270 |
|
- |
zType = BoAttribute.AttributeType.String; |
271 |
|
- |
} |
272 |
|
- |
|
273 |
|
- |
AttributeType zAttributeType = pAttribute.getAttributeSetType(); |
274 |
|
- |
String zEnumType = zType.toString(); |
275 |
|
- |
|
276 |
|
- |
PropertyManager zPM = pAttribute.getPropertyManager(); |
277 |
|
- |
List<String> zProperties = new ArrayList<String>(); |
278 |
|
- |
|
279 |
|
- |
String[] zOptions = pAttribute.getValidOptions(); |
280 |
|
- |
if ( zOptions != null ) { |
281 |
|
- |
zProperties.add( "Options.of( sValidOptions" + zName + " )" ); |
282 |
|
- |
zEnumType = (zAttributeType instanceof HasOpenOption) ? "OpenValidOptions" : "ValidOptions"; |
283 |
|
- |
} else if ( zAttributeType instanceof AbstractArrayOptionsAttributeTypeSimple ) { |
284 |
|
- |
String zArrayRef = Strings.noEmpty( zPM.get_String( PMD_FullyQualifiedStringArrayPath.NAME, "" ) ); |
285 |
|
- |
if ( zArrayRef == null ) { |
286 |
|
- |
mErrorSinc.addError( "AttributeStringArrayPath", "Missing", pAttribute.toString(), mObjectMetaData.toStringForError() ); |
287 |
|
- |
} |
288 |
|
- |
zProperties.add( "Options.of( " + zArrayRef + " )" ); |
289 |
|
- |
zEnumType = (zAttributeType instanceof HasOpenOption) ? "OpenValidOptions" : "ValidOptions"; |
290 |
|
- |
} else if ( A_Password.TYPE.equals( zAttributeType ) ) { |
291 |
|
- |
zEnumType = "Password"; |
292 |
|
- |
} else if ( A_Text.TYPE.equals( zAttributeType ) ) { |
293 |
|
- |
zEnumType = "Text"; |
294 |
|
- |
} |
295 |
|
- |
String zProperty = noEmpty( zPM.getProperty( PMD_Case.NAME ) ); |
296 |
|
- |
if ( zProperty != null ) { |
297 |
|
- |
zProperties.add( PMD_Case.NAME + "." + zProperty ); |
298 |
|
- |
} |
299 |
|
- |
// Will be rendered in REVERSE order |
300 |
|
- |
add( zProperties, zPM, PMD_DisplayLength.NAME, "DisplayLength" ); |
301 |
|
- |
add( zProperties, zPM, PMD_MaxLength.NAME, "MaxLength" ); |
302 |
|
- |
add( zProperties, zPM, PMD_DisplayHeightInitial.NAME, "DisplayHeightInitial" ); |
303 |
|
- |
add( zProperties, zPM, PMD_DisplayWidthInitial.NAME, "DisplayWidthInitial" ); |
304 |
|
- |
|
305 |
|
- |
pBaseLine += zRequired + ", _" + zEnumType; |
306 |
|
- |
if ( !Mutability.RW.equals( zMutability ) ) { |
307 |
|
- |
pBaseLine += "." + zMutability + "()"; |
308 |
|
- |
} |
309 |
|
- |
if ( zProperties.isEmpty() ) { |
310 |
|
- |
addLine( pBaseLine + " )" + pLineTerminator ); |
311 |
|
- |
} else { |
312 |
|
- |
pBaseLine += ".with( "; |
313 |
|
- |
int i = zProperties.size(); |
314 |
|
- |
if ( i == 1 ) { |
315 |
|
- |
addLine( pBaseLine + zProperties.get( --i ) + " ) )" + pLineTerminator ); |
316 |
|
- |
} else { |
317 |
|
- |
String zPadding = Strings.spaces( pBaseLine.length() ); |
318 |
|
- |
addLine( pBaseLine + zProperties.get( --i ) + ", //" ); |
319 |
|
- |
while ( i > 1 ) { |
320 |
|
- |
addLine( zPadding + zProperties.get( --i ) + ", //" ); |
321 |
|
- |
} |
322 |
|
- |
addLine( zPadding + zProperties.get( --i ) + " ) )" + pLineTerminator ); |
323 |
|
- |
} |
324 |
|
- |
} |
325 |
|
- |
String zTypeExtra = ""; |
326 |
|
- |
if ( Money.class.equals( zType.getType() ) ) { |
327 |
|
- |
zTypeExtra = "org.litesoft.core.simpletypes.currency.Currency.US, "; |
328 |
|
- |
} else if ( CalendarYMD.class.equals( zType.getType() ) ) { |
329 |
|
- |
zTypeExtra = "org.litesoft.core.simpletypes.temporal.DateFormatControl.DEFAULT_YMD_FORMAT, "; |
330 |
|
- |
} else if ( SimpleTime.class.equals( zType.getType() ) ) { |
331 |
|
- |
zTypeExtra = "org.litesoft.core.simpletypes.temporal.TimeRes.ToMIN, "; |
332 |
|
- |
} else if ( SimpleTimestamp.class.equals( zType.getType() ) ) { |
333 |
|
- |
zTypeExtra = "org.litesoft.core.simpletypes.temporal.TimeRes.ToMSEC, "; |
334 |
|
- |
} |
335 |
|
- |
return zTypeExtra; |
336 |
|
- |
} |
337 |
|
- |
|
338 |
|
- |
protected void add( List<String> pCollector, PropertyManager pPropertyManager, String pProperty, String pWhat ) { |
339 |
|
- |
String zProperty = noEmpty( pPropertyManager.getProperty( pProperty ) ); |
340 |
|
- |
if ( zProperty != null ) { |
341 |
|
- |
pCollector.add( pWhat + ".of( " + zProperty + " )" ); |
342 |
|
- |
} |
343 |
|
- |
} |
344 |
|
- |
|
345 |
|
- |
private String noEmpty( Property pProperty ) { |
346 |
|
- |
return (pProperty != null) ? Strings.noEmpty( pProperty.getValueAsString() ) : null; |
347 |
|
- |
} |
348 |
|
- |
|
349 |
|
- |
protected void addTopValidOptions( String pPOorVO ) { |
350 |
|
- |
for ( AttributeProxy zAttribute : getAttributes() ) { |
351 |
|
- |
addTopPSFSattributeValidOptions( zAttribute, pPOorVO ); |
352 |
|
- |
} |
353 |
|
- |
} |
354 |
|
- |
|
355 |
|
- |
private void addTopPSFSattributeValidOptions( AttributeProxy pAttribute, String pPOorVO ) { |
356 |
|
- |
String[] zOptions = pAttribute.getValidOptions(); |
357 |
|
- |
if ( zOptions != null ) { |
358 |
|
- |
addLine( "public static final String[] sValidOptions" + pAttribute.getName() + " = //" ); |
359 |
|
- |
indentStart(); |
360 |
|
- |
indentStart(); |
361 |
|
- |
addLine( "{ //" ); |
362 |
|
- |
indentPlus( 2 ); |
363 |
|
- |
|
364 |
|
- |
if ( (zOptions.length < 10) ) { |
365 |
|
- |
for ( String zOption : zOptions ) { |
366 |
|
- |
if ( Strings.isNotNullOrEmpty( zOption ) ) { |
367 |
|
- |
addLine( pPOorVO + pAttribute.getName() + "_" + adjustOptionForName( zOption ) + ", //" ); |
368 |
|
- |
} |
369 |
|
- |
} |
370 |
|
- |
} else { |
371 |
|
- |
for ( String zOption : zOptions ) { |
372 |
|
- |
if ( Strings.isNotNullOrEmpty( zOption ) ) { |
373 |
|
- |
addLine( quote( zOption ) + ", //" ); |
374 |
|
- |
} |
375 |
|
- |
} |
376 |
|
- |
} |
377 |
|
- |
|
378 |
|
- |
indentMinus( 2 ); |
379 |
|
- |
addLine( "};" ); |
380 |
|
- |
indentEnd(); |
381 |
|
- |
indentEnd(); |
382 |
|
- |
addBlankLine(); |
383 |
|
- |
} |
384 |
|
- |
} |
385 |
|
- |
|
386 |
|
- |
private static final InjectedAttributeProxy IAP_CREATED = createSysTimeStampAMD( "Created" ); |
387 |
|
- |
private static final InjectedAttributeProxy IAP_LAST_MOD = createSysTimeStampAMD( "LastModified" ); |
388 |
|
- |
|
389 |
|
- |
private static InjectedAttributeProxy createSysTimeStampAMD( String pName ) { |
390 |
|
- |
return new InjectedAttributeProxy( pName, true, A_Timestamp.TYPE, BoAttribute.AttributeType.SimpleTimestamp ); |
391 |
|
- |
} |
392 |
|
- |
|
393 |
|
- |
private static class InjectedAttributeProxy implements AttributeProxy { |
394 |
|
- |
private String mName; |
395 |
|
- |
private boolean mSysSetOnly; |
396 |
|
- |
private AttributeType mAttributeSetType; |
397 |
|
- |
private BoAttribute.AttributeType mBoAttributeType; |
398 |
|
- |
|
399 |
|
- |
private InjectedAttributeProxy( String pName, boolean pSysSetOnly, AttributeType pAttributeSetType, BoAttribute.AttributeType pBoAttributeType ) { |
400 |
|
- |
mName = pName; |
401 |
|
- |
mSysSetOnly = pSysSetOnly; |
402 |
|
- |
mAttributeSetType = pAttributeSetType; |
403 |
|
- |
mBoAttributeType = pBoAttributeType; |
404 |
|
- |
if ( pAttributeSetType.getSimpleDataType() != pBoAttributeType.getType() ) { |
405 |
|
- |
throw new IllegalArgumentException( "Incompatible AttributeTypes Set=" + pAttributeSetType + " & " + pBoAttributeType + "=BO" ); |
406 |
|
- |
} |
407 |
|
- |
} |
408 |
|
- |
|
409 |
|
- |
@Override |
410 |
|
- |
public boolean isInjected() { |
411 |
|
- |
return true; |
412 |
|
- |
} |
413 |
|
- |
|
414 |
|
- |
@Override |
415 |
|
- |
public String getDerivedFromAttribute() { |
416 |
|
- |
return null; |
417 |
|
- |
} |
418 |
|
- |
|
419 |
|
- |
@Override |
420 |
|
- |
public String getName() { |
421 |
|
- |
return mName; |
422 |
|
- |
} |
423 |
|
- |
|
424 |
|
- |
@Override |
425 |
|
- |
public String getColumnName() { |
426 |
|
- |
return mName; |
427 |
|
- |
} |
428 |
|
- |
|
429 |
|
- |
@Override |
430 |
|
- |
public Mutability getMutability() { |
431 |
|
- |
return Mutability.RO; |
432 |
|
- |
} |
433 |
|
- |
|
434 |
|
- |
@Override |
435 |
|
- |
public boolean isSysSetOnly() { |
436 |
|
- |
return mSysSetOnly; |
437 |
|
- |
} |
438 |
|
- |
|
439 |
|
- |
@Override |
440 |
|
- |
public String getNotes() { |
441 |
|
- |
return null; |
442 |
|
- |
} |
443 |
|
- |
|
444 |
|
- |
@Override |
445 |
|
- |
public boolean isVirtual() { |
446 |
|
- |
return false; |
447 |
|
- |
} |
448 |
|
- |
|
449 |
|
- |
@Override |
450 |
|
- |
public Class getSimpleDataType() { |
451 |
|
- |
return mAttributeSetType.getSimpleDataType(); |
452 |
|
- |
} |
453 |
|
- |
|
454 |
|
- |
@Override |
455 |
|
- |
public String[] getValidOptions() { |
456 |
|
- |
return null; |
457 |
|
- |
} |
458 |
|
- |
|
459 |
|
- |
@Override |
460 |
|
- |
public BoAttribute.AttributeType getBoAttributeType() { |
461 |
|
- |
return mBoAttributeType; |
462 |
|
- |
} |
463 |
|
- |
|
464 |
|
- |
@Override |
465 |
|
- |
public AttributeType getAttributeSetType() { |
466 |
|
- |
return mAttributeSetType; |
467 |
|
- |
} |
468 |
|
- |
|
469 |
|
- |
@Override |
470 |
|
- |
public boolean isRequired() { |
471 |
|
- |
return true; |
472 |
|
- |
} |
473 |
|
- |
|
474 |
|
- |
@Override |
475 |
|
- |
public boolean isQueryView() { |
476 |
|
- |
return false; |
477 |
|
- |
} |
478 |
|
- |
|
479 |
|
- |
@Override |
480 |
|
- |
public PropertyManager getPropertyManager() { |
481 |
|
- |
return PropertyManager.NONE; |
482 |
|
- |
} |
483 |
|
- |
|
484 |
|
- |
@Override |
485 |
|
- |
public String getToManyFullyQualifiedName() { |
486 |
|
- |
return null; |
487 |
|
- |
} |
488 |
|
- |
|
489 |
|
- |
@Override |
490 |
|
- |
public boolean isToManyInstantiable() { |
491 |
|
- |
return false; |
492 |
|
- |
} |
493 |
|
- |
|
494 |
|
- |
@Override |
495 |
|
- |
public String getToManyBackReference() { |
496 |
|
- |
return null; |
497 |
|
- |
} |
498 |
|
- |
|
499 |
|
- |
@Override |
500 |
|
- |
public AttributeProxy getToManyBackReferenceAttributeProxy() { |
501 |
|
- |
return null; |
502 |
|
- |
} |
503 |
|
- |
|
504 |
|
- |
@Override |
505 |
|
- |
public String getToOneFullyQualifiedName() { |
506 |
|
- |
return null; |
507 |
|
- |
} |
508 |
|
- |
|
509 |
|
- |
@Override |
510 |
|
- |
public boolean isToOneInstantiable() { |
511 |
|
- |
return false; |
512 |
|
- |
} |
513 |
|
- |
|
514 |
|
- |
@Override |
515 |
|
- |
public String getToOneBackReference() { |
516 |
|
- |
return null; |
517 |
|
- |
} |
518 |
|
- |
|
519 |
|
- |
@Override |
520 |
|
- |
public AttributeProxy getToOneBackReferenceAttributeProxy() { |
521 |
|
- |
return null; |
522 |
|
- |
} |
523 |
|
- |
|
524 |
|
- |
@Override |
525 |
|
- |
public String toString() { |
526 |
|
- |
return getClass().getSimpleName() + "(" + getSimpleDataType().getSimpleName() + "): " + getName(); |
527 |
|
- |
} |
528 |
|
- |
} |
529 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.generator; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.aokeyhole.objects.*; |
|
5 |
+ |
import org.litesoft.aokeyhole.objects.AttributeMetaData; |
|
6 |
+ |
import org.litesoft.aokeyhole.objects.attributes.*; |
|
7 |
+ |
import org.litesoft.aokeyhole.objects.properties.*; |
|
8 |
+ |
import org.litesoft.aokeyhole.objects.support.*; |
|
9 |
+ |
import org.litesoft.bo.*; |
|
10 |
+ |
import org.litesoft.bo.attributes.*; |
|
11 |
+ |
import org.litesoft.codegen.*; |
|
12 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
13 |
+ |
import org.litesoft.commonfoundation.typeutils.*; |
|
14 |
+ |
import org.litesoft.core.simpletypes.currency.*; |
|
15 |
+ |
import org.litesoft.core.simpletypes.temporal.*; |
|
16 |
+ |
|
|
17 |
+ |
import java.util.*; |
|
18 |
+ |
|
|
19 |
+ |
public abstract class AbstractTypeFileGenerator extends SourceCodeGenerator { |
|
20 |
+ |
protected interface AttributeProxy extends MinimalAttributeMetaData, |
|
21 |
+ |
HasValidOptions { |
|
22 |
+ |
boolean isInjected(); |
|
23 |
+ |
|
|
24 |
+ |
String getDerivedFromAttribute(); |
|
25 |
+ |
|
|
26 |
+ |
String getColumnName(); |
|
27 |
+ |
|
|
28 |
+ |
Mutability getMutability(); |
|
29 |
+ |
|
|
30 |
+ |
boolean isSysSetOnly(); |
|
31 |
+ |
|
|
32 |
+ |
Class getSimpleDataType(); |
|
33 |
+ |
|
|
34 |
+ |
BoAttribute.AttributeType getBoAttributeType(); |
|
35 |
+ |
|
|
36 |
+ |
boolean isRequired(); |
|
37 |
+ |
|
|
38 |
+ |
boolean isQueryView(); |
|
39 |
+ |
|
|
40 |
+ |
String getToManyFullyQualifiedName(); |
|
41 |
+ |
|
|
42 |
+ |
boolean isToManyInstantiable(); |
|
43 |
+ |
|
|
44 |
+ |
String getToManyBackReference(); |
|
45 |
+ |
|
|
46 |
+ |
AttributeProxy getToManyBackReferenceAttributeProxy(); |
|
47 |
+ |
|
|
48 |
+ |
String getToOneFullyQualifiedName(); |
|
49 |
+ |
|
|
50 |
+ |
boolean isToOneInstantiable(); |
|
51 |
+ |
|
|
52 |
+ |
String getToOneBackReference(); |
|
53 |
+ |
|
|
54 |
+ |
@SuppressWarnings({"UnusedDeclaration"}) |
|
55 |
+ |
AttributeProxy getToOneBackReferenceAttributeProxy(); |
|
56 |
+ |
} |
|
57 |
+ |
|
|
58 |
+ |
protected final ErrorSinc mErrorSinc; |
|
59 |
+ |
protected final ObjectRef mObjectRef, mParentObjectRef; |
|
60 |
+ |
protected final ObjectMetaData mObjectMetaData; |
|
61 |
+ |
protected final String mPackage, mObjectName, mClassName; |
|
62 |
+ |
protected final boolean mIsParent; |
|
63 |
+ |
|
|
64 |
+ |
public AbstractTypeFileGenerator( String pReportingType, ErrorSinc pErrorSinc, ObjectMetaData pObjectMetaData, ObjectRef pObjectRef, String pTypeExtension, |
|
65 |
+ |
ObjectRef pParentObjectRef, boolean pIsParent ) { |
|
66 |
+ |
super( pReportingType, pObjectRef.getFullFolderPath() + "/" + pObjectMetaData.getName() + pTypeExtension + ".java" ); |
|
67 |
+ |
mErrorSinc = pErrorSinc; |
|
68 |
+ |
mObjectRef = pObjectRef; |
|
69 |
+ |
mParentObjectRef = pParentObjectRef; |
|
70 |
+ |
mPackage = pObjectRef.getPackage(); |
|
71 |
+ |
mClassName = (mObjectName = (mObjectMetaData = pObjectMetaData).getName()) + pTypeExtension; |
|
72 |
+ |
mIsParent = pIsParent; |
|
73 |
+ |
setOverwrite( mClassName.endsWith( "GO" ) ); |
|
74 |
+ |
} |
|
75 |
+ |
|
|
76 |
+ |
public final SourceCodeGenerator generate() { |
|
77 |
+ |
addPackage( mPackage ); |
|
78 |
+ |
|
|
79 |
+ |
LLaddImports(); |
|
80 |
+ |
|
|
81 |
+ |
LLaddClassDefinition(); |
|
82 |
+ |
|
|
83 |
+ |
LLaddClassBody(); |
|
84 |
+ |
|
|
85 |
+ |
addClassEnd(); |
|
86 |
+ |
|
|
87 |
+ |
return this; |
|
88 |
+ |
} |
|
89 |
+ |
|
|
90 |
+ |
protected String getExtends( String pNoParentClassPrefix ) { |
|
91 |
+ |
if ( mParentObjectRef == null ) { |
|
92 |
+ |
return pNoParentClassPrefix; |
|
93 |
+ |
} |
|
94 |
+ |
return removePackageIfPossible( mParentObjectRef.getFullyQualifiedName() ); |
|
95 |
+ |
} |
|
96 |
+ |
|
|
97 |
+ |
protected String removePackageIfPossible( String pFullyQualifiedName ) { |
|
98 |
+ |
int zDotAt = pFullyQualifiedName.lastIndexOf( '.' ); |
|
99 |
+ |
if ( (zDotAt != -1) && mPackage.equals( pFullyQualifiedName.substring( 0, zDotAt ) ) ) { |
|
100 |
+ |
pFullyQualifiedName = pFullyQualifiedName.substring( zDotAt + 1 ); |
|
101 |
+ |
} |
|
102 |
+ |
return pFullyQualifiedName; |
|
103 |
+ |
} |
|
104 |
+ |
|
|
105 |
+ |
protected void LLaddImports() { |
|
106 |
+ |
} |
|
107 |
+ |
|
|
108 |
+ |
abstract protected void LLaddClassDefinition(); |
|
109 |
+ |
|
|
110 |
+ |
protected void LLaddClassBody() { |
|
111 |
+ |
} |
|
112 |
+ |
|
|
113 |
+ |
abstract protected AttributeProxy[] getAttributes(); |
|
114 |
+ |
|
|
115 |
+ |
protected static Mutability convertToMutability( AttributeMetaData pAttribute ) { |
|
116 |
+ |
AttributeType zType = pAttribute.getAttributeSet().getType(); |
|
117 |
+ |
if ( A_ID.TYPE.equals( zType ) ) { |
|
118 |
+ |
return Mutability.AddOnly; |
|
119 |
+ |
} |
|
120 |
+ |
String zChangeable = pAttribute.getPropertyManager().get_String( PMD_Changeable.NAME, "" ).trim(); |
|
121 |
+ |
if ( PMD_Changeable.ADD_ONLY.equals( zChangeable ) ) { |
|
122 |
+ |
return Mutability.AddOnly; |
|
123 |
+ |
} |
|
124 |
+ |
if ( PMD_Changeable.READ_ONLY.equals( zChangeable ) ) { |
|
125 |
+ |
return Mutability.RO; |
|
126 |
+ |
} |
|
127 |
+ |
return Mutability.RW; |
|
128 |
+ |
} |
|
129 |
+ |
|
|
130 |
+ |
protected BoAttribute.AttributeType getType( MinimalAttributeMetaData pAttribute ) { |
|
131 |
+ |
AttributeType zAttributeType = pAttribute.getAttributeSetType(); |
|
132 |
+ |
if ( zAttributeType.getFAT().isSimple() ) { |
|
133 |
+ |
Class zTypeClass = zAttributeType.getSimpleDataType(); |
|
134 |
+ |
if ( zTypeClass == null ) { |
|
135 |
+ |
mErrorSinc.addError( "CurrentlyUnsupportedAttributeType", pAttribute.toString(), mObjectMetaData.toStringForError() ); |
|
136 |
+ |
} else { |
|
137 |
+ |
String zType = zTypeClass.getName(); |
|
138 |
+ |
int zAt = zType.lastIndexOf( '.' ); |
|
139 |
+ |
if ( zAt != -1 ) { |
|
140 |
+ |
zType = zType.substring( zAt + 1 ); |
|
141 |
+ |
} |
|
142 |
+ |
try { |
|
143 |
+ |
return BoAttribute.AttributeType.valueOf( zType ); |
|
144 |
+ |
} |
|
145 |
+ |
catch ( IllegalArgumentException e ) { |
|
146 |
+ |
mErrorSinc.addError( "CurrentlyUnsupportedAttributeType", "of: " + zType, pAttribute.toString(), mObjectMetaData.toStringForError() ); |
|
147 |
+ |
} |
|
148 |
+ |
} |
|
149 |
+ |
} |
|
150 |
+ |
return null; |
|
151 |
+ |
} |
|
152 |
+ |
|
|
153 |
+ |
protected void addNotes( String pNotes ) { |
|
154 |
+ |
if ( Currently.isNotNullOrEmpty( pNotes ) ) { |
|
155 |
+ |
addLine( "/**" ); |
|
156 |
+ |
String[] zLines = Strings.parseChar( Strings.normalizeNewLines( pNotes ), '\n' ); |
|
157 |
+ |
for ( String zLine : zLines ) { |
|
158 |
+ |
addLine( " " + ("* " + zLine).trim() ); |
|
159 |
+ |
} |
|
160 |
+ |
addLine( " */" ); |
|
161 |
+ |
} |
|
162 |
+ |
} |
|
163 |
+ |
|
|
164 |
+ |
protected String adjustOptionForName( String pOption ) { |
|
165 |
+ |
StringBuilder rv = new StringBuilder( pOption ); |
|
166 |
+ |
for ( int i = 0; i < rv.length(); i++ ) { |
|
167 |
+ |
char c = rv.charAt( i ); |
|
168 |
+ |
if ( (c != '_') && !Characters.isAlphaNumeric( c ) ) { |
|
169 |
+ |
rv.setCharAt( i, '_' ); |
|
170 |
+ |
} |
|
171 |
+ |
} |
|
172 |
+ |
return rv.toString(); |
|
173 |
+ |
} |
|
174 |
+ |
|
|
175 |
+ |
private static Map<ObjectMetaData, List<AttributeProxy>> sInjectedAttributes = new HashMap<ObjectMetaData, List<AttributeProxy>>(); |
|
176 |
+ |
|
|
177 |
+ |
protected synchronized List<AttributeProxy> getInjectedAttributes( ObjectMetaData pObjectMetaData ) { |
|
178 |
+ |
List<AttributeProxy> zInjectedAttributes = sInjectedAttributes.get( pObjectMetaData ); |
|
179 |
+ |
if ( zInjectedAttributes == null ) { |
|
180 |
+ |
sInjectedAttributes.put( pObjectMetaData, zInjectedAttributes = createInjectedAttributes( pObjectMetaData ) ); |
|
181 |
+ |
} |
|
182 |
+ |
return zInjectedAttributes; |
|
183 |
+ |
} |
|
184 |
+ |
|
|
185 |
+ |
protected List<AttributeProxy> createInjectedAttributes( ObjectMetaData pObjectMetaData ) { |
|
186 |
+ |
String zTimeTracked = pObjectMetaData.getPropertyManager().get_String( PMD_TimeTracked.NAME, PMD_TimeTracked.NONE ); |
|
187 |
+ |
if ( PMD_TimeTracked.NONE.equals( zTimeTracked ) ) { |
|
188 |
+ |
return Collections.emptyList(); |
|
189 |
+ |
} |
|
190 |
+ |
ArrayList<AttributeProxy> zInjected = new ArrayList<AttributeProxy>(); |
|
191 |
+ |
if ( PMD_TimeTracked.CREATED.equals( zTimeTracked ) || PMD_TimeTracked.BOTH.equals( zTimeTracked ) ) { |
|
192 |
+ |
zInjected.add( IAP_CREATED ); |
|
193 |
+ |
} |
|
194 |
+ |
if ( PMD_TimeTracked.LAST_MOD.equals( zTimeTracked ) || PMD_TimeTracked.BOTH.equals( zTimeTracked ) ) { |
|
195 |
+ |
zInjected.add( IAP_LAST_MOD ); |
|
196 |
+ |
} |
|
197 |
+ |
return zInjected; |
|
198 |
+ |
} |
|
199 |
+ |
|
|
200 |
+ |
protected MinimalAttributeMetaData getRegularOrInjectedAttribute( ObjectMetaData pObjectMetaData, String pAttrName ) { |
|
201 |
+ |
AttributeMetaData zAMD = pObjectMetaData.getAttribute( pAttrName ); |
|
202 |
+ |
if ( zAMD != null ) { |
|
203 |
+ |
return zAMD; |
|
204 |
+ |
} |
|
205 |
+ |
List<AttributeProxy> zInjectedAttributes = getInjectedAttributes( pObjectMetaData ); |
|
206 |
+ |
for ( AttributeProxy zAttribute : zInjectedAttributes ) { |
|
207 |
+ |
if ( zAttribute.getName().equals( pAttrName ) ) { |
|
208 |
+ |
return zAttribute; |
|
209 |
+ |
} |
|
210 |
+ |
} |
|
211 |
+ |
return null; |
|
212 |
+ |
} |
|
213 |
+ |
|
|
214 |
+ |
protected MinimalAttributeMetaData getAttribute( ObjectMetaData pObjectMetaData, String pAttrName ) { |
|
215 |
+ |
while ( pObjectMetaData != null ) { |
|
216 |
+ |
MinimalAttributeMetaData zAMD = getRegularOrInjectedAttribute( pObjectMetaData, pAttrName ); |
|
217 |
+ |
if ( zAMD != null ) { |
|
218 |
+ |
return zAMD; |
|
219 |
+ |
} |
|
220 |
+ |
String zParentName = ConstrainTo.significantOrNull( pObjectMetaData.getParentName() ); |
|
221 |
+ |
SystemMetaData zSystemMetaData = pObjectMetaData.getSystemMetaData(); |
|
222 |
+ |
pObjectMetaData = ((zSystemMetaData != null) && (zParentName != null)) ? zSystemMetaData.getObject( zParentName ) : null; |
|
223 |
+ |
} |
|
224 |
+ |
return null; |
|
225 |
+ |
} |
|
226 |
+ |
|
|
227 |
+ |
protected SystemMetaData getSystemMetaData( MetaDataOwner pOwner ) { |
|
228 |
+ |
while ( pOwner instanceof AbstractNamedMetaData ) { |
|
229 |
+ |
pOwner = ((AbstractNamedMetaData) pOwner).getOwner(); |
|
230 |
+ |
} |
|
231 |
+ |
return (pOwner instanceof SystemMetaData) ? (SystemMetaData) pOwner : null; |
|
232 |
+ |
} |
|
233 |
+ |
|
|
234 |
+ |
protected void LLaddAttributes( boolean pAddBlank ) { |
|
235 |
+ |
for ( AttributeProxy zAttribute : getAttributes() ) { |
|
236 |
+ |
if ( pAddBlank ) { |
|
237 |
+ |
addBlankLine(); |
|
238 |
+ |
} |
|
239 |
+ |
pAddBlank = true; |
|
240 |
+ |
LLaddAttribute( zAttribute ); |
|
241 |
+ |
} |
|
242 |
+ |
} |
|
243 |
+ |
|
|
244 |
+ |
protected void addPSFSattributeValidOptions( AttributeProxy pAttribute, String pPOorVO ) { |
|
245 |
+ |
String[] zOptions = pAttribute.getValidOptions(); |
|
246 |
+ |
if ( Currently.isNotNullOrEmpty( zOptions ) && (zOptions.length < 10) ) { |
|
247 |
+ |
addBlankLine(); |
|
248 |
+ |
for ( String zOption : zOptions ) { |
|
249 |
+ |
if ( Currently.isNotNullOrEmpty( zOption ) ) { |
|
250 |
+ |
addPSFS( pPOorVO + pAttribute.getName() + "_" + adjustOptionForName( zOption ), zOption ); |
|
251 |
+ |
} |
|
252 |
+ |
} |
|
253 |
+ |
} |
|
254 |
+ |
} |
|
255 |
+ |
|
|
256 |
+ |
protected void LLaddAttribute( AttributeProxy zAttribute ) { |
|
257 |
+ |
} |
|
258 |
+ |
|
|
259 |
+ |
protected String createAttributeTypedCall( AttributeProxy pAttribute, String pPOorVO, String pBaseLine, String pLineTerminator ) { |
|
260 |
+ |
String zName = pAttribute.getName(); |
|
261 |
+ |
|
|
262 |
+ |
Mutability zMutability = pAttribute.getMutability(); |
|
263 |
+ |
|
|
264 |
+ |
String zRequired = pAttribute.isRequired() ? ", true" : ", false"; |
|
265 |
+ |
|
|
266 |
+ |
BoAttribute.AttributeType zType = pAttribute.getBoAttributeType(); |
|
267 |
+ |
if ( zType == null ) { |
|
268 |
+ |
mErrorSinc.addError( pPOorVO + " CurrentlyUnsupportedAttributeType", "of: " + pAttribute.getAttributeSetType(), pAttribute.toString(), |
|
269 |
+ |
mObjectMetaData.toStringForError() ); |
|
270 |
+ |
zType = BoAttribute.AttributeType.String; |
|
271 |
+ |
} |
|
272 |
+ |
|
|
273 |
+ |
AttributeType zAttributeType = pAttribute.getAttributeSetType(); |
|
274 |
+ |
String zEnumType = zType.toString(); |
|
275 |
+ |
|
|
276 |
+ |
PropertyManager zPM = pAttribute.getPropertyManager(); |
|
277 |
+ |
List<String> zProperties = new ArrayList<String>(); |
|
278 |
+ |
|
|
279 |
+ |
String[] zOptions = pAttribute.getValidOptions(); |
|
280 |
+ |
if ( zOptions != null ) { |
|
281 |
+ |
zProperties.add( "Options.of( sValidOptions" + zName + " )" ); |
|
282 |
+ |
zEnumType = (zAttributeType instanceof HasOpenOption) ? "OpenValidOptions" : "ValidOptions"; |
|
283 |
+ |
} else if ( zAttributeType instanceof AbstractArrayOptionsAttributeTypeSimple ) { |
|
284 |
+ |
String zArrayRef = ConstrainTo.significantOrNull( zPM.get_String( PMD_FullyQualifiedStringArrayPath.NAME, "" ) ); |
|
285 |
+ |
if ( zArrayRef == null ) { |
|
286 |
+ |
mErrorSinc.addError( "AttributeStringArrayPath", "Missing", pAttribute.toString(), mObjectMetaData.toStringForError() ); |
|
287 |
+ |
} |
|
288 |
+ |
zProperties.add( "Options.of( " + zArrayRef + " )" ); |
|
289 |
+ |
zEnumType = (zAttributeType instanceof HasOpenOption) ? "OpenValidOptions" : "ValidOptions"; |
|
290 |
+ |
} else if ( A_Password.TYPE.equals( zAttributeType ) ) { |
|
291 |
+ |
zEnumType = "Password"; |
|
292 |
+ |
} else if ( A_Text.TYPE.equals( zAttributeType ) ) { |
|
293 |
+ |
zEnumType = "Text"; |
|
294 |
+ |
} |
|
295 |
+ |
String zProperty = noEmpty( zPM.getProperty( PMD_Case.NAME ) ); |
|
296 |
+ |
if ( zProperty != null ) { |
|
297 |
+ |
zProperties.add( PMD_Case.NAME + "." + zProperty ); |
|
298 |
+ |
} |
|
299 |
+ |
// Will be rendered in REVERSE order |
|
300 |
+ |
add( zProperties, zPM, PMD_DisplayLength.NAME, "DisplayLength" ); |
|
301 |
+ |
add( zProperties, zPM, PMD_MaxLength.NAME, "MaxLength" ); |
|
302 |
+ |
add( zProperties, zPM, PMD_DisplayHeightInitial.NAME, "DisplayHeightInitial" ); |
|
303 |
+ |
add( zProperties, zPM, PMD_DisplayWidthInitial.NAME, "DisplayWidthInitial" ); |
|
304 |
+ |
|
|
305 |
+ |
pBaseLine += zRequired + ", _" + zEnumType; |
|
306 |
+ |
if ( !Mutability.RW.equals( zMutability ) ) { |
|
307 |
+ |
pBaseLine += "." + zMutability + "()"; |
|
308 |
+ |
} |
|
309 |
+ |
if ( zProperties.isEmpty() ) { |
|
310 |
+ |
addLine( pBaseLine + " )" + pLineTerminator ); |
|
311 |
+ |
} else { |
|
312 |
+ |
pBaseLine += ".with( "; |
|
313 |
+ |
int i = zProperties.size(); |
|
314 |
+ |
if ( i == 1 ) { |
|
315 |
+ |
addLine( pBaseLine + zProperties.get( --i ) + " ) )" + pLineTerminator ); |
|
316 |
+ |
} else { |
|
317 |
+ |
String zPadding = Strings.spaces( pBaseLine.length() ); |
|
318 |
+ |
addLine( pBaseLine + zProperties.get( --i ) + ", //" ); |
|
319 |
+ |
while ( i > 1 ) { |
|
320 |
+ |
addLine( zPadding + zProperties.get( --i ) + ", //" ); |
|
321 |
+ |
} |
|
322 |
+ |
addLine( zPadding + zProperties.get( --i ) + " ) )" + pLineTerminator ); |
|
323 |
+ |
} |
|
324 |
+ |
} |
|
325 |
+ |
String zTypeExtra = ""; |
|
326 |
+ |
if ( Money.class.equals( zType.getType() ) ) { |
|
327 |
+ |
zTypeExtra = "org.litesoft.core.simpletypes.currency.Currency.US, "; |
|
328 |
+ |
} else if ( CalendarYMD.class.equals( zType.getType() ) ) { |
|
329 |
+ |
zTypeExtra = "org.litesoft.core.simpletypes.temporal.DateFormatControl.DEFAULT_YMD_FORMAT, "; |
|
330 |
+ |
} else if ( SimpleTime.class.equals( zType.getType() ) ) { |
|
331 |
+ |
zTypeExtra = "org.litesoft.core.simpletypes.temporal.TimeRes.ToMIN, "; |
|
332 |
+ |
} else if ( SimpleTimestamp.class.equals( zType.getType() ) ) { |
|
333 |
+ |
zTypeExtra = "org.litesoft.core.simpletypes.temporal.TimeRes.ToMSEC, "; |
|
334 |
+ |
} |
|
335 |
+ |
return zTypeExtra; |
|
336 |
+ |
} |
|
337 |
+ |
|
|
338 |
+ |
protected void add( List<String> pCollector, PropertyManager pPropertyManager, String pProperty, String pWhat ) { |
|
339 |
+ |
String zProperty = noEmpty( pPropertyManager.getProperty( pProperty ) ); |
|
340 |
+ |
if ( zProperty != null ) { |
|
341 |
+ |
pCollector.add( pWhat + ".of( " + zProperty + " )" ); |
|
342 |
+ |
} |
|
343 |
+ |
} |
|
344 |
+ |
|
|
345 |
+ |
private String noEmpty( Property pProperty ) { |
|
346 |
+ |
return (pProperty != null) ? ConstrainTo.significantOrNull( pProperty.getValueAsString() ) : null; |
|
347 |
+ |
} |
|
348 |
+ |
|
|
349 |
+ |
protected void addTopValidOptions( String pPOorVO ) { |
|
350 |
+ |
for ( AttributeProxy zAttribute : getAttributes() ) { |
|
351 |
+ |
addTopPSFSattributeValidOptions( zAttribute, pPOorVO ); |
|
352 |
+ |
} |
|
353 |
+ |
} |
|
354 |
+ |
|
|
355 |
+ |
private void addTopPSFSattributeValidOptions( AttributeProxy pAttribute, String pPOorVO ) { |
|
356 |
+ |
String[] zOptions = pAttribute.getValidOptions(); |
|
357 |
+ |
if ( zOptions != null ) { |
|
358 |
+ |
addLine( "public static final String[] sValidOptions" + pAttribute.getName() + " = //" ); |
|
359 |
+ |
indentStart(); |
|
360 |
+ |
indentStart(); |
|
361 |
+ |
addLine( "{ //" ); |
|
362 |
+ |
indentPlus( 2 ); |
|
363 |
+ |
|
|
364 |
+ |
if ( (zOptions.length < 10) ) { |
|
365 |
+ |
for ( String zOption : zOptions ) { |
|
366 |
+ |
if ( Currently.isNotNullOrEmpty( zOption ) ) { |
|
367 |
+ |
addLine( pPOorVO + pAttribute.getName() + "_" + adjustOptionForName( zOption ) + ", //" ); |
|
368 |
+ |
} |
|
369 |
+ |
} |
|
370 |
+ |
} else { |
|
371 |
+ |
for ( String zOption : zOptions ) { |
|
372 |
+ |
if ( Currently.isNotNullOrEmpty( zOption ) ) { |
|
373 |
+ |
addLine( quote( zOption ) + ", //" ); |
|
374 |
+ |
} |
|
375 |
+ |
} |
|
376 |
+ |
} |
|
377 |
+ |
|
|
378 |
+ |
indentMinus( 2 ); |
|
379 |
+ |
addLine( "};" ); |
|
380 |
+ |
indentEnd(); |
|
381 |
+ |
indentEnd(); |
|
382 |
+ |
addBlankLine(); |
|
383 |
+ |
} |
|
384 |
+ |
} |
|
385 |
+ |
|
|
386 |
+ |
private static final InjectedAttributeProxy IAP_CREATED = createSysTimeStampAMD( "Created" ); |
|
387 |
+ |
private static final InjectedAttributeProxy IAP_LAST_MOD = createSysTimeStampAMD( "LastModified" ); |
|
388 |
+ |
|
|
389 |
+ |
private static InjectedAttributeProxy createSysTimeStampAMD( String pName ) { |
|
390 |
+ |
return new InjectedAttributeProxy( pName, true, A_Timestamp.TYPE, BoAttribute.AttributeType.SimpleTimestamp ); |
|
391 |
+ |
} |
|
392 |
+ |
|
|
393 |
+ |
private static class InjectedAttributeProxy implements AttributeProxy { |
|
394 |
+ |
private String mName; |
|
395 |
+ |
private boolean mSysSetOnly; |
|
396 |
+ |
private AttributeType mAttributeSetType; |
|
397 |
+ |
private BoAttribute.AttributeType mBoAttributeType; |
|
398 |
+ |
|
|
399 |
+ |
private InjectedAttributeProxy( String pName, boolean pSysSetOnly, AttributeType pAttributeSetType, BoAttribute.AttributeType pBoAttributeType ) { |
|
400 |
+ |
mName = pName; |
|
401 |
+ |
mSysSetOnly = pSysSetOnly; |
|
402 |
+ |
mAttributeSetType = pAttributeSetType; |
|
403 |
+ |
mBoAttributeType = pBoAttributeType; |
|
404 |
+ |
if ( pAttributeSetType.getSimpleDataType() != pBoAttributeType.getType() ) { |
|
405 |
+ |
throw new IllegalArgumentException( "Incompatible AttributeTypes Set=" + pAttributeSetType + " & " + pBoAttributeType + "=BO" ); |
|
406 |
+ |
} |
|
407 |
+ |
} |
|
408 |
+ |
|
|
409 |
+ |
@Override |
|
410 |
+ |
public boolean isInjected() { |
|
411 |
+ |
return true; |
|
412 |
+ |
} |
|
413 |
+ |
|
|
414 |
+ |
@Override |
|
415 |
+ |
public String getDerivedFromAttribute() { |
|
416 |
+ |
return null; |
|
417 |
+ |
} |
|
418 |
+ |
|
|
419 |
+ |
@Override |
|
420 |
+ |
public String getName() { |
|
421 |
+ |
return mName; |
|
422 |
+ |
} |
|
423 |
+ |
|
|
424 |
+ |
@Override |
|
425 |
+ |
public String getColumnName() { |
|
426 |
+ |
return mName; |
|
427 |
+ |
} |
|
428 |
+ |
|
|
429 |
+ |
@Override |
|
430 |
+ |
public Mutability getMutability() { |
|
431 |
+ |
return Mutability.RO; |
|
432 |
+ |
} |
|
433 |
+ |
|
|
434 |
+ |
@Override |
|
435 |
+ |
public boolean isSysSetOnly() { |
|
436 |
+ |
return mSysSetOnly; |
|
437 |
+ |
} |
|
438 |
+ |
|
|
439 |
+ |
@Override |
|
440 |
+ |
public String getNotes() { |
|
441 |
+ |
return null; |
|
442 |
+ |
} |
|
443 |
+ |
|
|
444 |
+ |
@Override |
|
445 |
+ |
public boolean isVirtual() { |
|
446 |
+ |
return false; |
|
447 |
+ |
} |
|
448 |
+ |
|
|
449 |
+ |
@Override |
|
450 |
+ |
public Class getSimpleDataType() { |
|
451 |
+ |
return mAttributeSetType.getSimpleDataType(); |
|
452 |
+ |
} |
|
453 |
+ |
|
|
454 |
+ |
@Override |
|
455 |
+ |
public String[] getValidOptions() { |
|
456 |
+ |
return null; |
|
457 |
+ |
} |
|
458 |
+ |
|
|
459 |
+ |
@Override |
|
460 |
+ |
public BoAttribute.AttributeType getBoAttributeType() { |
|
461 |
+ |
return mBoAttributeType; |
|
462 |
+ |
} |
|
463 |
+ |
|
|
464 |
+ |
@Override |
|
465 |
+ |
public AttributeType getAttributeSetType() { |
|
466 |
+ |
return mAttributeSetType; |
|
467 |
+ |
} |
|
468 |
+ |
|
|
469 |
+ |
@Override |
|
470 |
+ |
public boolean isRequired() { |
|
471 |
+ |
return true; |
|
472 |
+ |
} |
|
473 |
+ |
|
|
474 |
+ |
@Override |
|
475 |
+ |
public boolean isQueryView() { |
|
476 |
+ |
return false; |
|
477 |
+ |
} |
|
478 |
+ |
|
|
479 |
+ |
@Override |
|
480 |
+ |
public PropertyManager getPropertyManager() { |
|
481 |
+ |
return PropertyManager.NONE; |
|
482 |
+ |
} |
|
483 |
+ |
|
|
484 |
+ |
@Override |
|
485 |
+ |
public String getToManyFullyQualifiedName() { |
|
486 |
+ |
return null; |
|
487 |
+ |
} |
|
488 |
+ |
|
|
489 |
+ |
@Override |
|
490 |
+ |
public boolean isToManyInstantiable() { |
|
491 |
+ |
return false; |
|
492 |
+ |
} |
|
493 |
+ |
|
|
494 |
+ |
@Override |
|
495 |
+ |
public String getToManyBackReference() { |
|
496 |
+ |
return null; |
|
497 |
+ |
} |
|
498 |
+ |
|
|
499 |
+ |
@Override |
|
500 |
+ |
public AttributeProxy getToManyBackReferenceAttributeProxy() { |
|
501 |
+ |
return null; |
|
502 |
+ |
} |
|
503 |
+ |
|
|
504 |
+ |
@Override |
|
505 |
+ |
public String getToOneFullyQualifiedName() { |
|
506 |
+ |
return null; |
|
507 |
+ |
} |
|
508 |
+ |
|
|
509 |
+ |
@Override |
|
510 |
+ |
public boolean isToOneInstantiable() { |
|
511 |
+ |
return false; |
|
512 |
+ |
} |
|
513 |
+ |
|
|
514 |
+ |
@Override |
|
515 |
+ |
public String getToOneBackReference() { |
|
516 |
+ |
return null; |
|
517 |
+ |
} |
|
518 |
+ |
|
|
519 |
+ |
@Override |
|
520 |
+ |
public AttributeProxy getToOneBackReferenceAttributeProxy() { |
|
521 |
+ |
return null; |
|
522 |
+ |
} |
|
523 |
+ |
|
|
524 |
+ |
@Override |
|
525 |
+ |
public String toString() { |
|
526 |
+ |
return getClass().getSimpleName() + "(" + getSimpleDataType().getSimpleName() + "): " + getName(); |
|
527 |
+ |
} |
|
528 |
+ |
} |
|
529 |
+ |
} |