1 package org.andromda.metafacades.emf.uml22;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Iterator;
6 import java.util.List;
7 import org.andromda.metafacades.uml.FrontEndAction;
8 import org.andromda.metafacades.uml.FrontEndControllerOperation;
9 import org.andromda.metafacades.uml.FrontEndUseCase;
10 import org.andromda.metafacades.uml.TransitionFacade;
11 import org.apache.commons.lang.StringUtils;
12 import org.eclipse.uml2.uml.Activity;
13 import org.eclipse.uml2.uml.ActivityNode;
14 import org.eclipse.uml2.uml.CallOperationAction;
15 import org.eclipse.uml2.uml.Element;
16 import org.eclipse.uml2.uml.NamedElement;
17 import org.eclipse.uml2.uml.Operation;
18 import org.eclipse.uml2.uml.Transition;
19 import org.eclipse.uml2.uml.UseCase;
20
21
22
23
24
25
26
27 public class FrontEndEventLogicImpl
28 extends FrontEndEventLogic
29 {
30 private static final long serialVersionUID = 34L;
31
32
33
34
35 public FrontEndEventLogicImpl(
36 final Object metaObject,
37 final String context)
38 {
39 super(metaObject, context);
40 }
41
42
43
44
45 @Override
46 protected boolean handleIsContainedInFrontEndUseCase()
47 {
48
49
50
51
52 Element owner = (Element)this.metaObject;
53 if (!(owner.getOwner() instanceof Transition))
54 {
55 return false;
56 }
57 while (owner != null)
58 {
59 if (owner instanceof UseCase)
60 {
61 if (this.shieldedElement(owner) instanceof FrontEndUseCase)
62 {
63 return true;
64 }
65 }
66 owner = owner.getOwner();
67 }
68 return false;
69 }
70
71
72
73
74 @Override
75 protected FrontEndControllerOperation handleGetControllerCall()
76 {
77 final List<FrontEndControllerOperation> operations = this.getControllerCalls();
78 return (operations.isEmpty() ? null : operations.iterator().next());
79 }
80
81
82
83
84 @Override
85 public List<Operation> handleGetControllerCalls()
86 {
87
88
89 final Activity activity = (Activity)this.metaObject;
90 final List<Operation> operations = new ArrayList<Operation>();
91 Collection<ActivityNode> nodes = activity.getNodes();
92
93
94 if (nodes==null || nodes.isEmpty())
95 {
96 nodes = activity.getOwnedNodes();
97 }
98 for (final Iterator<ActivityNode> iterator = nodes.iterator(); iterator.hasNext();)
99 {
100 final Object nextNode = iterator.next();
101 if (nextNode instanceof CallOperationAction)
102 {
103 final Operation operation = ((CallOperationAction)nextNode).getOperation();
104 if (operation != null)
105 {
106 operations.add(operation);
107 }
108 }
109 }
110 return operations;
111 }
112
113
114
115
116 @Override
117 protected FrontEndAction handleGetAction()
118 {
119 FrontEndAction action = null;
120 final TransitionFacade transition = this.getTransition();
121 if (transition instanceof FrontEndAction)
122 {
123 action = (FrontEndAction)transition;
124 }
125 return action;
126 }
127
128
129
130
131
132 @Override
133 protected String handleGetPackageName()
134 {
135 String packageName = UmlUtilities.getPackageName((NamedElement)this.metaObject, ".", false);
136 if (StringUtils.isBlank(packageName))
137 {
138 packageName = this.getPackage().getFullyQualifiedName();
139 }
140 return packageName;
141 }
142 }