1
2
3
4
5 package org.andromda.cartridges.bpm4struts.metafacades;
6
7 import java.util.Collection;
8 import org.andromda.core.common.Introspector;
9 import org.andromda.core.metafacade.MetafacadeBase;
10 import org.andromda.core.metafacade.MetafacadeFactory;
11 import org.andromda.core.metafacade.ModelValidationMessage;
12 import org.andromda.metafacades.uml.ActionStateFacade;
13 import org.andromda.metafacades.uml.ConstraintFacade;
14 import org.andromda.metafacades.uml.DependencyFacade;
15 import org.andromda.metafacades.uml.FinalStateFacade;
16 import org.andromda.metafacades.uml.FrontEndAction;
17 import org.andromda.metafacades.uml.FrontEndActivityGraph;
18 import org.andromda.metafacades.uml.FrontEndController;
19 import org.andromda.metafacades.uml.ModelElementFacade;
20 import org.andromda.metafacades.uml.ModelFacade;
21 import org.andromda.metafacades.uml.ObjectFlowStateFacade;
22 import org.andromda.metafacades.uml.PackageFacade;
23 import org.andromda.metafacades.uml.PartitionFacade;
24 import org.andromda.metafacades.uml.PseudostateFacade;
25 import org.andromda.metafacades.uml.StateFacade;
26 import org.andromda.metafacades.uml.StateMachineFacade;
27 import org.andromda.metafacades.uml.StereotypeFacade;
28 import org.andromda.metafacades.uml.TaggedValueFacade;
29 import org.andromda.metafacades.uml.TemplateParameterFacade;
30 import org.andromda.metafacades.uml.TransitionFacade;
31 import org.andromda.metafacades.uml.TypeMappings;
32 import org.andromda.metafacades.uml.UseCaseFacade;
33 import org.andromda.translation.ocl.validation.OCLCollections;
34 import org.andromda.translation.ocl.validation.OCLIntrospector;
35 import org.andromda.translation.ocl.validation.OCLResultEnsurer;
36 import org.apache.log4j.Logger;
37
38
39
40
41
42
43
44 public abstract class StrutsActivityGraphLogic
45 extends MetafacadeBase
46 implements StrutsActivityGraph
47 {
48
49
50
51
52 protected Object metaObject;
53
54
55
56
57
58 protected StrutsActivityGraphLogic(Object metaObjectIn, String context)
59 {
60 super(metaObjectIn, getContext(context));
61 this.superFrontEndActivityGraph =
62 (FrontEndActivityGraph)
63 MetafacadeFactory.getInstance().createFacadeImpl(
64 "org.andromda.metafacades.uml.FrontEndActivityGraph",
65 metaObjectIn,
66 getContext(context));
67 this.metaObject = metaObjectIn;
68 }
69
70
71
72
73 private static final Logger logger = Logger.getLogger(StrutsActivityGraphLogic.class);
74
75
76
77
78
79
80 private static String getContext(String context)
81 {
82 if (context == null)
83 {
84 context = "org.andromda.cartridges.bpm4struts.metafacades.StrutsActivityGraph";
85 }
86 return context;
87 }
88
89 private FrontEndActivityGraph superFrontEndActivityGraph;
90 private boolean superFrontEndActivityGraphInitialized = false;
91
92
93
94
95
96 private FrontEndActivityGraph getSuperFrontEndActivityGraph()
97 {
98 if (!this.superFrontEndActivityGraphInitialized)
99 {
100 ((MetafacadeBase)this.superFrontEndActivityGraph).setMetafacadeContext(this.getMetafacadeContext());
101 this.superFrontEndActivityGraphInitialized = true;
102 }
103 return this.superFrontEndActivityGraph;
104 }
105
106
107
108
109
110 @Override
111 public void resetMetafacadeContext(String context)
112 {
113 if (!this.contextRoot)
114 {
115 context = getContext(context);
116 setMetafacadeContext (context);
117 if (this.superFrontEndActivityGraphInitialized)
118 {
119 ((MetafacadeBase)this.superFrontEndActivityGraph).resetMetafacadeContext(context);
120 }
121 }
122 }
123
124
125
126
127
128 public boolean isStrutsActivityGraphMetaType()
129 {
130 return true;
131 }
132
133
134
135 private StrutsAction __getFirstAction1r;
136 private boolean __getFirstAction1rSet = false;
137
138
139
140
141
142 public final StrutsAction getFirstAction()
143 {
144 StrutsAction getFirstAction1r = this.__getFirstAction1r;
145 if (!this.__getFirstAction1rSet)
146 {
147
148 Object result = handleGetFirstAction();
149 MetafacadeBase shieldedResult = this.shieldedElement(result);
150 try
151 {
152 getFirstAction1r = (StrutsAction)shieldedResult;
153 }
154 catch (ClassCastException ex)
155 {
156
157 StrutsActivityGraphLogic.logger.warn("incorrect metafacade cast for StrutsActivityGraphLogic.getFirstAction StrutsAction " + result + ": " + shieldedResult);
158 }
159
160 this.__getFirstAction1r = getFirstAction1r;
161 if (isMetafacadePropertyCachingEnabled())
162 {
163 this.__getFirstAction1rSet = true;
164 }
165 }
166 return getFirstAction1r;
167 }
168
169
170
171
172
173 protected abstract Object handleGetFirstAction();
174
175
176
177
178
179 public boolean isFrontEndActivityGraphMetaType()
180 {
181 return true;
182 }
183
184
185
186
187
188 public boolean isActivityGraphFacadeMetaType()
189 {
190 return true;
191 }
192
193
194
195
196
197 public boolean isStateMachineFacadeMetaType()
198 {
199 return true;
200 }
201
202
203
204
205
206 public boolean isModelElementFacadeMetaType()
207 {
208 return true;
209 }
210
211
212
213
214
215
216 public Collection<ActionStateFacade> getActionStates()
217 {
218 return this.getSuperFrontEndActivityGraph().getActionStates();
219 }
220
221
222
223
224
225 public Collection<ObjectFlowStateFacade> getObjectFlowStates()
226 {
227 return this.getSuperFrontEndActivityGraph().getObjectFlowStates();
228 }
229
230
231
232
233
234
235 public Collection<PartitionFacade> getPartitions()
236 {
237 return this.getSuperFrontEndActivityGraph().getPartitions();
238 }
239
240
241
242
243
244 public UseCaseFacade getUseCase()
245 {
246 return this.getSuperFrontEndActivityGraph().getUseCase();
247 }
248
249
250
251
252
253
254 public FrontEndController getController()
255 {
256 return this.getSuperFrontEndActivityGraph().getController();
257 }
258
259
260
261
262
263
264 public FrontEndAction getInitialAction()
265 {
266 return this.getSuperFrontEndActivityGraph().getInitialAction();
267 }
268
269
270
271
272
273 public boolean isContainedInFrontEndUseCase()
274 {
275 return this.getSuperFrontEndActivityGraph().isContainedInFrontEndUseCase();
276 }
277
278
279
280
281
282 public void copyTaggedValues(ModelElementFacade element)
283 {
284 this.getSuperFrontEndActivityGraph().copyTaggedValues(element);
285 }
286
287
288
289
290
291
292 public Object findTaggedValue(String tagName)
293 {
294 return this.getSuperFrontEndActivityGraph().findTaggedValue(tagName);
295 }
296
297
298
299
300
301
302 public Collection<Object> findTaggedValues(String tagName)
303 {
304 return this.getSuperFrontEndActivityGraph().findTaggedValues(tagName);
305 }
306
307
308
309
310
311
312
313 public String getBindedFullyQualifiedName(ModelElementFacade bindedElement)
314 {
315 return this.getSuperFrontEndActivityGraph().getBindedFullyQualifiedName(bindedElement);
316 }
317
318
319
320
321
322 public Collection<ConstraintFacade> getConstraints()
323 {
324 return this.getSuperFrontEndActivityGraph().getConstraints();
325 }
326
327
328
329
330
331
332 public Collection<ConstraintFacade> getConstraints(String kind)
333 {
334 return this.getSuperFrontEndActivityGraph().getConstraints(kind);
335 }
336
337
338
339
340
341
342
343 public String getDocumentation(String indent)
344 {
345 return this.getSuperFrontEndActivityGraph().getDocumentation(indent);
346 }
347
348
349
350
351
352
353
354
355 public String getDocumentation(String indent, int lineLength)
356 {
357 return this.getSuperFrontEndActivityGraph().getDocumentation(indent, lineLength);
358 }
359
360
361
362
363
364
365
366 public String getDocumentation(String indent, int lineLength, boolean htmlStyle)
367 {
368 return this.getSuperFrontEndActivityGraph().getDocumentation(indent, lineLength, htmlStyle);
369 }
370
371
372
373
374
375 public String getFullyQualifiedName()
376 {
377 return this.getSuperFrontEndActivityGraph().getFullyQualifiedName();
378 }
379
380
381
382
383
384
385
386
387 public String getFullyQualifiedName(boolean modelName)
388 {
389 return this.getSuperFrontEndActivityGraph().getFullyQualifiedName(modelName);
390 }
391
392
393
394
395
396
397 public String getFullyQualifiedNamePath()
398 {
399 return this.getSuperFrontEndActivityGraph().getFullyQualifiedNamePath();
400 }
401
402
403
404
405
406 public String getId()
407 {
408 return this.getSuperFrontEndActivityGraph().getId();
409 }
410
411
412
413
414
415
416
417
418
419 public Collection<String> getKeywords()
420 {
421 return this.getSuperFrontEndActivityGraph().getKeywords();
422 }
423
424
425
426
427
428 public String getLabel()
429 {
430 return this.getSuperFrontEndActivityGraph().getLabel();
431 }
432
433
434
435
436
437 public TypeMappings getLanguageMappings()
438 {
439 return this.getSuperFrontEndActivityGraph().getLanguageMappings();
440 }
441
442
443
444
445
446
447 public ModelFacade getModel()
448 {
449 return this.getSuperFrontEndActivityGraph().getModel();
450 }
451
452
453
454
455
456 public String getName()
457 {
458 return this.getSuperFrontEndActivityGraph().getName();
459 }
460
461
462
463
464
465 public ModelElementFacade getPackage()
466 {
467 return this.getSuperFrontEndActivityGraph().getPackage();
468 }
469
470
471
472
473
474 public String getPackageName()
475 {
476 return this.getSuperFrontEndActivityGraph().getPackageName();
477 }
478
479
480
481
482
483
484 public String getPackageName(boolean modelName)
485 {
486 return this.getSuperFrontEndActivityGraph().getPackageName(modelName);
487 }
488
489
490
491
492
493 public String getPackagePath()
494 {
495 return this.getSuperFrontEndActivityGraph().getPackagePath();
496 }
497
498
499
500
501
502
503
504
505 public String getQualifiedName()
506 {
507 return this.getSuperFrontEndActivityGraph().getQualifiedName();
508 }
509
510
511
512
513
514 public PackageFacade getRootPackage()
515 {
516 return this.getSuperFrontEndActivityGraph().getRootPackage();
517 }
518
519
520
521
522
523 public Collection<DependencyFacade> getSourceDependencies()
524 {
525 return this.getSuperFrontEndActivityGraph().getSourceDependencies();
526 }
527
528
529
530
531
532
533 public StateMachineFacade getStateMachineContext()
534 {
535 return this.getSuperFrontEndActivityGraph().getStateMachineContext();
536 }
537
538
539
540
541
542 public Collection<String> getStereotypeNames()
543 {
544 return this.getSuperFrontEndActivityGraph().getStereotypeNames();
545 }
546
547
548
549
550
551 public Collection<StereotypeFacade> getStereotypes()
552 {
553 return this.getSuperFrontEndActivityGraph().getStereotypes();
554 }
555
556
557
558
559
560 public Collection<TaggedValueFacade> getTaggedValues()
561 {
562 return this.getSuperFrontEndActivityGraph().getTaggedValues();
563 }
564
565
566
567
568
569 public Collection<DependencyFacade> getTargetDependencies()
570 {
571 return this.getSuperFrontEndActivityGraph().getTargetDependencies();
572 }
573
574
575
576
577
578 public Object getTemplateParameter(String parameterName)
579 {
580 return this.getSuperFrontEndActivityGraph().getTemplateParameter(parameterName);
581 }
582
583
584
585
586
587 public Collection<TemplateParameterFacade> getTemplateParameters()
588 {
589 return this.getSuperFrontEndActivityGraph().getTemplateParameters();
590 }
591
592
593
594
595
596
597 public String getVisibility()
598 {
599 return this.getSuperFrontEndActivityGraph().getVisibility();
600 }
601
602
603
604
605
606
607 public boolean hasExactStereotype(String stereotypeName)
608 {
609 return this.getSuperFrontEndActivityGraph().hasExactStereotype(stereotypeName);
610 }
611
612
613
614
615
616
617 public boolean hasKeyword(String keywordName)
618 {
619 return this.getSuperFrontEndActivityGraph().hasKeyword(keywordName);
620 }
621
622
623
624
625
626
627
628
629
630
631
632
633
634 public boolean hasStereotype(String stereotypeName)
635 {
636 return this.getSuperFrontEndActivityGraph().hasStereotype(stereotypeName);
637 }
638
639
640
641
642
643
644 public boolean isBindingDependenciesPresent()
645 {
646 return this.getSuperFrontEndActivityGraph().isBindingDependenciesPresent();
647 }
648
649
650
651
652
653 public boolean isConstraintsPresent()
654 {
655 return this.getSuperFrontEndActivityGraph().isConstraintsPresent();
656 }
657
658
659
660
661
662 public boolean isDocumentationPresent()
663 {
664 return this.getSuperFrontEndActivityGraph().isDocumentationPresent();
665 }
666
667
668
669
670
671 public boolean isReservedWord()
672 {
673 return this.getSuperFrontEndActivityGraph().isReservedWord();
674 }
675
676
677
678
679
680
681 public boolean isTemplateParametersPresent()
682 {
683 return this.getSuperFrontEndActivityGraph().isTemplateParametersPresent();
684 }
685
686
687
688
689
690
691
692 public boolean isValidIdentifierName()
693 {
694 return this.getSuperFrontEndActivityGraph().isValidIdentifierName();
695 }
696
697
698
699
700
701
702
703 public String translateConstraint(String name, String translation)
704 {
705 return this.getSuperFrontEndActivityGraph().translateConstraint(name, translation);
706 }
707
708
709
710
711
712 public String[] translateConstraints(String translation)
713 {
714 return this.getSuperFrontEndActivityGraph().translateConstraints(translation);
715 }
716
717
718
719
720
721 public String[] translateConstraints(String kind, String translation)
722 {
723 return this.getSuperFrontEndActivityGraph().translateConstraints(kind, translation);
724 }
725
726
727
728
729
730
731
732
733
734 public ModelElementFacade getContextElement()
735 {
736 return this.getSuperFrontEndActivityGraph().getContextElement();
737 }
738
739
740
741
742
743
744
745
746 public Collection<FinalStateFacade> getFinalStates()
747 {
748 return this.getSuperFrontEndActivityGraph().getFinalStates();
749 }
750
751
752
753
754
755
756
757 public PseudostateFacade getInitialState()
758 {
759 return this.getSuperFrontEndActivityGraph().getInitialState();
760 }
761
762
763
764
765
766
767 public Collection<PseudostateFacade> getInitialStates()
768 {
769 return this.getSuperFrontEndActivityGraph().getInitialStates();
770 }
771
772
773
774
775
776 public TransitionFacade getInitialTransition()
777 {
778 return this.getSuperFrontEndActivityGraph().getInitialTransition();
779 }
780
781
782
783
784
785
786 public Collection<PseudostateFacade> getPseudostates()
787 {
788 return this.getSuperFrontEndActivityGraph().getPseudostates();
789 }
790
791
792
793
794
795
796
797
798
799
800
801
802 public Collection<StateFacade> getStates()
803 {
804 return this.getSuperFrontEndActivityGraph().getStates();
805 }
806
807
808
809
810
811
812
813
814
815 public Collection<TransitionFacade> getTransitions()
816 {
817 return this.getSuperFrontEndActivityGraph().getTransitions();
818 }
819
820
821
822
823 @Override
824 public void initialize()
825 {
826 this.getSuperFrontEndActivityGraph().initialize();
827 }
828
829
830
831
832
833 @Override
834 public Object getValidationOwner()
835 {
836 Object owner = this.getSuperFrontEndActivityGraph().getValidationOwner();
837 return owner;
838 }
839
840
841
842
843
844 @Override
845 public String getValidationName()
846 {
847 String name = this.getSuperFrontEndActivityGraph().getValidationName();
848 return name;
849 }
850
851
852
853
854
855
856
857
858
859
860
861 @Override
862 public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
863 {
864 this.getSuperFrontEndActivityGraph().validateInvariants(validationMessages);
865 try
866 {
867 final Object contextElement = this.THIS();
868 boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"firstAction")));
869 if (!constraintValid)
870 {
871 validationMessages.add(
872 new ModelValidationMessage(
873 (MetafacadeBase)contextElement ,
874 "org::andromda::cartridges::bpm4struts::metafacades::StrutsActivityGraph::graph must have an action modeled on it's initial state",
875 "Each activity graph must have an action transition exiting the initial state, this is the minimum required."));
876 }
877 }
878 catch (Throwable th)
879 {
880 Throwable cause = th.getCause();
881 int depth = 0;
882 while (cause != null && depth < 7)
883 {
884 th = cause;
885 depth++;
886 }
887 logger.error("Error validating constraint 'org::andromda::cartridges::bpm4struts::metafacades::StrutsActivityGraph::graph must have an action modeled on it's initial state' ON "
888 + this.THIS().toString() + ": " + th.getMessage(), th);
889 }
890 try
891 {
892 final Object contextElement = this.THIS();
893 boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"controller")));
894 if (!constraintValid)
895 {
896 validationMessages.add(
897 new ModelValidationMessage(
898 (MetafacadeBase)contextElement ,
899 "org::andromda::cartridges::bpm4struts::metafacades::StrutsActivityGraph::front end graph must have a controller context",
900 "An activity graph must have a controller class context to which (optionally) operations can be deferred. Make sure this graph's use-case has the FrontEndUseCase stereotype."));
901 }
902 }
903 catch (Throwable th)
904 {
905 Throwable cause = th.getCause();
906 int depth = 0;
907 while (cause != null && depth < 7)
908 {
909 th = cause;
910 depth++;
911 }
912 logger.error("Error validating constraint 'org::andromda::cartridges::bpm4struts::metafacades::StrutsActivityGraph::front end graph must have a controller context' ON "
913 + this.THIS().toString() + ": " + th.getMessage(), th);
914 }
915 }
916
917
918
919
920 private static final String NAME_PROPERTY = "name";
921 private static final String FQNAME_PROPERTY = "fullyQualifiedName";
922
923
924
925
926 @Override
927 public String toString()
928 {
929 final StringBuilder toString = new StringBuilder(this.getClass().getName());
930 toString.append("[");
931 try
932 {
933 toString.append(Introspector.instance().getProperty(this, FQNAME_PROPERTY));
934 }
935 catch (final Throwable tryAgain)
936 {
937 try
938 {
939 toString.append(Introspector.instance().getProperty(this, NAME_PROPERTY));
940 }
941 catch (final Throwable ignore)
942 {
943
944 }
945 }
946 toString.append("]");
947 return toString.toString();
948 }
949 }