1 // license-header java merge-point
2 //
3 // Attention: generated code (by MetafacadeLogic.vsl) - do not modify!
4 //
5 package org.andromda.metafacades.emf.uml22;
6
7 import java.util.Collection;
8 import org.andromda.core.metafacade.MetafacadeBase;
9 import org.andromda.core.metafacade.ModelValidationMessage;
10 import org.andromda.metafacades.uml.ConstraintFacade;
11 import org.andromda.metafacades.uml.ModelElementFacade;
12 import org.apache.log4j.Logger;
13 import org.eclipse.uml2.uml.Constraint;
14
15 /**
16 * Condition or restriction expressed in natural language text or in a machine readable language for
17 * the purpose of declaring some of the semantics of an element.
18 * MetafacadeLogic for ConstraintFacade
19 *
20 * @see ConstraintFacade
21 */
22 public abstract class ConstraintFacadeLogic
23 extends ModelElementFacadeLogicImpl
24 implements ConstraintFacade
25 {
26 /**
27 * The underlying UML object
28 * @see Constraint
29 */
30 protected Constraint metaObject;
31
32 /** Create Metafacade implementation instance using the MetafacadeFactory from the context
33 * @param metaObjectIn
34 * @param context
35 */
36 protected ConstraintFacadeLogic(Constraint metaObjectIn, String context)
37 {
38 super(metaObjectIn, getContext(context));
39 this.metaObject = metaObjectIn;
40 }
41
42 /**
43 * The logger instance.
44 */
45 private static final Logger logger = Logger.getLogger(ConstraintFacadeLogic.class);
46
47 /**
48 * Gets the context for this metafacade logic instance.
49 * @param context String. Set to ConstraintFacade if null
50 * @return context String
51 */
52 private static String getContext(String context)
53 {
54 if (context == null)
55 {
56 context = "org.andromda.metafacades.uml.ConstraintFacade";
57 }
58 return context;
59 }
60
61 /** Reset context only for non-root metafacades
62 * @param context
63 */
64 @Override
65 public void resetMetafacadeContext(String context)
66 {
67 if (!this.contextRoot) // reset context only for non-root metafacades
68 {
69 context = getContext(context); // to have same value as in original constructor call
70 setMetafacadeContext (context);
71 }
72 }
73
74 /**
75 * @return boolean true always
76 * @see ConstraintFacade
77 */
78 public boolean isConstraintFacadeMetaType()
79 {
80 return true;
81 }
82
83 // --------------- attributes ---------------------
84
85 /**
86 * @see ConstraintFacade#getBody()
87 * @return String
88 */
89 protected abstract String handleGetBody();
90
91 private String __body1a;
92 private boolean __body1aSet = false;
93
94 /**
95 * Gets the 'body' or text of this constraint.
96 * @return (String)handleGetBody()
97 */
98 public final String getBody()
99 {
100 String body1a = this.__body1a;
101 if (!this.__body1aSet)
102 {
103 // body has no pre constraints
104 body1a = handleGetBody();
105 // body has no post constraints
106 this.__body1a = body1a;
107 if (isMetafacadePropertyCachingEnabled())
108 {
109 this.__body1aSet = true;
110 }
111 }
112 return body1a;
113 }
114
115 /**
116 * @see ConstraintFacade#isInvariant()
117 * @return boolean
118 */
119 protected abstract boolean handleIsInvariant();
120
121 private boolean __invariant2a;
122 private boolean __invariant2aSet = false;
123
124 /**
125 * True if this constraint denotes an invariant.
126 * For example:
127 * <pre>
128 * context LivingAnimal
129 * inv: alive = true
130 * </pre>
131 * False otherwise.
132 * @return (boolean)handleIsInvariant()
133 */
134 public final boolean isInvariant()
135 {
136 boolean invariant2a = this.__invariant2a;
137 if (!this.__invariant2aSet)
138 {
139 // invariant has no pre constraints
140 invariant2a = handleIsInvariant();
141 // invariant has no post constraints
142 this.__invariant2a = invariant2a;
143 if (isMetafacadePropertyCachingEnabled())
144 {
145 this.__invariant2aSet = true;
146 }
147 }
148 return invariant2a;
149 }
150
151 /**
152 * @see ConstraintFacade#isPreCondition()
153 * @return boolean
154 */
155 protected abstract boolean handleIsPreCondition();
156
157 private boolean __preCondition3a;
158 private boolean __preCondition3aSet = false;
159
160 /**
161 * True if this constraint denotes a precondition.
162 * For example:
163 * <pre>
164 * context LivingAnimal::canFly()
165 * pre: hasWings = true
166 * </pre>
167 * False otherwise.
168 * @return (boolean)handleIsPreCondition()
169 */
170 public final boolean isPreCondition()
171 {
172 boolean preCondition3a = this.__preCondition3a;
173 if (!this.__preCondition3aSet)
174 {
175 // preCondition has no pre constraints
176 preCondition3a = handleIsPreCondition();
177 // preCondition has no post constraints
178 this.__preCondition3a = preCondition3a;
179 if (isMetafacadePropertyCachingEnabled())
180 {
181 this.__preCondition3aSet = true;
182 }
183 }
184 return preCondition3a;
185 }
186
187 /**
188 * @see ConstraintFacade#isPostCondition()
189 * @return boolean
190 */
191 protected abstract boolean handleIsPostCondition();
192
193 private boolean __postCondition4a;
194 private boolean __postCondition4aSet = false;
195
196 /**
197 * True if this constraint denotes a postcondition.
198 * For example:
199 * <pre>
200 * context LivingAnimal::getNumberOfLegs()
201 * post: numberOfLegs >= 0
202 * </pre>
203 * False otherwise.
204 * @return (boolean)handleIsPostCondition()
205 */
206 public final boolean isPostCondition()
207 {
208 boolean postCondition4a = this.__postCondition4a;
209 if (!this.__postCondition4aSet)
210 {
211 // postCondition has no pre constraints
212 postCondition4a = handleIsPostCondition();
213 // postCondition has no post constraints
214 this.__postCondition4a = postCondition4a;
215 if (isMetafacadePropertyCachingEnabled())
216 {
217 this.__postCondition4aSet = true;
218 }
219 }
220 return postCondition4a;
221 }
222
223 /**
224 * @see ConstraintFacade#isDefinition()
225 * @return boolean
226 */
227 protected abstract boolean handleIsDefinition();
228
229 private boolean __definition5a;
230 private boolean __definition5aSet = false;
231
232 /**
233 * True if this constraint denotes a definition.
234 * For example:
235 * <pre>
236 * context CustomerCard
237 * def: getTotalPoints(d: date) : Integer = transaction->select(date.isAfter(d)).points->sum()
238 * </pre>
239 * False otherwise.
240 * @return (boolean)handleIsDefinition()
241 */
242 public final boolean isDefinition()
243 {
244 boolean definition5a = this.__definition5a;
245 if (!this.__definition5aSet)
246 {
247 // definition has no pre constraints
248 definition5a = handleIsDefinition();
249 // definition has no post constraints
250 this.__definition5a = definition5a;
251 if (isMetafacadePropertyCachingEnabled())
252 {
253 this.__definition5aSet = true;
254 }
255 }
256 return definition5a;
257 }
258
259 /**
260 * @see ConstraintFacade#isBodyExpression()
261 * @return boolean
262 */
263 protected abstract boolean handleIsBodyExpression();
264
265 private boolean __bodyExpression6a;
266 private boolean __bodyExpression6aSet = false;
267
268 /**
269 * True if this constraint denotes a body expression.
270 * For example:
271 * <pre>
272 * context CustomerCard:getTransaction(from:Date, until:Date)
273 * body: transactions->select(date.isAfter(from) and date.isBefore(until))
274 * </pre>
275 * False otherwise.
276 * @return (boolean)handleIsBodyExpression()
277 */
278 public final boolean isBodyExpression()
279 {
280 boolean bodyExpression6a = this.__bodyExpression6a;
281 if (!this.__bodyExpression6aSet)
282 {
283 // bodyExpression has no pre constraints
284 bodyExpression6a = handleIsBodyExpression();
285 // bodyExpression has no post constraints
286 this.__bodyExpression6a = bodyExpression6a;
287 if (isMetafacadePropertyCachingEnabled())
288 {
289 this.__bodyExpression6aSet = true;
290 }
291 }
292 return bodyExpression6a;
293 }
294
295 // ---------------- business methods ----------------------
296
297 /**
298 * Method to be implemented in descendants
299 * This constraint's translation for the argument languange.
300 * @param language
301 * @return String
302 */
303 protected abstract String handleGetTranslation(String language);
304
305 /**
306 * This constraint's translation for the argument languange.
307 * @param language String
308 * The target language to which the OCL constraint is to be translated.
309 * @return handleGetTranslation(language)
310 */
311 public String getTranslation(String language)
312 {
313 // getTranslation has no pre constraints
314 String returnValue = handleGetTranslation(language);
315 // getTranslation has no post constraints
316 return returnValue;
317 }
318
319 // ------------- associations ------------------
320
321 /**
322 * Gets all constraints belonging to the model element.
323 * @return (ModelElementFacade)handleGetContextElement()
324 */
325 public final ModelElementFacade getContextElement()
326 {
327 ModelElementFacade getContextElement1r = null;
328 // constraints has no pre constraints
329 Object result = handleGetContextElement();
330 MetafacadeBase shieldedResult = this.shieldedElement(result);
331 try
332 {
333 getContextElement1r = (ModelElementFacade)shieldedResult;
334 }
335 catch (ClassCastException ex)
336 {
337 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
338 ConstraintFacadeLogic.logger.warn("incorrect metafacade cast for ConstraintFacadeLogic.getContextElement ModelElementFacade " + result + ": " + shieldedResult);
339 }
340 // constraints has no post constraints
341 return getContextElement1r;
342 }
343
344 /**
345 * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type
346 * @return Object
347 */
348 protected abstract Object handleGetContextElement();
349
350 /**
351 * @param validationMessages Collection<ModelValidationMessage>
352 * @see ModelElementFacadeLogicImpl#validateInvariants(Collection validationMessages)
353 */
354 @Override
355 public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
356 {
357 super.validateInvariants(validationMessages);
358 }
359 }