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.DependencyFacade;
12 import org.andromda.metafacades.uml.FrontEndAction;
13 import org.andromda.metafacades.uml.FrontEndController;
14 import org.andromda.metafacades.uml.FrontEndUseCase;
15 import org.andromda.translation.ocl.validation.OCLCollections;
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.Classifier;
20
21
22
23
24
25
26
27
28 public abstract class FrontEndControllerLogic
29 extends ClassifierFacadeLogicImpl
30 implements FrontEndController
31 {
32
33
34
35
36 protected Object metaObject;
37
38
39
40
41
42 protected FrontEndControllerLogic(Object metaObjectIn, String context)
43 {
44 super((Classifier)metaObjectIn, getContext(context));
45 this.metaObject = metaObjectIn;
46 }
47
48
49
50
51 private static final Logger logger = Logger.getLogger(FrontEndControllerLogic.class);
52
53
54
55
56
57
58 private static String getContext(String context)
59 {
60 if (context == null)
61 {
62 context = "org.andromda.metafacades.uml.FrontEndController";
63 }
64 return context;
65 }
66
67
68
69
70 @Override
71 public void resetMetafacadeContext(String context)
72 {
73 if (!this.contextRoot)
74 {
75 context = getContext(context);
76 setMetafacadeContext (context);
77 }
78 }
79
80
81
82
83
84 public boolean isFrontEndControllerMetaType()
85 {
86 return true;
87 }
88
89
90
91 private FrontEndUseCase __getUseCase1r;
92 private boolean __getUseCase1rSet = false;
93
94
95
96
97
98 public final FrontEndUseCase getUseCase()
99 {
100 FrontEndUseCase getUseCase1r = this.__getUseCase1r;
101 if (!this.__getUseCase1rSet)
102 {
103
104 Object result = handleGetUseCase();
105 MetafacadeBase shieldedResult = this.shieldedElement(result);
106 try
107 {
108 getUseCase1r = (FrontEndUseCase)shieldedResult;
109 }
110 catch (ClassCastException ex)
111 {
112
113 FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getUseCase FrontEndUseCase " + result + ": " + shieldedResult);
114 }
115
116 this.__getUseCase1r = getUseCase1r;
117 if (isMetafacadePropertyCachingEnabled())
118 {
119 this.__getUseCase1rSet = true;
120 }
121 }
122 return getUseCase1r;
123 }
124
125
126
127
128
129 protected abstract Object handleGetUseCase();
130
131 private List<DependencyFacade> __getServiceReferences2r;
132 private boolean __getServiceReferences2rSet = false;
133
134
135
136
137
138
139 public final List<DependencyFacade> getServiceReferences()
140 {
141 List<DependencyFacade> getServiceReferences2r = this.__getServiceReferences2r;
142 if (!this.__getServiceReferences2rSet)
143 {
144
145 List result = handleGetServiceReferences();
146 List shieldedResult = this.shieldedElements(result);
147 try
148 {
149 getServiceReferences2r = (List<DependencyFacade>)shieldedResult;
150 }
151 catch (ClassCastException ex)
152 {
153
154 FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getServiceReferences List<DependencyFacade> " + result + ": " + shieldedResult);
155 }
156
157 this.__getServiceReferences2r = getServiceReferences2r;
158 if (isMetafacadePropertyCachingEnabled())
159 {
160 this.__getServiceReferences2rSet = true;
161 }
162 }
163 return getServiceReferences2r;
164 }
165
166
167
168
169
170 protected abstract List handleGetServiceReferences();
171
172 private List<FrontEndAction> __getDeferringActions3r;
173 private boolean __getDeferringActions3rSet = false;
174
175
176
177
178
179
180 public final List<FrontEndAction> getDeferringActions()
181 {
182 List<FrontEndAction> getDeferringActions3r = this.__getDeferringActions3r;
183 if (!this.__getDeferringActions3rSet)
184 {
185
186 List result = handleGetDeferringActions();
187 List shieldedResult = this.shieldedElements(result);
188 try
189 {
190 getDeferringActions3r = (List<FrontEndAction>)shieldedResult;
191 }
192 catch (ClassCastException ex)
193 {
194
195 FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getDeferringActions List<FrontEndAction> " + result + ": " + shieldedResult);
196 }
197
198 this.__getDeferringActions3r = getDeferringActions3r;
199 if (isMetafacadePropertyCachingEnabled())
200 {
201 this.__getDeferringActions3rSet = true;
202 }
203 }
204 return getDeferringActions3r;
205 }
206
207
208
209
210
211 protected abstract List handleGetDeferringActions();
212
213
214
215
216
217
218
219
220 @Override
221 public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
222 {
223 super.validateInvariants(validationMessages);
224 try
225 {
226 final Object contextElement = this.THIS();
227 boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"packageName")));
228 if (!constraintValid)
229 {
230 validationMessages.add(
231 new ModelValidationMessage(
232 (MetafacadeBase)contextElement ,
233 "org::andromda::metafacades::uml::FrontEndController::front-end controllers need a package",
234 "Each front-end controller is required to be modeled in a package, doing otherwise will result in uncompileable code due to filename collisions."));
235 }
236 }
237 catch (Throwable th)
238 {
239 Throwable cause = th.getCause();
240 int depth = 0;
241 while (cause != null && depth < 7)
242 {
243 th = cause;
244 depth++;
245 }
246 logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndController::front-end controllers need a package' ON "
247 + this.THIS().toString() + ": " + th.getMessage(), th);
248 }
249 }
250 }