View Javadoc
1   // license-header java merge-point
2   //
3   // Attention: generated code (by MetafacadeLogic.vsl) - do not modify!
4   //
5   package org.andromda.metafacades.uml14;
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.Role;
11  import org.andromda.translation.ocl.validation.OCLCollections;
12  import org.andromda.translation.ocl.validation.OCLIntrospector;
13  import org.andromda.translation.ocl.validation.OCLResultEnsurer;
14  import org.apache.commons.collections.Transformer;
15  import org.apache.log4j.Logger;
16  import org.omg.uml.behavioralelements.usecases.Actor;
17  
18  /**
19   * Represents a role a user may play within a system.  Provides access to things such as services
20   * and service operations.
21   * MetafacadeLogic for Role
22   *
23   * @see Role
24   */
25  public abstract class RoleLogic
26      extends ActorFacadeLogicImpl
27      implements Role
28  {
29      /**
30       * The underlying UML object
31       * @see Object
32       */
33      protected Object metaObject;
34  
35      /** Create Metafacade implementation instance using the MetafacadeFactory from the context
36       * @param metaObjectIn
37       * @param context
38       */
39      protected RoleLogic(Object metaObjectIn, String context)
40      {
41          super((Actor)metaObjectIn, getContext(context));
42          this.metaObject = metaObjectIn;
43      }
44  
45      /**
46       * The logger instance.
47       */
48      private static final Logger logger = Logger.getLogger(RoleLogic.class);
49  
50      /**
51       * Gets the context for this metafacade logic instance.
52       * @param context String. Set to Role if null
53       * @return context String
54       */
55      private static String getContext(String context)
56      {
57          if (context == null)
58          {
59              context = "org.andromda.metafacades.uml.Role";
60          }
61          return context;
62      }
63  
64      /** Reset context only for non-root metafacades
65       * @param context
66       */
67      @Override
68      public void resetMetafacadeContext(String context)
69      {
70          if (!this.contextRoot) // reset context only for non-root metafacades
71          {
72              context = getContext(context);  // to have same value as in original constructor call
73              setMetafacadeContext (context);
74          }
75      }
76  
77      /**
78       * @return boolean true always
79       * @see Role
80       */
81      public boolean isRoleMetaType()
82      {
83          return true;
84      }
85  
86      // --------------- attributes ---------------------
87  
88     /**
89      * @see Role#isReferencesPresent()
90      * @return boolean
91      */
92      protected abstract boolean handleIsReferencesPresent();
93  
94      private boolean __referencesPresent1a;
95      private boolean __referencesPresent1aSet = false;
96  
97      /**
98       * Indicates if the necessary references are present for the Role.  This include any references
99       * to a service, service operation or use case.
100      * @return (boolean)handleIsReferencesPresent()
101      */
102     public final boolean isReferencesPresent()
103     {
104         boolean referencesPresent1a = this.__referencesPresent1a;
105         if (!this.__referencesPresent1aSet)
106         {
107             // referencesPresent has no pre constraints
108             referencesPresent1a = handleIsReferencesPresent();
109             // referencesPresent has no post constraints
110             this.__referencesPresent1a = referencesPresent1a;
111             if (isMetafacadePropertyCachingEnabled())
112             {
113                 this.__referencesPresent1aSet = true;
114             }
115         }
116         return referencesPresent1a;
117     }
118 
119     // ------------- associations ------------------
120 
121     /**
122      * <p><b>Constraint:</b> org::andromda::metafacades::uml::Role::non-empty unique role name</p>
123      * <p><b>Error:</b> Each role must have a non-empty name that is unique among all other roles.</p>
124      * <p><b>OCL:</b> context Role inv: name->notEmpty() and model.allActors->isUnique(name)</p>
125      * @param validationMessages Collection<ModelValidationMessage>
126      * @see ActorFacadeLogicImpl#validateInvariants(Collection validationMessages)
127      */
128     @Override
129     public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
130     {
131         super.validateInvariants(validationMessages);
132         try
133         {
134             final Object contextElement = this.THIS();
135             boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"name"))&&OCLCollections.isUnique(OCLIntrospector.invoke(contextElement,"model.allActors"),new Transformer(){public Object transform(Object object){return OCLIntrospector.invoke(object,"name");}}));
136             if (!constraintValid)
137             {
138                 validationMessages.add(
139                     new ModelValidationMessage(
140                         (MetafacadeBase)contextElement ,
141                         "org::andromda::metafacades::uml::Role::non-empty unique role name",
142                         "Each role must have a non-empty name that is unique among all other roles."));
143             }
144         }
145         catch (Throwable th)
146         {
147             Throwable cause = th.getCause();
148             int depth = 0; // Some throwables have infinite recursion
149             while (cause != null && depth < 7)
150             {
151                 th = cause;
152                 depth++;
153             }
154             logger.error("Error validating constraint 'org::andromda::metafacades::uml::Role::non-empty unique role name' ON "
155                 + this.THIS().toString() + ": " + th.getMessage(), th);
156         }
157     }
158 }