001// license-header java merge-point 002// 003// Attention: generated code (by MetafacadeLogic.vsl) - do not modify! 004// 005package org.andromda.metafacades.uml14; 006 007import java.util.Collection; 008import org.andromda.core.metafacade.MetafacadeBase; 009import org.andromda.core.metafacade.ModelValidationMessage; 010import org.andromda.metafacades.uml.ConstraintFacade; 011import org.andromda.metafacades.uml.ModelElementFacade; 012import org.apache.log4j.Logger; 013import org.omg.uml.foundation.core.Constraint; 014 015/** 016 * Condition or restriction expressed in natural language text or in a machine readable language for 017 * the purpose of declaring some of the semantics of an element. 018 * MetafacadeLogic for ConstraintFacade 019 * 020 * @see ConstraintFacade 021 */ 022public abstract class ConstraintFacadeLogic 023 extends ModelElementFacadeLogicImpl 024 implements ConstraintFacade 025{ 026 /** 027 * The underlying UML object 028 * @see Constraint 029 */ 030 protected Constraint metaObject; 031 032 /** Create Metafacade implementation instance using the MetafacadeFactory from the context 033 * @param metaObjectIn 034 * @param context 035 */ 036 protected ConstraintFacadeLogic(Constraint metaObjectIn, String context) 037 { 038 super(metaObjectIn, getContext(context)); 039 this.metaObject = metaObjectIn; 040 } 041 042 /** 043 * The logger instance. 044 */ 045 private static final Logger logger = Logger.getLogger(ConstraintFacadeLogic.class); 046 047 /** 048 * Gets the context for this metafacade logic instance. 049 * @param context String. Set to ConstraintFacade if null 050 * @return context String 051 */ 052 private static String getContext(String context) 053 { 054 if (context == null) 055 { 056 context = "org.andromda.metafacades.uml.ConstraintFacade"; 057 } 058 return context; 059 } 060 061 /** Reset context only for non-root metafacades 062 * @param context 063 */ 064 @Override 065 public void resetMetafacadeContext(String context) 066 { 067 if (!this.contextRoot) // reset context only for non-root metafacades 068 { 069 context = getContext(context); // to have same value as in original constructor call 070 setMetafacadeContext (context); 071 } 072 } 073 074 /** 075 * @return boolean true always 076 * @see ConstraintFacade 077 */ 078 public boolean isConstraintFacadeMetaType() 079 { 080 return true; 081 } 082 083 // --------------- attributes --------------------- 084 085 /** 086 * @see ConstraintFacade#getBody() 087 * @return String 088 */ 089 protected abstract String handleGetBody(); 090 091 private String __body1a; 092 private boolean __body1aSet = false; 093 094 /** 095 * Gets the 'body' or text of this constraint. 096 * @return (String)handleGetBody() 097 */ 098 public final String getBody() 099 { 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}