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.DependencyFacade; 012import org.andromda.metafacades.uml.Destination; 013import org.andromda.metafacades.uml.Role; 014import org.andromda.metafacades.uml.Service; 015import org.andromda.translation.ocl.validation.OCLCollections; 016import org.andromda.translation.ocl.validation.OCLIntrospector; 017import org.andromda.translation.ocl.validation.OCLResultEnsurer; 018import org.apache.commons.collections.Predicate; 019import org.apache.log4j.Logger; 020import org.omg.uml.foundation.core.Classifier; 021 022/** 023 * Represents a service. 024 * MetafacadeLogic for Service 025 * 026 * @see Service 027 */ 028public abstract class ServiceLogic 029 extends ClassifierFacadeLogicImpl 030 implements Service 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 ServiceLogic(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(ServiceLogic.class); 052 053 /** 054 * Gets the context for this metafacade logic instance. 055 * @param context String. Set to Service 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.Service"; 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 Service 083 */ 084 public boolean isServiceMetaType() 085 { 086 return true; 087 } 088 089 // ------------- associations ------------------ 090 091 /** 092 * Represents a service. 093 * @return (Collection<DependencyFacade>)handleGetServiceReferences() 094 */ 095 public final Collection<DependencyFacade> getServiceReferences() 096 { 097 Collection<DependencyFacade> getServiceReferences1r = null; 098 // service has no pre constraints 099 Collection result = handleGetServiceReferences(); 100 List shieldedResult = this.shieldedElements(result); 101 try 102 { 103 getServiceReferences1r = (Collection<DependencyFacade>)shieldedResult; 104 } 105 catch (ClassCastException ex) 106 { 107 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn 108 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getServiceReferences Collection<DependencyFacade> " + result + ": " + shieldedResult); 109 } 110 // service has no post constraints 111 return getServiceReferences1r; 112 } 113 114 /** 115 * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type 116 * @return Collection 117 */ 118 protected abstract Collection handleGetServiceReferences(); 119 120 /** 121 * Represents a service. 122 * @return (Collection<DependencyFacade>)handleGetEntityReferences() 123 */ 124 public final Collection<DependencyFacade> getEntityReferences() 125 { 126 Collection<DependencyFacade> getEntityReferences2r = null; 127 // service has no pre constraints 128 Collection result = handleGetEntityReferences(); 129 List shieldedResult = this.shieldedElements(result); 130 try 131 { 132 getEntityReferences2r = (Collection<DependencyFacade>)shieldedResult; 133 } 134 catch (ClassCastException ex) 135 { 136 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn 137 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getEntityReferences Collection<DependencyFacade> " + result + ": " + shieldedResult); 138 } 139 // service has no post constraints 140 return getEntityReferences2r; 141 } 142 143 /** 144 * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type 145 * @return Collection 146 */ 147 protected abstract Collection handleGetEntityReferences(); 148 149 /** 150 * Represents a service. 151 * @return (Collection<Role>)handleGetAllRoles() 152 */ 153 public final Collection<Role> getAllRoles() 154 { 155 Collection<Role> getAllRoles3r = null; 156 // service has no pre constraints 157 Collection result = handleGetAllRoles(); 158 List shieldedResult = this.shieldedElements(result); 159 try 160 { 161 getAllRoles3r = (Collection<Role>)shieldedResult; 162 } 163 catch (ClassCastException ex) 164 { 165 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn 166 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllRoles Collection<Role> " + result + ": " + shieldedResult); 167 } 168 // service has no post constraints 169 return getAllRoles3r; 170 } 171 172 /** 173 * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type 174 * @return Collection 175 */ 176 protected abstract Collection handleGetAllRoles(); 177 178 /** 179 * Represents a service. 180 * @return (Collection<Role>)handleGetRoles() 181 */ 182 public final Collection<Role> getRoles() 183 { 184 Collection<Role> getRoles4r = null; 185 // service has no pre constraints 186 Collection result = handleGetRoles(); 187 List shieldedResult = this.shieldedElements(result); 188 try 189 { 190 getRoles4r = (Collection<Role>)shieldedResult; 191 } 192 catch (ClassCastException ex) 193 { 194 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn 195 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getRoles Collection<Role> " + result + ": " + shieldedResult); 196 } 197 // service has no post constraints 198 return getRoles4r; 199 } 200 201 /** 202 * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type 203 * @return Collection 204 */ 205 protected abstract Collection handleGetRoles(); 206 207 /** 208 * Represents a service. 209 * @return (Collection<DependencyFacade>)handleGetAllServiceReferences() 210 */ 211 public final Collection<DependencyFacade> getAllServiceReferences() 212 { 213 Collection<DependencyFacade> getAllServiceReferences5r = null; 214 // service has no pre constraints 215 Collection result = handleGetAllServiceReferences(); 216 List shieldedResult = this.shieldedElements(result); 217 try 218 { 219 getAllServiceReferences5r = (Collection<DependencyFacade>)shieldedResult; 220 } 221 catch (ClassCastException ex) 222 { 223 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn 224 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllServiceReferences Collection<DependencyFacade> " + result + ": " + shieldedResult); 225 } 226 // service has no post constraints 227 return getAllServiceReferences5r; 228 } 229 230 /** 231 * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type 232 * @return Collection 233 */ 234 protected abstract Collection handleGetAllServiceReferences(); 235 236 /** 237 * Represents a service. 238 * @return (Collection<Destination>)handleGetAllMessagingDestinations() 239 */ 240 public final Collection<Destination> getAllMessagingDestinations() 241 { 242 Collection<Destination> getAllMessagingDestinations6r = null; 243 // service has no pre constraints 244 Collection result = handleGetAllMessagingDestinations(); 245 List shieldedResult = this.shieldedElements(result); 246 try 247 { 248 getAllMessagingDestinations6r = (Collection<Destination>)shieldedResult; 249 } 250 catch (ClassCastException ex) 251 { 252 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn 253 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllMessagingDestinations Collection<Destination> " + result + ": " + shieldedResult); 254 } 255 // service has no post constraints 256 return getAllMessagingDestinations6r; 257 } 258 259 /** 260 * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type 261 * @return Collection 262 */ 263 protected abstract Collection handleGetAllMessagingDestinations(); 264 265 /** 266 * Represents a service. 267 * @return (Collection<Destination>)handleGetMessagingDestinations() 268 */ 269 public final Collection<Destination> getMessagingDestinations() 270 { 271 Collection<Destination> getMessagingDestinations7r = null; 272 // service has no pre constraints 273 Collection result = handleGetMessagingDestinations(); 274 List shieldedResult = this.shieldedElements(result); 275 try 276 { 277 getMessagingDestinations7r = (Collection<Destination>)shieldedResult; 278 } 279 catch (ClassCastException ex) 280 { 281 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn 282 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getMessagingDestinations Collection<Destination> " + result + ": " + shieldedResult); 283 } 284 // service has no post constraints 285 return getMessagingDestinations7r; 286 } 287 288 /** 289 * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type 290 * @return Collection 291 */ 292 protected abstract Collection handleGetMessagingDestinations(); 293 294 /** 295 * Represents a service. 296 * @return (Collection<DependencyFacade>)handleGetAllEntityReferences() 297 */ 298 public final Collection<DependencyFacade> getAllEntityReferences() 299 { 300 Collection<DependencyFacade> getAllEntityReferences8r = null; 301 // service has no pre constraints 302 Collection result = handleGetAllEntityReferences(); 303 List shieldedResult = this.shieldedElements(result); 304 try 305 { 306 getAllEntityReferences8r = (Collection<DependencyFacade>)shieldedResult; 307 } 308 catch (ClassCastException ex) 309 { 310 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn 311 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllEntityReferences Collection<DependencyFacade> " + result + ": " + shieldedResult); 312 } 313 // service has no post constraints 314 return getAllEntityReferences8r; 315 } 316 317 /** 318 * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type 319 * @return Collection 320 */ 321 protected abstract Collection handleGetAllEntityReferences(); 322 323 /** 324 * <p><b>Constraint:</b> org::andromda::metafacades::uml::Service::a service can only generalize another service</p> 325 * <p><b>Error:</b> A service can only generalize another service.</p> 326 * <p><b>OCL:</b> context Service 327inv : generalization -> notEmpty() implies generalization.oclIsKindOf(Service)</p> 328 * <p><b>Constraint:</b> org::andromda::metafacades::uml::Service::services can only specialize other service</p> 329 * <p><b>Error:</b> A service can only specialize another service.</p> 330 * <p><b>OCL:</b> context ServiceFacade inv : specializations -> notEmpty() implies specializations -> forAll(oclIsKindOf(Service))</p> 331 * @param validationMessages Collection<ModelValidationMessage> 332 * @see ClassifierFacadeLogicImpl#validateInvariants(Collection validationMessages) 333 */ 334 @Override 335 public void validateInvariants(Collection<ModelValidationMessage> validationMessages) 336 { 337 super.validateInvariants(validationMessages); 338 try 339 { 340 final Object contextElement = this.THIS(); 341 boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"generalization")))).booleanValue()?OCLIntrospector.invoke(contextElement,"generalization") instanceof Service:true)); 342 if (!constraintValid) 343 { 344 validationMessages.add( 345 new ModelValidationMessage( 346 (MetafacadeBase)contextElement , 347 "org::andromda::metafacades::uml::Service::a service can only generalize another service", 348 "A service can only generalize another service.")); 349 } 350 } 351 catch (Throwable th) 352 { 353 Throwable cause = th.getCause(); 354 int depth = 0; // Some throwables have infinite recursion 355 while (cause != null && depth < 7) 356 { 357 th = cause; 358 depth++; 359 } 360 logger.error("Error validating constraint 'org::andromda::metafacades::uml::Service::a service can only generalize another service' ON " 361 + this.THIS().toString() + ": " + th.getMessage(), th); 362 } 363 try 364 { 365 final Object contextElement = this.THIS(); 366 boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"specializations")))).booleanValue()?OCLCollections.forAll(OCLIntrospector.invoke(contextElement,"specializations"),new Predicate(){public boolean evaluate(Object object){return Boolean.valueOf(String.valueOf(object instanceof Service)).booleanValue();}}):true)); 367 if (!constraintValid) 368 { 369 validationMessages.add( 370 new ModelValidationMessage( 371 (MetafacadeBase)contextElement , 372 "org::andromda::metafacades::uml::Service::services can only specialize other service", 373 "A service can only specialize another service.")); 374 } 375 } 376 catch (Throwable th) 377 { 378 Throwable cause = th.getCause(); 379 int depth = 0; // Some throwables have infinite recursion 380 while (cause != null && depth < 7) 381 { 382 th = cause; 383 depth++; 384 } 385 logger.error("Error validating constraint 'org::andromda::metafacades::uml::Service::services can only specialize other service' ON " 386 + this.THIS().toString() + ": " + th.getMessage(), th); 387 } 388 } 389}