Subversion Repository Public Repository

litesoft

Diff Revisions 49 vs 193 for /trunk/Java/PoVoGenerator/Generator/src/org/litesoft/generator/AbstractTypeFileGenerator.java

Diff revisions: vs.
  @@ -17,38 +17,27 @@
17 17
18 18 public abstract class AbstractTypeFileGenerator extends SourceCodeGenerator
19 19 {
20 - protected interface AttributeProxy
20 + protected interface AttributeProxy extends MinimalAttributeMetaData,
21 + HasValidOptions
21 22 {
22 23 boolean isInjected();
23 24
24 25 String getDerivedFromAttribute();
25 26
26 - String getName();
27 -
28 27 String getColumnName();
29 28
30 29 Mutability getMutability();
31 30
32 31 boolean isSysSetOnly();
33 32
34 - String getNotes();
35 -
36 - boolean isVirtual();
37 -
38 33 Class getSimpleDataType();
39 34
40 - String[] getValidOptions();
41 -
42 35 BoAttribute.AttributeType getBoAttributeType();
43 36
44 - AttributeType getAttributeType();
45 -
46 37 boolean isRequired();
47 38
48 39 boolean isQueryView();
49 40
50 - PropertyManager getPropertyManager();
51 -
52 41 String getToManyFullyQualifiedName();
53 42
54 43 boolean isToManyInstantiable();
  @@ -63,6 +52,7 @@
63 52
64 53 String getToOneBackReference();
65 54
55 + @SuppressWarnings({"UnusedDeclaration"})
66 56 AttributeProxy getToOneBackReferenceAttributeProxy();
67 57 }
68 58
  @@ -149,9 +139,9 @@
149 139 return Mutability.RW;
150 140 }
151 141
152 - protected BoAttribute.AttributeType getType( AttributeMetaData pAttribute )
142 + protected BoAttribute.AttributeType getType( MinimalAttributeMetaData pAttribute )
153 143 {
154 - AttributeType zAttributeType = pAttribute.getAttributeSet().getType();
144 + AttributeType zAttributeType = pAttribute.getAttributeSetType();
155 145 if ( zAttributeType.getFAT().isSimple() )
156 146 {
157 147 Class zTypeClass = zAttributeType.getSimpleDataType();
  @@ -180,11 +170,6 @@
180 170 return null;
181 171 }
182 172
183 - protected Class extractSimpleDataType( AttributeMetaData pAttribute )
184 - {
185 - return pAttribute.getAttributeSet().getType().getSimpleDataType();
186 - }
187 -
188 173 protected void addNotes( String pNotes )
189 174 {
190 175 if ( Utils.isNotNullOrEmpty( pNotes ) )
  @@ -213,10 +198,59 @@
213 198 return rv.toString();
214 199 }
215 200
216 - protected AttributeMetaData getAttribute( ObjectMetaData pObjectMetaData, String pAttrName )
201 + private static Map<ObjectMetaData, List<AttributeProxy>> sInjectedAttributes = new HashMap<ObjectMetaData, List<AttributeProxy>>();
202 +
203 + protected synchronized List<AttributeProxy> getInjectedAttributes( ObjectMetaData pObjectMetaData )
204 + {
205 + List<AttributeProxy> zInjectedAttributes = sInjectedAttributes.get( pObjectMetaData );
206 + if ( zInjectedAttributes == null )
207 + {
208 + sInjectedAttributes.put( pObjectMetaData, zInjectedAttributes = createInjectedAttributes( pObjectMetaData ) );
209 + }
210 + return zInjectedAttributes;
211 + }
212 +
213 + protected List<AttributeProxy> createInjectedAttributes( ObjectMetaData pObjectMetaData )
214 + {
215 + String zTimeTracked = pObjectMetaData.getPropertyManager().get_String( PMD_TimeTracked.NAME, PMD_TimeTracked.NONE );
216 + if ( PMD_TimeTracked.NONE.equals( zTimeTracked ) )
217 + {
218 + return Collections.emptyList();
219 + }
220 + ArrayList<AttributeProxy> zInjected = new ArrayList<AttributeProxy>();
221 + if ( PMD_TimeTracked.CREATED.equals( zTimeTracked ) || PMD_TimeTracked.BOTH.equals( zTimeTracked ) )
222 + {
223 + zInjected.add( IAP_CREATED );
224 + }
225 + if ( PMD_TimeTracked.LAST_MOD.equals( zTimeTracked ) || PMD_TimeTracked.BOTH.equals( zTimeTracked ) )
226 + {
227 + zInjected.add( IAP_LAST_MOD );
228 + }
229 + return zInjected;
230 + }
231 +
232 + protected MinimalAttributeMetaData getRegularOrInjectedAttribute( ObjectMetaData pObjectMetaData, String pAttrName )
233 + {
234 + AttributeMetaData zAMD = pObjectMetaData.getAttribute( pAttrName );
235 + if ( zAMD != null )
236 + {
237 + return zAMD;
238 + }
239 + List<AttributeProxy> zInjectedAttributes = getInjectedAttributes( pObjectMetaData );
240 + for ( AttributeProxy zAttribute : zInjectedAttributes )
241 + {
242 + if ( zAttribute.getName().equals( pAttrName ) )
243 + {
244 + return zAttribute;
245 + }
246 + }
247 + return null;
248 + }
249 +
250 + protected MinimalAttributeMetaData getAttribute( ObjectMetaData pObjectMetaData, String pAttrName )
217 251 {
218 - AttributeMetaData zAMD = null;
219 - while ( (pObjectMetaData != null) && (null == (zAMD = pObjectMetaData.getAttribute( pAttrName ))) )
252 + MinimalAttributeMetaData zAMD = null;
253 + while ( (pObjectMetaData != null) && (null == (zAMD = getRegularOrInjectedAttribute( pObjectMetaData, pAttrName ))) )
220 254 {
221 255 String zParentName = Utils.noEmpty( pObjectMetaData.getParentName() );
222 256 SystemMetaData zSystemMetaData = pObjectMetaData.getSystemMetaData();
  @@ -278,11 +312,11 @@
278 312 BoAttribute.AttributeType zType = pAttribute.getBoAttributeType();
279 313 if ( zType == null )
280 314 {
281 - mErrorSinc.addError( pPOorVO + " CurrentlyUnsupportedAttributeType", "of: " + pAttribute.getAttributeType(), pAttribute.toString(), mObjectMetaData.toStringForError() );
315 + mErrorSinc.addError( pPOorVO + " CurrentlyUnsupportedAttributeType", "of: " + pAttribute.getAttributeSetType(), pAttribute.toString(), mObjectMetaData.toStringForError() );
282 316 zType = BoAttribute.AttributeType.String;
283 317 }
284 318
285 - AttributeType zAttributeType = pAttribute.getAttributeType();
319 + AttributeType zAttributeType = pAttribute.getAttributeSetType();
286 320 String zEnumType = zType.toString();
287 321
288 322 PropertyManager zPM = pAttribute.getPropertyManager();
  @@ -432,4 +466,176 @@
432 466 addBlankLine();
433 467 }
434 468 }
469 +
470 + private static final InjectedAttributeProxy IAP_CREATED = createSysTimeStampAMD( "Created" );
471 + private static final InjectedAttributeProxy IAP_LAST_MOD = createSysTimeStampAMD( "LastModified" );
472 +
473 + private static InjectedAttributeProxy createSysTimeStampAMD( String pName )
474 + {
475 + return new InjectedAttributeProxy( pName, true, A_Timestamp.TYPE, BoAttribute.AttributeType.SimpleTimestamp );
476 + }
477 +
478 + private static class InjectedAttributeProxy implements AttributeProxy
479 + {
480 + private String mName;
481 + private boolean mSysSetOnly;
482 + private AttributeType mAttributeSetType;
483 + private BoAttribute.AttributeType mBoAttributeType;
484 +
485 + private InjectedAttributeProxy( String pName, boolean pSysSetOnly, AttributeType pAttributeSetType, BoAttribute.AttributeType pBoAttributeType )
486 + {
487 + mName = pName;
488 + mSysSetOnly = pSysSetOnly;
489 + mAttributeSetType = pAttributeSetType;
490 + mBoAttributeType = pBoAttributeType;
491 + if ( pAttributeSetType.getSimpleDataType() != pBoAttributeType.getType() )
492 + {
493 + throw new IllegalArgumentException( "Incompatible AttributeTypes Set=" + pAttributeSetType + " & " + pBoAttributeType + "=BO" );
494 + }
495 + }
496 +
497 + @Override
498 + public boolean isInjected()
499 + {
500 + return true;
501 + }
502 +
503 + @Override
504 + public String getDerivedFromAttribute()
505 + {
506 + return null;
507 + }
508 +
509 + @Override
510 + public String getName()
511 + {
512 + return mName;
513 + }
514 +
515 + @Override
516 + public String getColumnName()
517 + {
518 + return mName;
519 + }
520 +
521 + @Override
522 + public Mutability getMutability()
523 + {
524 + return Mutability.RO;
525 + }
526 +
527 + @Override
528 + public boolean isSysSetOnly()
529 + {
530 + return mSysSetOnly;
531 + }
532 +
533 + @Override
534 + public String getNotes()
535 + {
536 + return null;
537 + }
538 +
539 + @Override
540 + public boolean isVirtual()
541 + {
542 + return false;
543 + }
544 +
545 + @Override
546 + public Class getSimpleDataType()
547 + {
548 + return mAttributeSetType.getSimpleDataType();
549 + }
550 +
551 + @Override
552 + public String[] getValidOptions()
553 + {
554 + return null;
555 + }
556 +
557 + @Override
558 + public BoAttribute.AttributeType getBoAttributeType()
559 + {
560 + return mBoAttributeType;
561 + }
562 +
563 + @Override
564 + public AttributeType getAttributeSetType()
565 + {
566 + return mAttributeSetType;
567 + }
568 +
569 + @Override
570 + public boolean isRequired()
571 + {
572 + return true;
573 + }
574 +
575 + @Override
576 + public boolean isQueryView()
577 + {
578 + return false;
579 + }
580 +
581 + @Override
582 + public PropertyManager getPropertyManager()
583 + {
584 + return PropertyManager.NONE;
585 + }
586 +
587 + @Override
588 + public String getToManyFullyQualifiedName()
589 + {
590 + return null;
591 + }
592 +
593 + @Override
594 + public boolean isToManyInstantiable()
595 + {
596 + return false;
597 + }
598 +
599 + @Override
600 + public String getToManyBackReference()
601 + {
602 + return null;
603 + }
604 +
605 + @Override
606 + public AttributeProxy getToManyBackReferenceAttributeProxy()
607 + {
608 + return null;
609 + }
610 +
611 + @Override
612 + public String getToOneFullyQualifiedName()
613 + {
614 + return null;
615 + }
616 +
617 + @Override
618 + public boolean isToOneInstantiable()
619 + {
620 + return false;
621 + }
622 +
623 + @Override
624 + public String getToOneBackReference()
625 + {
626 + return null;
627 + }
628 +
629 + @Override
630 + public AttributeProxy getToOneBackReferenceAttributeProxy()
631 + {
632 + return null;
633 + }
634 +
635 + @Override
636 + public String toString()
637 + {
638 + return getClass().getSimpleName() + "(" + getSimpleDataType().getSimpleName() + "): " + getName();
639 + }
640 + }
435 641 }