1
2
3
4
5 package org.andromda.metafacades.uml14;
6
7 import java.util.Collection;
8 import org.andromda.core.metafacade.MetafacadeBase;
9 import org.andromda.core.metafacade.ModelValidationMessage;
10 import org.andromda.metafacades.uml.AttributeFacade;
11 import org.andromda.metafacades.uml.ClassifierFacade;
12 import org.andromda.metafacades.uml.EnumerationFacade;
13 import org.andromda.translation.ocl.validation.OCLCollections;
14 import org.andromda.translation.ocl.validation.OCLExpressions;
15 import org.andromda.translation.ocl.validation.OCLIntrospector;
16 import org.andromda.translation.ocl.validation.OCLResultEnsurer;
17 import org.apache.log4j.Logger;
18 import org.omg.uml.foundation.core.Attribute;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public abstract class AttributeFacadeLogic
36 extends ModelElementFacadeLogicImpl
37 implements AttributeFacade
38 {
39
40
41
42
43 protected Attribute metaObject;
44
45
46
47
48
49 protected AttributeFacadeLogic(Attribute metaObjectIn, String context)
50 {
51 super(metaObjectIn, getContext(context));
52 this.metaObject = metaObjectIn;
53 }
54
55
56
57
58 private static final Logger logger = Logger.getLogger(AttributeFacadeLogic.class);
59
60
61
62
63
64
65 private static String getContext(String context)
66 {
67 if (context == null)
68 {
69 context = "org.andromda.metafacades.uml.AttributeFacade";
70 }
71 return context;
72 }
73
74
75
76
77 @Override
78 public void resetMetafacadeContext(String context)
79 {
80 if (!this.contextRoot)
81 {
82 context = getContext(context);
83 setMetafacadeContext (context);
84 }
85 }
86
87
88
89
90
91 public boolean isAttributeFacadeMetaType()
92 {
93 return true;
94 }
95
96
97
98
99
100
101
102 protected abstract String handleGetGetterName();
103
104 private String __getterName1a;
105 private boolean __getterName1aSet = false;
106
107
108
109
110
111 public final String getGetterName()
112 {
113 String getterName1a = this.__getterName1a;
114 if (!this.__getterName1aSet)
115 {
116
117 getterName1a = handleGetGetterName();
118
119 this.__getterName1a = getterName1a;
120 if (isMetafacadePropertyCachingEnabled())
121 {
122 this.__getterName1aSet = true;
123 }
124 }
125 return getterName1a;
126 }
127
128
129
130
131
132 protected abstract String handleGetSetterName();
133
134 private String __setterName2a;
135 private boolean __setterName2aSet = false;
136
137
138
139
140
141 public final String getSetterName()
142 {
143 String setterName2a = this.__setterName2a;
144 if (!this.__setterName2aSet)
145 {
146
147 setterName2a = handleGetSetterName();
148
149 this.__setterName2a = setterName2a;
150 if (isMetafacadePropertyCachingEnabled())
151 {
152 this.__setterName2aSet = true;
153 }
154 }
155 return setterName2a;
156 }
157
158
159
160
161
162 protected abstract boolean handleIsReadOnly();
163
164 private boolean __readOnly3a;
165 private boolean __readOnly3aSet = false;
166
167
168
169
170
171 public final boolean isReadOnly()
172 {
173 boolean readOnly3a = this.__readOnly3a;
174 if (!this.__readOnly3aSet)
175 {
176
177 readOnly3a = handleIsReadOnly();
178
179 this.__readOnly3a = readOnly3a;
180 if (isMetafacadePropertyCachingEnabled())
181 {
182 this.__readOnly3aSet = true;
183 }
184 }
185 return readOnly3a;
186 }
187
188
189
190
191
192 protected abstract String handleGetDefaultValue();
193
194 private String __defaultValue4a;
195 private boolean __defaultValue4aSet = false;
196
197
198
199
200
201 public final String getDefaultValue()
202 {
203 String defaultValue4a = this.__defaultValue4a;
204 if (!this.__defaultValue4aSet)
205 {
206
207 defaultValue4a = handleGetDefaultValue();
208
209 this.__defaultValue4a = defaultValue4a;
210 if (isMetafacadePropertyCachingEnabled())
211 {
212 this.__defaultValue4aSet = true;
213 }
214 }
215 return defaultValue4a;
216 }
217
218
219
220
221
222 protected abstract boolean handleIsStatic();
223
224 private boolean __static5a;
225 private boolean __static5aSet = false;
226
227
228
229
230
231 public final boolean isStatic()
232 {
233 boolean static5a = this.__static5a;
234 if (!this.__static5aSet)
235 {
236
237 static5a = handleIsStatic();
238
239 this.__static5a = static5a;
240 if (isMetafacadePropertyCachingEnabled())
241 {
242 this.__static5aSet = true;
243 }
244 }
245 return static5a;
246 }
247
248
249
250
251
252 protected abstract boolean handleIsRequired();
253
254 private boolean __required6a;
255 private boolean __required6aSet = false;
256
257
258
259
260
261 public final boolean isRequired()
262 {
263 boolean required6a = this.__required6a;
264 if (!this.__required6aSet)
265 {
266
267 required6a = handleIsRequired();
268
269 this.__required6a = required6a;
270 if (isMetafacadePropertyCachingEnabled())
271 {
272 this.__required6aSet = true;
273 }
274 }
275 return required6a;
276 }
277
278
279
280
281
282 protected abstract boolean handleIsMany();
283
284 private boolean __many7a;
285 private boolean __many7aSet = false;
286
287
288
289
290
291 public final boolean isMany()
292 {
293 boolean many7a = this.__many7a;
294 if (!this.__many7aSet)
295 {
296
297 many7a = handleIsMany();
298
299 this.__many7a = many7a;
300 if (isMetafacadePropertyCachingEnabled())
301 {
302 this.__many7aSet = true;
303 }
304 }
305 return many7a;
306 }
307
308
309
310
311
312 protected abstract boolean handleIsChangeable();
313
314 private boolean __changeable8a;
315 private boolean __changeable8aSet = false;
316
317
318
319
320
321 public final boolean isChangeable()
322 {
323 boolean changeable8a = this.__changeable8a;
324 if (!this.__changeable8aSet)
325 {
326
327 changeable8a = handleIsChangeable();
328
329 this.__changeable8a = changeable8a;
330 if (isMetafacadePropertyCachingEnabled())
331 {
332 this.__changeable8aSet = true;
333 }
334 }
335 return changeable8a;
336 }
337
338
339
340
341
342 protected abstract boolean handleIsAddOnly();
343
344 private boolean __addOnly9a;
345 private boolean __addOnly9aSet = false;
346
347
348
349
350
351 public final boolean isAddOnly()
352 {
353 boolean addOnly9a = this.__addOnly9a;
354 if (!this.__addOnly9aSet)
355 {
356
357 addOnly9a = handleIsAddOnly();
358
359 this.__addOnly9a = addOnly9a;
360 if (isMetafacadePropertyCachingEnabled())
361 {
362 this.__addOnly9aSet = true;
363 }
364 }
365 return addOnly9a;
366 }
367
368
369
370
371
372 protected abstract boolean handleIsEnumerationLiteral();
373
374 private boolean __enumerationLiteral10a;
375 private boolean __enumerationLiteral10aSet = false;
376
377
378
379
380
381 public final boolean isEnumerationLiteral()
382 {
383 boolean enumerationLiteral10a = this.__enumerationLiteral10a;
384 if (!this.__enumerationLiteral10aSet)
385 {
386
387 enumerationLiteral10a = handleIsEnumerationLiteral();
388
389 this.__enumerationLiteral10a = enumerationLiteral10a;
390 if (isMetafacadePropertyCachingEnabled())
391 {
392 this.__enumerationLiteral10aSet = true;
393 }
394 }
395 return enumerationLiteral10a;
396 }
397
398
399
400
401
402 protected abstract String handleGetEnumerationValue();
403
404 private String __enumerationValue11a;
405 private boolean __enumerationValue11aSet = false;
406
407
408
409
410
411
412
413 public final String getEnumerationValue()
414 {
415 String enumerationValue11a = this.__enumerationValue11a;
416 if (!this.__enumerationValue11aSet)
417 {
418
419 enumerationValue11a = handleGetEnumerationValue();
420
421 this.__enumerationValue11a = enumerationValue11a;
422 if (isMetafacadePropertyCachingEnabled())
423 {
424 this.__enumerationValue11aSet = true;
425 }
426 }
427 return enumerationValue11a;
428 }
429
430
431
432
433
434 protected abstract String handleGetGetterSetterTypeName();
435
436 private String __getterSetterTypeName12a;
437 private boolean __getterSetterTypeName12aSet = false;
438
439
440
441
442
443
444 public final String getGetterSetterTypeName()
445 {
446 String getterSetterTypeName12a = this.__getterSetterTypeName12a;
447 if (!this.__getterSetterTypeName12aSet)
448 {
449
450 getterSetterTypeName12a = handleGetGetterSetterTypeName();
451
452 this.__getterSetterTypeName12a = getterSetterTypeName12a;
453 if (isMetafacadePropertyCachingEnabled())
454 {
455 this.__getterSetterTypeName12aSet = true;
456 }
457 }
458 return getterSetterTypeName12a;
459 }
460
461
462
463
464
465 protected abstract boolean handleIsOrdered();
466
467 private boolean __ordered13a;
468 private boolean __ordered13aSet = false;
469
470
471
472
473
474 public final boolean isOrdered()
475 {
476 boolean ordered13a = this.__ordered13a;
477 if (!this.__ordered13aSet)
478 {
479
480 ordered13a = handleIsOrdered();
481
482 this.__ordered13a = ordered13a;
483 if (isMetafacadePropertyCachingEnabled())
484 {
485 this.__ordered13aSet = true;
486 }
487 }
488 return ordered13a;
489 }
490
491
492
493
494
495 protected abstract boolean handleIsDefaultValuePresent();
496
497 private boolean __defaultValuePresent14a;
498 private boolean __defaultValuePresent14aSet = false;
499
500
501
502
503
504 public final boolean isDefaultValuePresent()
505 {
506 boolean defaultValuePresent14a = this.__defaultValuePresent14a;
507 if (!this.__defaultValuePresent14aSet)
508 {
509
510 defaultValuePresent14a = handleIsDefaultValuePresent();
511
512 this.__defaultValuePresent14a = defaultValuePresent14a;
513 if (isMetafacadePropertyCachingEnabled())
514 {
515 this.__defaultValuePresent14aSet = true;
516 }
517 }
518 return defaultValuePresent14a;
519 }
520
521
522
523
524
525 protected abstract int handleGetUpper();
526
527 private int __upper15a;
528 private boolean __upper15aSet = false;
529
530
531
532
533
534
535 public final int getUpper()
536 {
537 int upper15a = this.__upper15a;
538 if (!this.__upper15aSet)
539 {
540
541 upper15a = handleGetUpper();
542
543 this.__upper15a = upper15a;
544 if (isMetafacadePropertyCachingEnabled())
545 {
546 this.__upper15aSet = true;
547 }
548 }
549 return upper15a;
550 }
551
552
553
554
555
556 protected abstract int handleGetLower();
557
558 private int __lower16a;
559 private boolean __lower16aSet = false;
560
561
562
563
564
565
566 public final int getLower()
567 {
568 int lower16a = this.__lower16a;
569 if (!this.__lower16aSet)
570 {
571
572 lower16a = handleGetLower();
573
574 this.__lower16a = lower16a;
575 if (isMetafacadePropertyCachingEnabled())
576 {
577 this.__lower16aSet = true;
578 }
579 }
580 return lower16a;
581 }
582
583
584
585
586
587 protected abstract boolean handleIsEnumerationMember();
588
589 private boolean __enumerationMember17a;
590 private boolean __enumerationMember17aSet = false;
591
592
593
594
595
596
597 public final boolean isEnumerationMember()
598 {
599 boolean enumerationMember17a = this.__enumerationMember17a;
600 if (!this.__enumerationMember17aSet)
601 {
602
603 enumerationMember17a = handleIsEnumerationMember();
604
605 this.__enumerationMember17a = enumerationMember17a;
606 if (isMetafacadePropertyCachingEnabled())
607 {
608 this.__enumerationMember17aSet = true;
609 }
610 }
611 return enumerationMember17a;
612 }
613
614
615
616
617
618 protected abstract String handleGetEnumerationLiteralParameters();
619
620 private String __enumerationLiteralParameters18a;
621 private boolean __enumerationLiteralParameters18aSet = false;
622
623
624
625
626
627 public final String getEnumerationLiteralParameters()
628 {
629 String enumerationLiteralParameters18a = this.__enumerationLiteralParameters18a;
630 if (!this.__enumerationLiteralParameters18aSet)
631 {
632
633 enumerationLiteralParameters18a = handleGetEnumerationLiteralParameters();
634
635 this.__enumerationLiteralParameters18a = enumerationLiteralParameters18a;
636 if (isMetafacadePropertyCachingEnabled())
637 {
638 this.__enumerationLiteralParameters18aSet = true;
639 }
640 }
641 return enumerationLiteralParameters18a;
642 }
643
644
645
646
647
648 protected abstract boolean handleIsEnumerationLiteralParametersExist();
649
650 private boolean __enumerationLiteralParametersExist19a;
651 private boolean __enumerationLiteralParametersExist19aSet = false;
652
653
654
655
656
657
658 public final boolean isEnumerationLiteralParametersExist()
659 {
660 boolean enumerationLiteralParametersExist19a = this.__enumerationLiteralParametersExist19a;
661 if (!this.__enumerationLiteralParametersExist19aSet)
662 {
663
664 enumerationLiteralParametersExist19a = handleIsEnumerationLiteralParametersExist();
665
666 this.__enumerationLiteralParametersExist19a = enumerationLiteralParametersExist19a;
667 if (isMetafacadePropertyCachingEnabled())
668 {
669 this.__enumerationLiteralParametersExist19aSet = true;
670 }
671 }
672 return enumerationLiteralParametersExist19a;
673 }
674
675
676
677
678
679 protected abstract boolean handleIsUnique();
680
681 private boolean __unique20a;
682 private boolean __unique20aSet = false;
683
684
685
686
687
688
689 public final boolean isUnique()
690 {
691 boolean unique20a = this.__unique20a;
692 if (!this.__unique20aSet)
693 {
694
695 unique20a = handleIsUnique();
696
697 this.__unique20a = unique20a;
698 if (isMetafacadePropertyCachingEnabled())
699 {
700 this.__unique20aSet = true;
701 }
702 }
703 return unique20a;
704 }
705
706
707
708
709
710 protected abstract boolean handleIsLeaf();
711
712 private boolean __leaf21a;
713 private boolean __leaf21aSet = false;
714
715
716
717
718
719
720 public final boolean isLeaf()
721 {
722 boolean leaf21a = this.__leaf21a;
723 if (!this.__leaf21aSet)
724 {
725
726 leaf21a = handleIsLeaf();
727
728 this.__leaf21a = leaf21a;
729 if (isMetafacadePropertyCachingEnabled())
730 {
731 this.__leaf21aSet = true;
732 }
733 }
734 return leaf21a;
735 }
736
737
738
739
740
741 protected abstract boolean handleIsDerived();
742
743 private boolean __derived22a;
744 private boolean __derived22aSet = false;
745
746
747
748
749
750
751 public final boolean isDerived()
752 {
753 boolean derived22a = this.__derived22a;
754 if (!this.__derived22aSet)
755 {
756
757 derived22a = handleIsDerived();
758
759 this.__derived22a = derived22a;
760 if (isMetafacadePropertyCachingEnabled())
761 {
762 this.__derived22aSet = true;
763 }
764 }
765 return derived22a;
766 }
767
768
769
770
771
772
773
774
775
776
777
778
779 protected abstract Object handleFindTaggedValue(String name, boolean follow);
780
781
782
783
784
785
786
787
788
789
790
791 public Object findTaggedValue(String name, boolean follow)
792 {
793
794 Object returnValue = handleFindTaggedValue(name, follow);
795
796 return returnValue;
797 }
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822 public final ClassifierFacade getType()
823 {
824 ClassifierFacade getType1r = null;
825
826 Object result = handleGetType();
827 MetafacadeBase shieldedResult = this.shieldedElement(result);
828 try
829 {
830 getType1r = (ClassifierFacade)shieldedResult;
831 }
832 catch (ClassCastException ex)
833 {
834
835 AttributeFacadeLogic.logger.warn("incorrect metafacade cast for AttributeFacadeLogic.getType ClassifierFacade " + result + ": " + shieldedResult);
836 }
837
838 return getType1r;
839 }
840
841
842
843
844
845 protected abstract Object handleGetType();
846
847
848
849
850
851 public final EnumerationFacade getEnumeration()
852 {
853 EnumerationFacade getEnumeration2r = null;
854
855 Object result = handleGetEnumeration();
856 MetafacadeBase shieldedResult = this.shieldedElement(result);
857 try
858 {
859 getEnumeration2r = (EnumerationFacade)shieldedResult;
860 }
861 catch (ClassCastException ex)
862 {
863
864 AttributeFacadeLogic.logger.warn("incorrect metafacade cast for AttributeFacadeLogic.getEnumeration EnumerationFacade " + result + ": " + shieldedResult);
865 }
866
867 return getEnumeration2r;
868 }
869
870
871
872
873
874 protected abstract Object handleGetEnumeration();
875
876
877
878
879
880 public final ClassifierFacade getOwner()
881 {
882 ClassifierFacade getOwner3r = null;
883
884 Object result = handleGetOwner();
885 MetafacadeBase shieldedResult = this.shieldedElement(result);
886 try
887 {
888 getOwner3r = (ClassifierFacade)shieldedResult;
889 }
890 catch (ClassCastException ex)
891 {
892
893 AttributeFacadeLogic.logger.warn("incorrect metafacade cast for AttributeFacadeLogic.getOwner ClassifierFacade " + result + ": " + shieldedResult);
894 }
895
896 return getOwner3r;
897 }
898
899
900
901
902
903 protected abstract Object handleGetOwner();
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924 @Override
925 public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
926 {
927 super.validateInvariants(validationMessages);
928 try
929 {
930 final Object contextElement = this.THIS();
931 boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"type.name")));
932 if (!constraintValid)
933 {
934 validationMessages.add(
935 new ModelValidationMessage(
936 (MetafacadeBase)contextElement ,
937 "org::andromda::metafacades::uml::AttributeFacade::attribute needs a type",
938 "Each attribute needs a type, you cannot leave the type unspecified."));
939 }
940 }
941 catch (Throwable th)
942 {
943 Throwable cause = th.getCause();
944 int depth = 0;
945 while (cause != null && depth < 7)
946 {
947 th = cause;
948 depth++;
949 }
950 logger.error("Error validating constraint 'org::andromda::metafacades::uml::AttributeFacade::attribute needs a type' ON "
951 + this.THIS().toString() + ": " + th.getMessage(), th);
952 }
953 try
954 {
955 final Object contextElement = this.THIS();
956 boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"name")));
957 if (!constraintValid)
958 {
959 validationMessages.add(
960 new ModelValidationMessage(
961 (MetafacadeBase)contextElement ,
962 "org::andromda::metafacades::uml::AttributeFacade::attribute must have a name",
963 "Each attribute must have a non-empty name."));
964 }
965 }
966 catch (Throwable th)
967 {
968 Throwable cause = th.getCause();
969 int depth = 0;
970 while (cause != null && depth < 7)
971 {
972 th = cause;
973 depth++;
974 }
975 logger.error("Error validating constraint 'org::andromda::metafacades::uml::AttributeFacade::attribute must have a name' ON "
976 + this.THIS().toString() + ": " + th.getMessage(), th);
977 }
978 try
979 {
980 final Object contextElement = this.THIS();
981 boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(contextElement,"type.primitive"))).booleanValue()?(OCLExpressions.greater(OCLIntrospector.invoke(contextElement,"lower"),0)):true));
982 if (!constraintValid)
983 {
984 validationMessages.add(
985 new ModelValidationMessage(
986 (MetafacadeBase)contextElement ,
987 "org::andromda::metafacades::uml::AttributeFacade::primitive attribute must be required",
988 "Primitive attributes must have a multiplicity lower bound > 0 (must be required). Use a wrapped type, or change the multiplicity."));
989 }
990 }
991 catch (Throwable th)
992 {
993 Throwable cause = th.getCause();
994 int depth = 0;
995 while (cause != null && depth < 7)
996 {
997 th = cause;
998 depth++;
999 }
1000 logger.error("Error validating constraint 'org::andromda::metafacades::uml::AttributeFacade::primitive attribute must be required' ON "
1001 + this.THIS().toString() + ": " + th.getMessage(), th);
1002 }
1003 try
1004 {
1005 final Object contextElement = this.THIS();
1006 boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(contextElement,"type.primitive"))).booleanValue()?(OCLExpressions.equal(OCLIntrospector.invoke(contextElement,"many"),false)):true));
1007 if (!constraintValid)
1008 {
1009 validationMessages.add(
1010 new ModelValidationMessage(
1011 (MetafacadeBase)contextElement ,
1012 "org::andromda::metafacades::uml::AttributeFacade::primitive attribute cannot be used in Collection",
1013 "Primitive attributes cannot be used in Collections (multiplicity > 1). Use the wrapped type instead."));
1014 }
1015 }
1016 catch (Throwable th)
1017 {
1018 Throwable cause = th.getCause();
1019 int depth = 0;
1020 while (cause != null && depth < 7)
1021 {
1022 th = cause;
1023 depth++;
1024 }
1025 logger.error("Error validating constraint 'org::andromda::metafacades::uml::AttributeFacade::primitive attribute cannot be used in Collection' ON "
1026 + this.THIS().toString() + ": " + th.getMessage(), th);
1027 }
1028 try
1029 {
1030 final Object contextElement = this.THIS();
1031 boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(contextElement,"type.wrappedPrimitive"))).booleanValue()&&OCLExpressions.equal(OCLIntrospector.invoke(contextElement,"many"),false))).booleanValue()?(OCLExpressions.equal(OCLIntrospector.invoke(contextElement,"lower"),0)):true));
1032 if (!constraintValid)
1033 {
1034 validationMessages.add(
1035 new ModelValidationMessage(
1036 (MetafacadeBase)contextElement ,
1037 "org::andromda::metafacades::uml::AttributeFacade::wrapped primitive attribute should not be required",
1038 "Wrapped primitive attributes must have a multiplicity lower bound = 0 (must be optional). Use the unwrapped type, or change the multiplicity."));
1039 }
1040 }
1041 catch (Throwable th)
1042 {
1043 Throwable cause = th.getCause();
1044 int depth = 0;
1045 while (cause != null && depth < 7)
1046 {
1047 th = cause;
1048 depth++;
1049 }
1050 logger.error("Error validating constraint 'org::andromda::metafacades::uml::AttributeFacade::wrapped primitive attribute should not be required' ON "
1051 + this.THIS().toString() + ": " + th.getMessage(), th);
1052 }
1053 }
1054 }