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.LinkedHashMap;
7 import java.util.List;
8 import java.util.Map;
9 import org.andromda.metafacades.uml.ActivityGraphFacade;
10 import org.andromda.metafacades.uml.EventFacade;
11 import org.andromda.metafacades.uml.FrontEndAction;
12 import org.andromda.metafacades.uml.FrontEndParameter;
13 import org.andromda.metafacades.uml.FrontEndUseCase;
14 import org.andromda.metafacades.uml.ModelElementFacade;
15 import org.andromda.metafacades.uml.ParameterFacade;
16 import org.andromda.metafacades.uml.StateMachineFacade;
17 import org.andromda.metafacades.uml.TransitionFacade;
18 import org.andromda.metafacades.uml.UMLProfile;
19 import org.andromda.metafacades.uml.UseCaseFacade;
20
21
22
23
24
25
26 public class FrontEndViewLogicImpl
27 extends FrontEndViewLogic
28 {
29 private static final long serialVersionUID = 34L;
30
31
32
33
34 public FrontEndViewLogicImpl(
35 final Object metaObject,
36 final String context)
37 {
38 super(metaObject, context);
39 }
40
41
42
43
44 @Override
45 protected boolean handleIsFrontEndView()
46 {
47 return this.hasStereotype(UMLProfile.STEREOTYPE_FRONT_END_VIEW);
48 }
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 @Override
73 protected UseCaseFacade handleGetUseCase()
74 {
75 UseCaseFacade useCase = null;
76 final StateMachineFacade graphContext = this.getStateMachine();
77 if (graphContext instanceof ActivityGraphFacade)
78 {
79 useCase = ((ActivityGraphFacade)graphContext).getUseCase();
80 if (!(useCase instanceof FrontEndUseCase))
81 {
82 useCase = null;
83 }
84 }
85 return useCase;
86 }
87
88
89
90
91
92
93 @Override
94 public String handleGetPackageName()
95 {
96 String packageName = null;
97 final StateMachineFacade graphContext = this.getStateMachine();
98
99
100 if (graphContext instanceof ActivityGraphFacade)
101 {
102 final UseCaseFacade graphUseCase = ((ActivityGraphFacade)graphContext).getUseCase();
103 if (graphUseCase instanceof FrontEndUseCase)
104 {
105 final FrontEndUseCase useCase = (FrontEndUseCase)graphUseCase;
106 packageName = useCase.getPackageName();
107 }
108 }
109 return packageName;
110 }
111
112
113
114
115 @Override
116 protected List<ModelElementFacade> handleGetVariables()
117 {
118 final Map<String, ModelElementFacade> variablesMap = new LinkedHashMap<String, ModelElementFacade>();
119 final Collection<TransitionFacade> incoming = this.getIncomings();
120 for (final Iterator<TransitionFacade> iterator = incoming.iterator(); iterator.hasNext();)
121 {
122 final TransitionFacade transition = iterator.next();
123 final EventFacade trigger = transition.getTrigger();
124 if (trigger != null)
125 {
126 for (final Iterator<ParameterFacade> parameterIterator = trigger.getParameters().iterator();
127 parameterIterator.hasNext();)
128 {
129 final ModelElementFacade modelElement = (ModelElementFacade)parameterIterator.next();
130 variablesMap.put(
131 modelElement.getName(),
132 modelElement);
133 }
134 }
135 }
136 return new ArrayList<ModelElementFacade>(variablesMap.values());
137 }
138
139
140
141
142 @Override
143 protected List<FrontEndParameter> handleGetAllActionParameters()
144 {
145 final List<FrontEndParameter> actionParameters = new ArrayList<FrontEndParameter>();
146 final Collection<FrontEndAction> actions = this.getActions();
147 for (FrontEndAction action : actions)
148 {
149 actionParameters.addAll(action.getParameters());
150 }
151 return actionParameters;
152 }
153
154
155
156
157 @Override
158 protected List<FrontEndParameter> handleGetAllFormFields()
159 {
160 final List<FrontEndParameter> actionParameters = new ArrayList<FrontEndParameter>();
161 final Collection<FrontEndAction> actions = this.getActions();
162 for (FrontEndAction action : actions)
163 {
164 actionParameters.addAll(action.getParameters());
165 }
166 return actionParameters;
167 }
168
169
170
171
172 @Override
173 protected List<FrontEndParameter> handleGetTables()
174 {
175 final List<FrontEndParameter> variables = new ArrayList<FrontEndParameter>(this.getVariables());
176 for (final Iterator iterator = variables.iterator(); iterator.hasNext();)
177 {
178 final FrontEndParameter parameter = (FrontEndParameter)iterator.next();
179 if (!parameter.isTable())
180 {
181 iterator.remove();
182 }
183 }
184 return variables;
185 }
186
187
188
189
190 @Override
191 protected List<FrontEndAction> handleGetActions()
192 {
193 final List<FrontEndAction> actions = new ArrayList<FrontEndAction>();
194 final Collection<TransitionFacade> outgoing = this.getOutgoings();
195 for (final Iterator<TransitionFacade> iterator = outgoing.iterator(); iterator.hasNext();)
196 {
197 final TransitionFacade object = iterator.next();
198 if (object instanceof FrontEndAction)
199 {
200 actions.add((FrontEndAction)object);
201 }
202 }
203 return actions;
204 }
205 }