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.ClassifierFacade;
11 import org.andromda.metafacades.uml.EventFacade;
12 import org.andromda.metafacades.uml.OperationFacade;
13 import org.andromda.metafacades.uml.ParameterFacade;
14 import org.andromda.translation.ocl.validation.OCLCollections;
15 import org.andromda.translation.ocl.validation.OCLExpressions;
16 import org.andromda.translation.ocl.validation.OCLIntrospector;
17 import org.andromda.translation.ocl.validation.OCLResultEnsurer;
18 import org.apache.log4j.Logger;
19 import org.omg.uml.foundation.core.Parameter;
20
21
22
23
24
25
26
27
28
29 public abstract class ParameterFacadeLogic
30 extends ModelElementFacadeLogicImpl
31 implements ParameterFacade
32 {
33
34
35
36
37 protected Parameter metaObject;
38
39
40
41
42
43 protected ParameterFacadeLogic(Parameter metaObjectIn, String context)
44 {
45 super(metaObjectIn, getContext(context));
46 this.metaObject = metaObjectIn;
47 }
48
49
50
51
52 private static final Logger logger = Logger.getLogger(ParameterFacadeLogic.class);
53
54
55
56
57
58
59 private static String getContext(String context)
60 {
61 if (context == null)
62 {
63 context = "org.andromda.metafacades.uml.ParameterFacade";
64 }
65 return context;
66 }
67
68
69
70
71 @Override
72 public void resetMetafacadeContext(String context)
73 {
74 if (!this.contextRoot)
75 {
76 context = getContext(context);
77 setMetafacadeContext (context);
78 }
79 }
80
81
82
83
84
85 public boolean isParameterFacadeMetaType()
86 {
87 return true;
88 }
89
90
91
92
93
94
95
96 protected abstract String handleGetDefaultValue();
97
98 private String __defaultValue1a;
99 private boolean __defaultValue1aSet = false;
100
101
102
103
104
105 public final String getDefaultValue()
106 {
107 String defaultValue1a = this.__defaultValue1a;
108 if (!this.__defaultValue1aSet)
109 {
110
111 defaultValue1a = handleGetDefaultValue();
112
113 this.__defaultValue1a = defaultValue1a;
114 if (isMetafacadePropertyCachingEnabled())
115 {
116 this.__defaultValue1aSet = true;
117 }
118 }
119 return defaultValue1a;
120 }
121
122
123
124
125
126 protected abstract boolean handleIsDefaultValuePresent();
127
128 private boolean __defaultValuePresent2a;
129 private boolean __defaultValuePresent2aSet = false;
130
131
132
133
134
135 public final boolean isDefaultValuePresent()
136 {
137 boolean defaultValuePresent2a = this.__defaultValuePresent2a;
138 if (!this.__defaultValuePresent2aSet)
139 {
140
141 defaultValuePresent2a = handleIsDefaultValuePresent();
142
143 this.__defaultValuePresent2a = defaultValuePresent2a;
144 if (isMetafacadePropertyCachingEnabled())
145 {
146 this.__defaultValuePresent2aSet = true;
147 }
148 }
149 return defaultValuePresent2a;
150 }
151
152
153
154
155
156 protected abstract String handleGetGetterName();
157
158 private String __getterName3a;
159 private boolean __getterName3aSet = false;
160
161
162
163
164
165 public final String getGetterName()
166 {
167 String getterName3a = this.__getterName3a;
168 if (!this.__getterName3aSet)
169 {
170
171 getterName3a = handleGetGetterName();
172
173 this.__getterName3a = getterName3a;
174 if (isMetafacadePropertyCachingEnabled())
175 {
176 this.__getterName3aSet = true;
177 }
178 }
179 return getterName3a;
180 }
181
182
183
184
185
186 protected abstract String handleGetGetterSetterTypeName();
187
188 private String __getterSetterTypeName4a;
189 private boolean __getterSetterTypeName4aSet = false;
190
191
192
193
194
195
196 public final String getGetterSetterTypeName()
197 {
198 String getterSetterTypeName4a = this.__getterSetterTypeName4a;
199 if (!this.__getterSetterTypeName4aSet)
200 {
201
202 getterSetterTypeName4a = handleGetGetterSetterTypeName();
203
204 this.__getterSetterTypeName4a = getterSetterTypeName4a;
205 if (isMetafacadePropertyCachingEnabled())
206 {
207 this.__getterSetterTypeName4aSet = true;
208 }
209 }
210 return getterSetterTypeName4a;
211 }
212
213
214
215
216
217 protected abstract String handleGetGetterSetterTypeNameImpl();
218
219 private String __getterSetterTypeNameImpl5a;
220 private boolean __getterSetterTypeNameImpl5aSet = false;
221
222
223
224
225
226
227 public final String getGetterSetterTypeNameImpl()
228 {
229 String getterSetterTypeNameImpl5a = this.__getterSetterTypeNameImpl5a;
230 if (!this.__getterSetterTypeNameImpl5aSet)
231 {
232
233 getterSetterTypeNameImpl5a = handleGetGetterSetterTypeNameImpl();
234
235 this.__getterSetterTypeNameImpl5a = getterSetterTypeNameImpl5a;
236 if (isMetafacadePropertyCachingEnabled())
237 {
238 this.__getterSetterTypeNameImpl5aSet = true;
239 }
240 }
241 return getterSetterTypeNameImpl5a;
242 }
243
244
245
246
247
248 protected abstract boolean handleIsRequired();
249
250 private boolean __required6a;
251 private boolean __required6aSet = false;
252
253
254
255
256
257 public final boolean isRequired()
258 {
259 boolean required6a = this.__required6a;
260 if (!this.__required6aSet)
261 {
262
263 required6a = handleIsRequired();
264
265 this.__required6a = required6a;
266 if (isMetafacadePropertyCachingEnabled())
267 {
268 this.__required6aSet = true;
269 }
270 }
271 return required6a;
272 }
273
274
275
276
277
278 protected abstract boolean handleIsReturn();
279
280 private boolean __return7a;
281 private boolean __return7aSet = false;
282
283
284
285
286
287 public final boolean isReturn()
288 {
289 boolean return7a = this.__return7a;
290 if (!this.__return7aSet)
291 {
292
293 return7a = handleIsReturn();
294
295 this.__return7a = return7a;
296 if (isMetafacadePropertyCachingEnabled())
297 {
298 this.__return7aSet = true;
299 }
300 }
301 return return7a;
302 }
303
304
305
306
307
308 protected abstract String handleGetSetterName();
309
310 private String __setterName8a;
311 private boolean __setterName8aSet = false;
312
313
314
315
316
317 public final String getSetterName()
318 {
319 String setterName8a = this.__setterName8a;
320 if (!this.__setterName8aSet)
321 {
322
323 setterName8a = handleGetSetterName();
324
325 this.__setterName8a = setterName8a;
326 if (isMetafacadePropertyCachingEnabled())
327 {
328 this.__setterName8aSet = true;
329 }
330 }
331 return setterName8a;
332 }
333
334
335
336
337
338 protected abstract boolean handleIsReadable();
339
340 private boolean __readable9a;
341 private boolean __readable9aSet = false;
342
343
344
345
346
347 public final boolean isReadable()
348 {
349 boolean readable9a = this.__readable9a;
350 if (!this.__readable9aSet)
351 {
352
353 readable9a = handleIsReadable();
354
355 this.__readable9a = readable9a;
356 if (isMetafacadePropertyCachingEnabled())
357 {
358 this.__readable9aSet = true;
359 }
360 }
361 return readable9a;
362 }
363
364
365
366
367
368 protected abstract boolean handleIsWritable();
369
370 private boolean __writable10a;
371 private boolean __writable10aSet = false;
372
373
374
375
376
377 public final boolean isWritable()
378 {
379 boolean writable10a = this.__writable10a;
380 if (!this.__writable10aSet)
381 {
382
383 writable10a = handleIsWritable();
384
385 this.__writable10a = writable10a;
386 if (isMetafacadePropertyCachingEnabled())
387 {
388 this.__writable10aSet = true;
389 }
390 }
391 return writable10a;
392 }
393
394
395
396
397
398 protected abstract boolean handleIsInParameter();
399
400 private boolean __inParameter11a;
401 private boolean __inParameter11aSet = false;
402
403
404
405
406
407 public final boolean isInParameter()
408 {
409 boolean inParameter11a = this.__inParameter11a;
410 if (!this.__inParameter11aSet)
411 {
412
413 inParameter11a = handleIsInParameter();
414
415 this.__inParameter11a = inParameter11a;
416 if (isMetafacadePropertyCachingEnabled())
417 {
418 this.__inParameter11aSet = true;
419 }
420 }
421 return inParameter11a;
422 }
423
424
425
426
427
428 protected abstract boolean handleIsOutParameter();
429
430 private boolean __outParameter12a;
431 private boolean __outParameter12aSet = false;
432
433
434
435
436
437 public final boolean isOutParameter()
438 {
439 boolean outParameter12a = this.__outParameter12a;
440 if (!this.__outParameter12aSet)
441 {
442
443 outParameter12a = handleIsOutParameter();
444
445 this.__outParameter12a = outParameter12a;
446 if (isMetafacadePropertyCachingEnabled())
447 {
448 this.__outParameter12aSet = true;
449 }
450 }
451 return outParameter12a;
452 }
453
454
455
456
457
458 protected abstract boolean handleIsInoutParameter();
459
460 private boolean __inoutParameter13a;
461 private boolean __inoutParameter13aSet = false;
462
463
464
465
466
467 public final boolean isInoutParameter()
468 {
469 boolean inoutParameter13a = this.__inoutParameter13a;
470 if (!this.__inoutParameter13aSet)
471 {
472
473 inoutParameter13a = handleIsInoutParameter();
474
475 this.__inoutParameter13a = inoutParameter13a;
476 if (isMetafacadePropertyCachingEnabled())
477 {
478 this.__inoutParameter13aSet = true;
479 }
480 }
481 return inoutParameter13a;
482 }
483
484
485
486
487
488 protected abstract int handleGetUpper();
489
490 private int __upper14a;
491 private boolean __upper14aSet = false;
492
493
494
495
496
497
498 public final int getUpper()
499 {
500 int upper14a = this.__upper14a;
501 if (!this.__upper14aSet)
502 {
503
504 upper14a = handleGetUpper();
505
506 this.__upper14a = upper14a;
507 if (isMetafacadePropertyCachingEnabled())
508 {
509 this.__upper14aSet = true;
510 }
511 }
512 return upper14a;
513 }
514
515
516
517
518
519 protected abstract int handleGetLower();
520
521 private int __lower15a;
522 private boolean __lower15aSet = false;
523
524
525
526
527
528
529 public final int getLower()
530 {
531 int lower15a = this.__lower15a;
532 if (!this.__lower15aSet)
533 {
534
535 lower15a = handleGetLower();
536
537 this.__lower15a = lower15a;
538 if (isMetafacadePropertyCachingEnabled())
539 {
540 this.__lower15aSet = true;
541 }
542 }
543 return lower15a;
544 }
545
546
547
548
549
550 protected abstract boolean handleIsUnique();
551
552 private boolean __unique16a;
553 private boolean __unique16aSet = false;
554
555
556
557
558
559
560 public final boolean isUnique()
561 {
562 boolean unique16a = this.__unique16a;
563 if (!this.__unique16aSet)
564 {
565
566 unique16a = handleIsUnique();
567
568 this.__unique16a = unique16a;
569 if (isMetafacadePropertyCachingEnabled())
570 {
571 this.__unique16aSet = true;
572 }
573 }
574 return unique16a;
575 }
576
577
578
579
580
581 protected abstract boolean handleIsOrdered();
582
583 private boolean __ordered17a;
584 private boolean __ordered17aSet = false;
585
586
587
588
589
590
591 public final boolean isOrdered()
592 {
593 boolean ordered17a = this.__ordered17a;
594 if (!this.__ordered17aSet)
595 {
596
597 ordered17a = handleIsOrdered();
598
599 this.__ordered17a = ordered17a;
600 if (isMetafacadePropertyCachingEnabled())
601 {
602 this.__ordered17aSet = true;
603 }
604 }
605 return ordered17a;
606 }
607
608
609
610
611
612 protected abstract boolean handleIsMany();
613
614 private boolean __many18a;
615 private boolean __many18aSet = false;
616
617
618
619
620
621 public final boolean isMany()
622 {
623 boolean many18a = this.__many18a;
624 if (!this.__many18aSet)
625 {
626
627 many18a = handleIsMany();
628
629 this.__many18a = many18a;
630 if (isMetafacadePropertyCachingEnabled())
631 {
632 this.__many18aSet = true;
633 }
634 }
635 return many18a;
636 }
637
638
639
640
641
642 protected abstract boolean handleIsException();
643
644 private boolean __exception19a;
645 private boolean __exception19aSet = false;
646
647
648
649
650
651
652 public final boolean isException()
653 {
654 boolean exception19a = this.__exception19a;
655 if (!this.__exception19aSet)
656 {
657
658 exception19a = handleIsException();
659
660 this.__exception19a = exception19a;
661 if (isMetafacadePropertyCachingEnabled())
662 {
663 this.__exception19aSet = true;
664 }
665 }
666 return exception19a;
667 }
668
669
670
671
672
673 protected abstract String handleGetEffect();
674
675 private String __effect20a;
676 private boolean __effect20aSet = false;
677
678
679
680
681
682
683
684 public final String getEffect()
685 {
686 String effect20a = this.__effect20a;
687 if (!this.__effect20aSet)
688 {
689
690 effect20a = handleGetEffect();
691
692 this.__effect20a = effect20a;
693 if (isMetafacadePropertyCachingEnabled())
694 {
695 this.__effect20aSet = true;
696 }
697 }
698 return effect20a;
699 }
700
701
702
703
704
705
706
707
708
709
710
711 public final ClassifierFacade getType()
712 {
713 ClassifierFacade getType1r = null;
714
715 Object result = handleGetType();
716 MetafacadeBase shieldedResult = this.shieldedElement(result);
717 try
718 {
719 getType1r = (ClassifierFacade)shieldedResult;
720 }
721 catch (ClassCastException ex)
722 {
723
724 ParameterFacadeLogic.logger.warn("incorrect metafacade cast for ParameterFacadeLogic.getType ClassifierFacade " + result + ": " + shieldedResult);
725 }
726
727 return getType1r;
728 }
729
730
731
732
733
734 protected abstract Object handleGetType();
735
736
737
738
739
740 public final EventFacade getEvent()
741 {
742 EventFacade getEvent2r = null;
743
744 Object result = handleGetEvent();
745 MetafacadeBase shieldedResult = this.shieldedElement(result);
746 try
747 {
748 getEvent2r = (EventFacade)shieldedResult;
749 }
750 catch (ClassCastException ex)
751 {
752
753 ParameterFacadeLogic.logger.warn("incorrect metafacade cast for ParameterFacadeLogic.getEvent EventFacade " + result + ": " + shieldedResult);
754 }
755
756 return getEvent2r;
757 }
758
759
760
761
762
763 protected abstract Object handleGetEvent();
764
765
766
767
768
769 public final OperationFacade getOperation()
770 {
771 OperationFacade getOperation3r = null;
772
773 Object result = handleGetOperation();
774 MetafacadeBase shieldedResult = this.shieldedElement(result);
775 try
776 {
777 getOperation3r = (OperationFacade)shieldedResult;
778 }
779 catch (ClassCastException ex)
780 {
781
782 ParameterFacadeLogic.logger.warn("incorrect metafacade cast for ParameterFacadeLogic.getOperation OperationFacade " + result + ": " + shieldedResult);
783 }
784
785 return getOperation3r;
786 }
787
788
789
790
791
792 protected abstract Object handleGetOperation();
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816 @Override
817 public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
818 {
819 super.validateInvariants(validationMessages);
820 try
821 {
822 final Object contextElement = this.THIS();
823 boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLExpressions.equal(OCLIntrospector.invoke(contextElement,"return"),false))).booleanValue()?OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"type.name")):true));
824 if (!constraintValid)
825 {
826 validationMessages.add(
827 new ModelValidationMessage(
828 (MetafacadeBase)contextElement ,
829 "org::andromda::metafacades::uml::ParameterFacade::parameter needs a type",
830 "Each parameter needs a type, you cannot leave the type unspecified."));
831 }
832 }
833 catch (Throwable th)
834 {
835 Throwable cause = th.getCause();
836 int depth = 0;
837 while (cause != null && depth < 7)
838 {
839 th = cause;
840 depth++;
841 }
842 logger.error("Error validating constraint 'org::andromda::metafacades::uml::ParameterFacade::parameter needs a type' ON "
843 + this.THIS().toString() + ": " + th.getMessage(), th);
844 }
845 try
846 {
847 final Object contextElement = this.THIS();
848 boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLExpressions.equal(OCLIntrospector.invoke(contextElement,"return"),false))).booleanValue()?OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"name")):true));
849 if (!constraintValid)
850 {
851 validationMessages.add(
852 new ModelValidationMessage(
853 (MetafacadeBase)contextElement ,
854 "org::andromda::metafacades::uml::ParameterFacade::non return type parameters must be named",
855 "Each parameter that is NOT a return parameter must have a non-empty name."));
856 }
857 }
858 catch (Throwable th)
859 {
860 Throwable cause = th.getCause();
861 int depth = 0;
862 while (cause != null && depth < 7)
863 {
864 th = cause;
865 depth++;
866 }
867 logger.error("Error validating constraint 'org::andromda::metafacades::uml::ParameterFacade::non return type parameters must be named' ON "
868 + this.THIS().toString() + ": " + th.getMessage(), th);
869 }
870 try
871 {
872 final Object contextElement = this.THIS();
873 boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(contextElement,"type.primitive"))).booleanValue()?(OCLExpressions.equal(OCLIntrospector.invoke(contextElement,"many"),false)):true));
874 if (!constraintValid)
875 {
876 validationMessages.add(
877 new ModelValidationMessage(
878 (MetafacadeBase)contextElement ,
879 "org::andromda::metafacades::uml::ParameterFacade::primitive parameter cannot be used in Collection",
880 "Primitive parameters cannot be used in Collections (multiplicity > 1). Use the wrapped type instead."));
881 }
882 }
883 catch (Throwable th)
884 {
885 Throwable cause = th.getCause();
886 int depth = 0;
887 while (cause != null && depth < 7)
888 {
889 th = cause;
890 depth++;
891 }
892 logger.error("Error validating constraint 'org::andromda::metafacades::uml::ParameterFacade::primitive parameter cannot be used in Collection' ON "
893 + this.THIS().toString() + ": " + th.getMessage(), th);
894 }
895 try
896 {
897 final Object contextElement = this.THIS();
898 boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(contextElement,"type.primitive"))).booleanValue()?(OCLExpressions.greater(OCLIntrospector.invoke(contextElement,"lower"),0)):true));
899 if (!constraintValid)
900 {
901 validationMessages.add(
902 new ModelValidationMessage(
903 (MetafacadeBase)contextElement ,
904 "org::andromda::metafacades::uml::ParameterFacade::primitive parameter must be required",
905 "Primitive operation parameters must have a multiplicity lower bound > 0 (must be required). Use a wrapped type, or change the multiplicity."));
906 }
907 }
908 catch (Throwable th)
909 {
910 Throwable cause = th.getCause();
911 int depth = 0;
912 while (cause != null && depth < 7)
913 {
914 th = cause;
915 depth++;
916 }
917 logger.error("Error validating constraint 'org::andromda::metafacades::uml::ParameterFacade::primitive parameter must be required' ON "
918 + this.THIS().toString() + ": " + th.getMessage(), th);
919 }
920 try
921 {
922 final Object contextElement = this.THIS();
923 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));
924 if (!constraintValid)
925 {
926 validationMessages.add(
927 new ModelValidationMessage(
928 (MetafacadeBase)contextElement ,
929 "org::andromda::metafacades::uml::ParameterFacade::wrapped primitive parameter should not be required",
930 "Wrapped primitive operation parameters must have a multiplicity lower bound = 0 (must be optional). Use the unwrapped type, or change the multiplicity."));
931 }
932 }
933 catch (Throwable th)
934 {
935 Throwable cause = th.getCause();
936 int depth = 0;
937 while (cause != null && depth < 7)
938 {
939 th = cause;
940 depth++;
941 }
942 logger.error("Error validating constraint 'org::andromda::metafacades::uml::ParameterFacade::wrapped primitive parameter should not be required' ON "
943 + this.THIS().toString() + ": " + th.getMessage(), th);
944 }
945 }
946 }