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.AttributeFacade;
12 import org.andromda.metafacades.uml.ClassifierFacade;
13 import org.andromda.metafacades.uml.EnumerationFacade;
14 import org.andromda.translation.ocl.validation.OCLCollections;
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.Classifier;
20
21
22
23
24
25
26
27
28 public abstract class EnumerationFacadeLogic
29 extends ClassifierFacadeLogicImpl
30 implements EnumerationFacade
31 {
32
33
34
35
36 protected Object metaObject;
37
38
39
40
41
42 protected EnumerationFacadeLogic(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(EnumerationFacadeLogic.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.EnumerationFacade";
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 isEnumerationFacadeMetaType()
85 {
86 return true;
87 }
88
89
90
91
92
93
94
95 protected abstract String handleGetFromOperationSignature();
96
97 private String __fromOperationSignature1a;
98 private boolean __fromOperationSignature1aSet = false;
99
100
101
102
103
104
105 public final String getFromOperationSignature()
106 {
107 String fromOperationSignature1a = this.__fromOperationSignature1a;
108 if (!this.__fromOperationSignature1aSet)
109 {
110
111 fromOperationSignature1a = handleGetFromOperationSignature();
112
113 this.__fromOperationSignature1a = fromOperationSignature1a;
114 if (isMetafacadePropertyCachingEnabled())
115 {
116 this.__fromOperationSignature1aSet = true;
117 }
118 }
119 return fromOperationSignature1a;
120 }
121
122
123
124
125
126 protected abstract String handleGetFromOperationName();
127
128 private String __fromOperationName2a;
129 private boolean __fromOperationName2aSet = false;
130
131
132
133
134
135
136 public final String getFromOperationName()
137 {
138 String fromOperationName2a = this.__fromOperationName2a;
139 if (!this.__fromOperationName2aSet)
140 {
141
142 fromOperationName2a = handleGetFromOperationName();
143
144 this.__fromOperationName2a = fromOperationName2a;
145 if (isMetafacadePropertyCachingEnabled())
146 {
147 this.__fromOperationName2aSet = true;
148 }
149 }
150 return fromOperationName2a;
151 }
152
153
154
155
156
157 protected abstract boolean handleIsTypeSafe();
158
159 private boolean __typeSafe3a;
160 private boolean __typeSafe3aSet = false;
161
162
163
164
165
166
167 public final boolean isTypeSafe()
168 {
169 boolean typeSafe3a = this.__typeSafe3a;
170 if (!this.__typeSafe3aSet)
171 {
172
173 typeSafe3a = handleIsTypeSafe();
174
175 this.__typeSafe3a = typeSafe3a;
176 if (isMetafacadePropertyCachingEnabled())
177 {
178 this.__typeSafe3aSet = true;
179 }
180 }
181 return typeSafe3a;
182 }
183
184
185
186
187
188
189
190
191
192 public final ClassifierFacade getLiteralType()
193 {
194 ClassifierFacade getLiteralType1r = null;
195
196 Object result = handleGetLiteralType();
197 MetafacadeBase shieldedResult = this.shieldedElement(result);
198 try
199 {
200 getLiteralType1r = (ClassifierFacade)shieldedResult;
201 }
202 catch (ClassCastException ex)
203 {
204
205 EnumerationFacadeLogic.logger.warn("incorrect metafacade cast for EnumerationFacadeLogic.getLiteralType ClassifierFacade " + result + ": " + shieldedResult);
206 }
207
208 return getLiteralType1r;
209 }
210
211
212
213
214
215 protected abstract Object handleGetLiteralType();
216
217
218
219
220
221
222 public final Collection<AttributeFacade> getLiterals()
223 {
224 Collection<AttributeFacade> getLiterals2r = null;
225
226 Collection result = handleGetLiterals();
227 List shieldedResult = this.shieldedElements(result);
228 try
229 {
230 getLiterals2r = (Collection<AttributeFacade>)shieldedResult;
231 }
232 catch (ClassCastException ex)
233 {
234
235 EnumerationFacadeLogic.logger.warn("incorrect metafacade cast for EnumerationFacadeLogic.getLiterals Collection<AttributeFacade> " + result + ": " + shieldedResult);
236 }
237
238 return getLiterals2r;
239 }
240
241
242
243
244
245 protected abstract Collection handleGetLiterals();
246
247
248
249
250
251
252
253 public final Collection<AttributeFacade> getMemberVariables()
254 {
255 Collection<AttributeFacade> getMemberVariables3r = null;
256
257 Collection result = handleGetMemberVariables();
258 List shieldedResult = this.shieldedElements(result);
259 try
260 {
261 getMemberVariables3r = (Collection<AttributeFacade>)shieldedResult;
262 }
263 catch (ClassCastException ex)
264 {
265
266 EnumerationFacadeLogic.logger.warn("incorrect metafacade cast for EnumerationFacadeLogic.getMemberVariables Collection<AttributeFacade> " + result + ": " + shieldedResult);
267 }
268
269 return getMemberVariables3r;
270 }
271
272
273
274
275
276 protected abstract Collection handleGetMemberVariables();
277
278
279
280
281
282
283
284
285
286
287
288
289 @Override
290 public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
291 {
292 super.validateInvariants(validationMessages);
293 try
294 {
295 final Object contextElement = this.THIS();
296 boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"literals")));
297 if (!constraintValid)
298 {
299 validationMessages.add(
300 new ModelValidationMessage(
301 (MetafacadeBase)contextElement ,
302 "org::andromda::metafacades::uml::EnumerationFacade::enumerations must have at least one literal value",
303 "An enumeration must have at least one literal modeled."));
304 }
305 }
306 catch (Throwable th)
307 {
308 Throwable cause = th.getCause();
309 int depth = 0;
310 while (cause != null && depth < 7)
311 {
312 th = cause;
313 depth++;
314 }
315 logger.error("Error validating constraint 'org::andromda::metafacades::uml::EnumerationFacade::enumerations must have at least one literal value' ON "
316 + this.THIS().toString() + ": " + th.getMessage(), th);
317 }
318 try
319 {
320 final Object contextElement = this.THIS();
321 boolean constraintValid = OCLResultEnsurer.ensure(OCLExpressions.equal(OCLIntrospector.invoke(contextElement,"validIdentifierName"),true));
322 if (!constraintValid)
323 {
324 validationMessages.add(
325 new ModelValidationMessage(
326 (MetafacadeBase)contextElement ,
327 "org::andromda::metafacades::uml::EnumerationFacade::name must be a valid identifier",
328 "Model Element name cannot be a reserved word"));
329 }
330 }
331 catch (Throwable th)
332 {
333 Throwable cause = th.getCause();
334 int depth = 0;
335 while (cause != null && depth < 7)
336 {
337 th = cause;
338 depth++;
339 }
340 logger.error("Error validating constraint 'org::andromda::metafacades::uml::EnumerationFacade::name must be a valid identifier' ON "
341 + this.THIS().toString() + ": " + th.getMessage(), th);
342 }
343 }
344 }