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 java.util.List;
9   import org.andromda.core.metafacade.MetafacadeBase;
10  import org.andromda.core.metafacade.ModelValidationMessage;
11  import org.andromda.metafacades.uml.AttributeFacade;
12  import org.andromda.metafacades.uml.ClassifierFacade;
13  import org.andromda.metafacades.uml.EnumerationFacade;
14  import org.andromda.translation.ocl.validation.OCLCollections;
15  import org.andromda.translation.ocl.validation.OCLExpressions;
16  import org.andromda.translation.ocl.validation.OCLIntrospector;
17  import org.andromda.translation.ocl.validation.OCLResultEnsurer;
18  import org.apache.log4j.Logger;
19  import org.omg.uml.foundation.core.Classifier;
20  
21  /**
22   * Represents an enumeration. A data type whose values are enumerated in the model as enumeration
23   * literals. May also be a Classifier with Stereotype Enumeration.
24   * MetafacadeLogic for EnumerationFacade
25   *
26   * @see EnumerationFacade
27   */
28  public abstract class EnumerationFacadeLogic
29      extends ClassifierFacadeLogicImpl
30      implements EnumerationFacade
31  {
32      /**
33       * The underlying UML object
34       * @see Object
35       */
36      protected Object metaObject;
37  
38      /** Create Metafacade implementation instance using the MetafacadeFactory from the context
39       * @param metaObjectIn
40       * @param context
41       */
42      protected EnumerationFacadeLogic(Object metaObjectIn, String context)
43      {
44          super((Classifier)metaObjectIn, getContext(context));
45          this.metaObject = metaObjectIn;
46      }
47  
48      /**
49       * The logger instance.
50       */
51      private static final Logger logger = Logger.getLogger(EnumerationFacadeLogic.class);
52  
53      /**
54       * Gets the context for this metafacade logic instance.
55       * @param context String. Set to EnumerationFacade if null
56       * @return context String
57       */
58      private static String getContext(String context)
59      {
60          if (context == null)
61          {
62              context = "org.andromda.metafacades.uml.EnumerationFacade";
63          }
64          return context;
65      }
66  
67      /** Reset context only for non-root metafacades
68       * @param context
69       */
70      @Override
71      public void resetMetafacadeContext(String context)
72      {
73          if (!this.contextRoot) // reset context only for non-root metafacades
74          {
75              context = getContext(context);  // to have same value as in original constructor call
76              setMetafacadeContext (context);
77          }
78      }
79  
80      /**
81       * @return boolean true always
82       * @see EnumerationFacade
83       */
84      public boolean isEnumerationFacadeMetaType()
85      {
86          return true;
87      }
88  
89      // --------------- attributes ---------------------
90  
91     /**
92      * @see EnumerationFacade#getFromOperationSignature()
93      * @return String
94      */
95      protected abstract String handleGetFromOperationSignature();
96  
97      private String __fromOperationSignature1a;
98      private boolean __fromOperationSignature1aSet = false;
99  
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
282 inv: 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 }