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