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 java.util.List; 009import org.andromda.core.metafacade.MetafacadeBase; 010import org.andromda.core.metafacade.ModelValidationMessage; 011import org.andromda.metafacades.uml.AttributeFacade; 012import org.andromda.metafacades.uml.ClassifierFacade; 013import org.andromda.metafacades.uml.EnumerationFacade; 014import org.andromda.translation.ocl.validation.OCLCollections; 015import org.andromda.translation.ocl.validation.OCLExpressions; 016import org.andromda.translation.ocl.validation.OCLIntrospector; 017import org.andromda.translation.ocl.validation.OCLResultEnsurer; 018import org.apache.log4j.Logger; 019import org.omg.uml.foundation.core.Classifier; 020 021/** 022 * Represents an enumeration. A data type whose values are enumerated in the model as enumeration 023 * literals. May also be a Classifier with Stereotype Enumeration. 024 * MetafacadeLogic for EnumerationFacade 025 * 026 * @see EnumerationFacade 027 */ 028public abstract class EnumerationFacadeLogic 029 extends ClassifierFacadeLogicImpl 030 implements EnumerationFacade 031{ 032 /** 033 * The underlying UML object 034 * @see Object 035 */ 036 protected Object metaObject; 037 038 /** Create Metafacade implementation instance using the MetafacadeFactory from the context 039 * @param metaObjectIn 040 * @param context 041 */ 042 protected EnumerationFacadeLogic(Object metaObjectIn, String context) 043 { 044 super((Classifier)metaObjectIn, getContext(context)); 045 this.metaObject = metaObjectIn; 046 } 047 048 /** 049 * The logger instance. 050 */ 051 private static final Logger logger = Logger.getLogger(EnumerationFacadeLogic.class); 052 053 /** 054 * Gets the context for this metafacade logic instance. 055 * @param context String. Set to EnumerationFacade if null 056 * @return context String 057 */ 058 private static String getContext(String context) 059 { 060 if (context == null) 061 { 062 context = "org.andromda.metafacades.uml.EnumerationFacade"; 063 } 064 return context; 065 } 066 067 /** Reset context only for non-root metafacades 068 * @param context 069 */ 070 @Override 071 public void resetMetafacadeContext(String context) 072 { 073 if (!this.contextRoot) // reset context only for non-root metafacades 074 { 075 context = getContext(context); // to have same value as in original constructor call 076 setMetafacadeContext (context); 077 } 078 } 079 080 /** 081 * @return boolean true always 082 * @see EnumerationFacade 083 */ 084 public boolean isEnumerationFacadeMetaType() 085 { 086 return true; 087 } 088 089 // --------------- attributes --------------------- 090 091 /** 092 * @see EnumerationFacade#getFromOperationSignature() 093 * @return String 094 */ 095 protected abstract String handleGetFromOperationSignature(); 096 097 private String __fromOperationSignature1a; 098 private boolean __fromOperationSignature1aSet = false; 099 100 /** 101 * The 'from' operation signature. This is the signature that takes the actual literal value 102 * and allows a new enumeration to be constructed. 103 * @return (String)handleGetFromOperationSignature() 104 */ 105 public final String getFromOperationSignature() 106 { 107 String fromOperationSignature1a = this.__fromOperationSignature1a; 108 if (!this.__fromOperationSignature1aSet) 109 { 110 // fromOperationSignature has no pre constraints 111 fromOperationSignature1a = handleGetFromOperationSignature(); 112 // fromOperationSignature has no post constraints 113 this.__fromOperationSignature1a = fromOperationSignature1a; 114 if (isMetafacadePropertyCachingEnabled()) 115 { 116 this.__fromOperationSignature1aSet = true; 117 } 118 } 119 return fromOperationSignature1a; 120 } 121 122 /** 123 * @see EnumerationFacade#getFromOperationName() 124 * @return String 125 */ 126 protected abstract String handleGetFromOperationName(); 127 128 private String __fromOperationName2a; 129 private boolean __fromOperationName2aSet = false; 130 131 /** 132 * The 'from' operation name. This is the name of the operation that takes the actual literal 133 * value and allows a new enumeration to be constructed. 134 * @return (String)handleGetFromOperationName() 135 */ 136 public final String getFromOperationName() 137 { 138 String fromOperationName2a = this.__fromOperationName2a; 139 if (!this.__fromOperationName2aSet) 140 { 141 // fromOperationName has no pre constraints 142 fromOperationName2a = handleGetFromOperationName(); 143 // fromOperationName has no post constraints 144 this.__fromOperationName2a = fromOperationName2a; 145 if (isMetafacadePropertyCachingEnabled()) 146 { 147 this.__fromOperationName2aSet = true; 148 } 149 } 150 return fromOperationName2a; 151 } 152 153 /** 154 * @see EnumerationFacade#isTypeSafe() 155 * @return boolean 156 */ 157 protected abstract boolean handleIsTypeSafe(); 158 159 private boolean __typeSafe3a; 160 private boolean __typeSafe3aSet = false; 161 162 /** 163 * Indicates whether the enumeration must be generated using a Java 5 type-safe enum or a 164 * traditional enumeration-pattern class. 165 * @return (boolean)handleIsTypeSafe() 166 */ 167 public final boolean isTypeSafe() 168 { 169 boolean typeSafe3a = this.__typeSafe3a; 170 if (!this.__typeSafe3aSet) 171 { 172 // typeSafe has no pre constraints 173 typeSafe3a = handleIsTypeSafe(); 174 // typeSafe has no post constraints 175 this.__typeSafe3a = typeSafe3a; 176 if (isMetafacadePropertyCachingEnabled()) 177 { 178 this.__typeSafe3aSet = true; 179 } 180 } 181 return typeSafe3a; 182 } 183 184 // ------------- associations ------------------ 185 186 /** 187 * Represents an enumeration. A data type whose values are enumerated in the model as 188 * enumeration 189 * literals. May also be a Classifier with Stereotype Enumeration. 190 * @return (ClassifierFacade)handleGetLiteralType() 191 */ 192 public final ClassifierFacade getLiteralType() 193 { 194 ClassifierFacade getLiteralType1r = null; 195 // enumerationFacade has no pre constraints 196 Object result = handleGetLiteralType(); 197 MetafacadeBase shieldedResult = this.shieldedElement(result); 198 try 199 { 200 getLiteralType1r = (ClassifierFacade)shieldedResult; 201 } 202 catch (ClassCastException ex) 203 { 204 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn 205 EnumerationFacadeLogic.logger.warn("incorrect metafacade cast for EnumerationFacadeLogic.getLiteralType ClassifierFacade " + result + ": " + shieldedResult); 206 } 207 // enumerationFacade has no post constraints 208 return getLiteralType1r; 209 } 210 211 /** 212 * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type 213 * @return Object 214 */ 215 protected abstract Object handleGetLiteralType(); 216 217 /** 218 * If the attribute is an enumeration literal this represents the owning enumeration. Can be 219 * empty. 220 * @return (Collection<AttributeFacade>)handleGetLiterals() 221 */ 222 public final Collection<AttributeFacade> getLiterals() 223 { 224 Collection<AttributeFacade> getLiterals2r = null; 225 // enumeration has no pre constraints 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 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn 235 EnumerationFacadeLogic.logger.warn("incorrect metafacade cast for EnumerationFacadeLogic.getLiterals Collection<AttributeFacade> " + result + ": " + shieldedResult); 236 } 237 // enumeration has no post constraints 238 return getLiterals2r; 239 } 240 241 /** 242 * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type 243 * @return Collection 244 */ 245 protected abstract Collection handleGetLiterals(); 246 247 /** 248 * Represents an enumeration. A data type whose values are enumerated in the model as 249 * enumeration 250 * literals. May also be a Classifier with Stereotype Enumeration. 251 * @return (Collection<AttributeFacade>)handleGetMemberVariables() 252 */ 253 public final Collection<AttributeFacade> getMemberVariables() 254 { 255 Collection<AttributeFacade> getMemberVariables3r = null; 256 // enumeration has no pre constraints 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 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn 266 EnumerationFacadeLogic.logger.warn("incorrect metafacade cast for EnumerationFacadeLogic.getMemberVariables Collection<AttributeFacade> " + result + ": " + shieldedResult); 267 } 268 // enumeration has no post constraints 269 return getMemberVariables3r; 270 } 271 272 /** 273 * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type 274 * @return Collection 275 */ 276 protected abstract Collection handleGetMemberVariables(); 277 278 /** 279 * <p><b>Constraint:</b> org::andromda::metafacades::uml::EnumerationFacade::enumerations must have at least one literal value</p> 280 * <p><b>Error:</b> An enumeration must have at least one literal modeled.</p> 281 * <p><b>OCL:</b> context EnumerationFacade 282inv: literals -> notEmpty()</p> 283 * <p><b>Constraint:</b> org::andromda::metafacades::uml::EnumerationFacade::name must be a valid identifier</p> 284 * <p><b>Error:</b> Model Element name cannot be a reserved word</p> 285 * <p><b>OCL:</b> context EnumerationFacade inv: validIdentifierName=true</p> 286 * @param validationMessages Collection<ModelValidationMessage> 287 * @see ClassifierFacadeLogicImpl#validateInvariants(Collection validationMessages) 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; // Some throwables have infinite recursion 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; // Some throwables have infinite recursion 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}