1
2
3
4
5 package org.andromda.metafacades.uml14;
6
7 import java.util.Collection;
8 import java.util.List;
9 import org.andromda.core.metafacade.MetafacadeBase;
10 import org.andromda.core.metafacade.ModelValidationMessage;
11 import org.andromda.metafacades.uml.FrontEndAction;
12 import org.andromda.metafacades.uml.FrontEndActivityGraph;
13 import org.andromda.metafacades.uml.FrontEndControllerOperation;
14 import org.andromda.metafacades.uml.FrontEndParameter;
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.Operation;
20
21
22
23
24
25
26
27 public abstract class FrontEndControllerOperationLogic
28 extends OperationFacadeLogicImpl
29 implements FrontEndControllerOperation
30 {
31
32
33
34
35 protected Object metaObject;
36
37
38
39
40
41 protected FrontEndControllerOperationLogic(Object metaObjectIn, String context)
42 {
43 super((Operation)metaObjectIn, getContext(context));
44 this.metaObject = metaObjectIn;
45 }
46
47
48
49
50 private static final Logger logger = Logger.getLogger(FrontEndControllerOperationLogic.class);
51
52
53
54
55
56
57 private static String getContext(String context)
58 {
59 if (context == null)
60 {
61 context = "org.andromda.metafacades.uml.FrontEndControllerOperation";
62 }
63 return context;
64 }
65
66
67
68
69 @Override
70 public void resetMetafacadeContext(String context)
71 {
72 if (!this.contextRoot)
73 {
74 context = getContext(context);
75 setMetafacadeContext (context);
76 }
77 }
78
79
80
81
82
83 public boolean isFrontEndControllerOperationMetaType()
84 {
85 return true;
86 }
87
88
89
90
91
92
93
94 protected abstract boolean handleIsOwnerIsController();
95
96 private boolean __ownerIsController1a;
97 private boolean __ownerIsController1aSet = false;
98
99
100
101
102
103 public final boolean isOwnerIsController()
104 {
105 boolean ownerIsController1a = this.__ownerIsController1a;
106 if (!this.__ownerIsController1aSet)
107 {
108
109 ownerIsController1a = handleIsOwnerIsController();
110
111 this.__ownerIsController1a = ownerIsController1a;
112 if (isMetafacadePropertyCachingEnabled())
113 {
114 this.__ownerIsController1aSet = true;
115 }
116 }
117 return ownerIsController1a;
118 }
119
120
121
122
123
124 protected abstract boolean handleIsAllArgumentsHaveFormFields();
125
126 private boolean __allArgumentsHaveFormFields2a;
127 private boolean __allArgumentsHaveFormFields2aSet = false;
128
129
130
131
132
133
134
135 public final boolean isAllArgumentsHaveFormFields()
136 {
137 boolean allArgumentsHaveFormFields2a = this.__allArgumentsHaveFormFields2a;
138 if (!this.__allArgumentsHaveFormFields2aSet)
139 {
140
141 allArgumentsHaveFormFields2a = handleIsAllArgumentsHaveFormFields();
142
143 this.__allArgumentsHaveFormFields2a = allArgumentsHaveFormFields2a;
144 if (isMetafacadePropertyCachingEnabled())
145 {
146 this.__allArgumentsHaveFormFields2aSet = true;
147 }
148 }
149 return allArgumentsHaveFormFields2a;
150 }
151
152
153
154 private FrontEndActivityGraph __getActivityGraph1r;
155 private boolean __getActivityGraph1rSet = false;
156
157
158
159
160
161 public final FrontEndActivityGraph getActivityGraph()
162 {
163 FrontEndActivityGraph getActivityGraph1r = this.__getActivityGraph1r;
164 if (!this.__getActivityGraph1rSet)
165 {
166
167 Object result = handleGetActivityGraph();
168 MetafacadeBase shieldedResult = this.shieldedElement(result);
169 try
170 {
171 getActivityGraph1r = (FrontEndActivityGraph)shieldedResult;
172 }
173 catch (ClassCastException ex)
174 {
175
176 FrontEndControllerOperationLogic.logger.warn("incorrect metafacade cast for FrontEndControllerOperationLogic.getActivityGraph FrontEndActivityGraph " + result + ": " + shieldedResult);
177 }
178
179 this.__getActivityGraph1r = getActivityGraph1r;
180 if (isMetafacadePropertyCachingEnabled())
181 {
182 this.__getActivityGraph1rSet = true;
183 }
184 }
185 return getActivityGraph1r;
186 }
187
188
189
190
191
192 protected abstract Object handleGetActivityGraph();
193
194 private List<FrontEndParameter> __getFormFields2r;
195 private boolean __getFormFields2rSet = false;
196
197
198
199
200
201 public final List<FrontEndParameter> getFormFields()
202 {
203 List<FrontEndParameter> getFormFields2r = this.__getFormFields2r;
204 if (!this.__getFormFields2rSet)
205 {
206
207 List result = handleGetFormFields();
208 List shieldedResult = this.shieldedElements(result);
209 try
210 {
211 getFormFields2r = (List<FrontEndParameter>)shieldedResult;
212 }
213 catch (ClassCastException ex)
214 {
215
216 FrontEndControllerOperationLogic.logger.warn("incorrect metafacade cast for FrontEndControllerOperationLogic.getFormFields List<FrontEndParameter> " + result + ": " + shieldedResult);
217 }
218
219 this.__getFormFields2r = getFormFields2r;
220 if (isMetafacadePropertyCachingEnabled())
221 {
222 this.__getFormFields2rSet = true;
223 }
224 }
225 return getFormFields2r;
226 }
227
228
229
230
231
232 protected abstract List handleGetFormFields();
233
234 private List<FrontEndAction> __getDeferringActions3r;
235 private boolean __getDeferringActions3rSet = false;
236
237
238
239
240
241 public final List<FrontEndAction> getDeferringActions()
242 {
243 List<FrontEndAction> getDeferringActions3r = this.__getDeferringActions3r;
244 if (!this.__getDeferringActions3rSet)
245 {
246
247 List result = handleGetDeferringActions();
248 List shieldedResult = this.shieldedElements(result);
249 try
250 {
251 getDeferringActions3r = (List<FrontEndAction>)shieldedResult;
252 }
253 catch (ClassCastException ex)
254 {
255
256 FrontEndControllerOperationLogic.logger.warn("incorrect metafacade cast for FrontEndControllerOperationLogic.getDeferringActions List<FrontEndAction> " + result + ": " + shieldedResult);
257 }
258
259 this.__getDeferringActions3r = getDeferringActions3r;
260 if (isMetafacadePropertyCachingEnabled())
261 {
262 this.__getDeferringActions3rSet = true;
263 }
264 }
265 return getDeferringActions3r;
266 }
267
268
269
270
271
272 protected abstract List handleGetDeferringActions();
273
274
275
276
277
278
279
280
281
282
283
284 @Override
285 public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
286 {
287 super.validateInvariants(validationMessages);
288 try
289 {
290 final Object contextElement = this.THIS();
291 boolean constraintValid = OCLResultEnsurer.ensure(OCLIntrospector.invoke(contextElement,"allArgumentsHaveFormFields"));
292 if (!constraintValid)
293 {
294 validationMessages.add(
295 new ModelValidationMessage(
296 (MetafacadeBase)contextElement ,
297 "org::andromda::metafacades::uml::FrontEndControllerOperation::all arguments need an event parameter",
298 "For each controller operation argument there must exist a parameter for each action deferring to that operation. This parameter must carry the same name and must be of the same type."));
299 }
300 }
301 catch (Throwable th)
302 {
303 Throwable cause = th.getCause();
304 int depth = 0;
305 while (cause != null && depth < 7)
306 {
307 th = cause;
308 depth++;
309 }
310 logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndControllerOperation::all arguments need an event parameter' ON "
311 + this.THIS().toString() + ": " + th.getMessage(), th);
312 }
313 try
314 {
315 final Object contextElement = this.THIS();
316 boolean constraintValid = OCLResultEnsurer.ensure(OCLExpressions.notEqual(OCLIntrospector.invoke(contextElement,"name"),OCLIntrospector.invoke(contextElement,"owner.useCase.name")));
317 if (!constraintValid)
318 {
319 validationMessages.add(
320 new ModelValidationMessage(
321 (MetafacadeBase)contextElement ,
322 "org::andromda::metafacades::uml::FrontEndControllerOperation::the operation name may not be the same as the use-case name",
323 "It is not allowed to give a controller operation the same name as the use-case for which it is defined, please either rename your operation or your use-case."));
324 }
325 }
326 catch (Throwable th)
327 {
328 Throwable cause = th.getCause();
329 int depth = 0;
330 while (cause != null && depth < 7)
331 {
332 th = cause;
333 depth++;
334 }
335 logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndControllerOperation::the operation name may not be the same as the use-case name' ON "
336 + this.THIS().toString() + ": " + th.getMessage(), th);
337 }
338 }
339 }