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.FrontEndAction;
12  import org.andromda.metafacades.uml.FrontEndActivityGraph;
13  import org.andromda.metafacades.uml.FrontEndControllerOperation;
14  import org.andromda.metafacades.uml.FrontEndParameter;
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.Operation;
20  
21  /**
22   * Represents an operation modeled on a controller.
23   * MetafacadeLogic for FrontEndControllerOperation
24   *
25   * @see FrontEndControllerOperation
26   */
27  public abstract class FrontEndControllerOperationLogic
28      extends OperationFacadeLogicImpl
29      implements FrontEndControllerOperation
30  {
31      /**
32       * The underlying UML object
33       * @see Object
34       */
35      protected Object metaObject;
36  
37      /** Create Metafacade implementation instance using the MetafacadeFactory from the context
38       * @param metaObjectIn
39       * @param context
40       */
41      protected FrontEndControllerOperationLogic(Object metaObjectIn, String context)
42      {
43          super((Operation)metaObjectIn, getContext(context));
44          this.metaObject = metaObjectIn;
45      }
46  
47      /**
48       * The logger instance.
49       */
50      private static final Logger logger = Logger.getLogger(FrontEndControllerOperationLogic.class);
51  
52      /**
53       * Gets the context for this metafacade logic instance.
54       * @param context String. Set to FrontEndControllerOperation if null
55       * @return context String
56       */
57      private static String getContext(String context)
58      {
59          if (context == null)
60          {
61              context = "org.andromda.metafacades.uml.FrontEndControllerOperation";
62          }
63          return context;
64      }
65  
66      /** Reset context only for non-root metafacades
67       * @param context
68       */
69      @Override
70      public void resetMetafacadeContext(String context)
71      {
72          if (!this.contextRoot) // reset context only for non-root metafacades
73          {
74              context = getContext(context);  // to have same value as in original constructor call
75              setMetafacadeContext (context);
76          }
77      }
78  
79      /**
80       * @return boolean true always
81       * @see FrontEndControllerOperation
82       */
83      public boolean isFrontEndControllerOperationMetaType()
84      {
85          return true;
86      }
87  
88      // --------------- attributes ---------------------
89  
90     /**
91      * @see FrontEndControllerOperation#isOwnerIsController()
92      * @return boolean
93      */
94      protected abstract boolean handleIsOwnerIsController();
95  
96      private boolean __ownerIsController1a;
97      private boolean __ownerIsController1aSet = false;
98  
99      /**
100      * Indicates if the owner of this operation is a controller.
101      * @return (boolean)handleIsOwnerIsController()
102      */
103     public final boolean isOwnerIsController()
104     {
105         boolean ownerIsController1a = this.__ownerIsController1a;
106         if (!this.__ownerIsController1aSet)
107         {
108             // ownerIsController has no pre constraints
109             ownerIsController1a = handleIsOwnerIsController();
110             // ownerIsController has no post constraints
111             this.__ownerIsController1a = ownerIsController1a;
112             if (isMetafacadePropertyCachingEnabled())
113             {
114                 this.__ownerIsController1aSet = true;
115             }
116         }
117         return ownerIsController1a;
118     }
119 
120    /**
121     * @see FrontEndControllerOperation#isAllArgumentsHaveFormFields()
122     * @return boolean
123     */
124     protected abstract boolean handleIsAllArgumentsHaveFormFields();
125 
126     private boolean __allArgumentsHaveFormFields2a;
127     private boolean __allArgumentsHaveFormFields2aSet = false;
128 
129     /**
130      * For each front-end controller operation argument there must exist a form field for each
131      * action deferring to that operation. This form field must carry the same name and must be of
132      * the same type. True if this is the case, false otherwise.
133      * @return (boolean)handleIsAllArgumentsHaveFormFields()
134      */
135     public final boolean isAllArgumentsHaveFormFields()
136     {
137         boolean allArgumentsHaveFormFields2a = this.__allArgumentsHaveFormFields2a;
138         if (!this.__allArgumentsHaveFormFields2aSet)
139         {
140             // allArgumentsHaveFormFields has no pre constraints
141             allArgumentsHaveFormFields2a = handleIsAllArgumentsHaveFormFields();
142             // allArgumentsHaveFormFields has no post constraints
143             this.__allArgumentsHaveFormFields2a = allArgumentsHaveFormFields2a;
144             if (isMetafacadePropertyCachingEnabled())
145             {
146                 this.__allArgumentsHaveFormFields2aSet = true;
147             }
148         }
149         return allArgumentsHaveFormFields2a;
150     }
151 
152     // ------------- associations ------------------
153 
154     private FrontEndActivityGraph __getActivityGraph1r;
155     private boolean __getActivityGraph1rSet = false;
156 
157     /**
158      * Represents an operation modeled on a controller.
159      * @return (FrontEndActivityGraph)handleGetActivityGraph()
160      */
161     public final FrontEndActivityGraph getActivityGraph()
162     {
163         FrontEndActivityGraph getActivityGraph1r = this.__getActivityGraph1r;
164         if (!this.__getActivityGraph1rSet)
165         {
166             // frontEndControllerOperation has no pre constraints
167             Object result = handleGetActivityGraph();
168             MetafacadeBase shieldedResult = this.shieldedElement(result);
169             try
170             {
171                 getActivityGraph1r = (FrontEndActivityGraph)shieldedResult;
172             }
173             catch (ClassCastException ex)
174             {
175                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
176                 FrontEndControllerOperationLogic.logger.warn("incorrect metafacade cast for FrontEndControllerOperationLogic.getActivityGraph FrontEndActivityGraph " + result + ": " + shieldedResult);
177             }
178             // frontEndControllerOperation has no post constraints
179             this.__getActivityGraph1r = getActivityGraph1r;
180             if (isMetafacadePropertyCachingEnabled())
181             {
182                 this.__getActivityGraph1rSet = true;
183             }
184         }
185         return getActivityGraph1r;
186     }
187 
188     /**
189      * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type
190      * @return Object
191      */
192     protected abstract Object handleGetActivityGraph();
193 
194     private List<FrontEndParameter> __getFormFields2r;
195     private boolean __getFormFields2rSet = false;
196 
197     /**
198      * Gets the controller operation to which this parameter belongs.
199      * @return (List<FrontEndParameter>)handleGetFormFields()
200      */
201     public final List<FrontEndParameter> getFormFields()
202     {
203         List<FrontEndParameter> getFormFields2r = this.__getFormFields2r;
204         if (!this.__getFormFields2rSet)
205         {
206             // controllerOperation has no pre constraints
207             List result = handleGetFormFields();
208             List shieldedResult = this.shieldedElements(result);
209             try
210             {
211                 getFormFields2r = (List<FrontEndParameter>)shieldedResult;
212             }
213             catch (ClassCastException ex)
214             {
215                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
216                 FrontEndControllerOperationLogic.logger.warn("incorrect metafacade cast for FrontEndControllerOperationLogic.getFormFields List<FrontEndParameter> " + result + ": " + shieldedResult);
217             }
218             // controllerOperation has no post constraints
219             this.__getFormFields2r = getFormFields2r;
220             if (isMetafacadePropertyCachingEnabled())
221             {
222                 this.__getFormFields2rSet = true;
223             }
224         }
225         return getFormFields2r;
226     }
227 
228     /**
229      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
230      * @return  List
231      */
232     protected abstract List handleGetFormFields();
233 
234     private List<FrontEndAction> __getDeferringActions3r;
235     private boolean __getDeferringActions3rSet = false;
236 
237     /**
238      * The controller operations to which this action defers, the order is preserved.
239      * @return (List<FrontEndAction>)handleGetDeferringActions()
240      */
241     public final List<FrontEndAction> getDeferringActions()
242     {
243         List<FrontEndAction> getDeferringActions3r = this.__getDeferringActions3r;
244         if (!this.__getDeferringActions3rSet)
245         {
246             // deferredOperations has no pre constraints
247             List result = handleGetDeferringActions();
248             List shieldedResult = this.shieldedElements(result);
249             try
250             {
251                 getDeferringActions3r = (List<FrontEndAction>)shieldedResult;
252             }
253             catch (ClassCastException ex)
254             {
255                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
256                 FrontEndControllerOperationLogic.logger.warn("incorrect metafacade cast for FrontEndControllerOperationLogic.getDeferringActions List<FrontEndAction> " + result + ": " + shieldedResult);
257             }
258             // deferredOperations has no post constraints
259             this.__getDeferringActions3r = getDeferringActions3r;
260             if (isMetafacadePropertyCachingEnabled())
261             {
262                 this.__getDeferringActions3rSet = true;
263             }
264         }
265         return getDeferringActions3r;
266     }
267 
268     /**
269      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
270      * @return  List
271      */
272     protected abstract List handleGetDeferringActions();
273 
274     /**
275      * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndControllerOperation::all arguments need an event parameter</p>
276      * <p><b>Error:</b> For each controller operation argument there must exist a parameter for each action deferring to that operation. This parameter must carry the same name and must be of the same type.</p>
277      * <p><b>OCL:</b> context FrontEndControllerOperation inv: allArgumentsHaveFormFields</p>
278      * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndControllerOperation::the operation name may not be the same as the use-case name</p>
279      * <p><b>Error:</b> It is not allowed to give a controller operation the same name as the use-case for which it is defined, please either rename your operation or your use-case.</p>
280      * <p><b>OCL:</b> context FrontEndControllerOperation inv: name <> owner.useCase.name</p>
281      * @param validationMessages Collection<ModelValidationMessage>
282      * @see OperationFacadeLogicImpl#validateInvariants(Collection validationMessages)
283      */
284     @Override
285     public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
286     {
287         super.validateInvariants(validationMessages);
288         try
289         {
290             final Object contextElement = this.THIS();
291             boolean constraintValid = OCLResultEnsurer.ensure(OCLIntrospector.invoke(contextElement,"allArgumentsHaveFormFields"));
292             if (!constraintValid)
293             {
294                 validationMessages.add(
295                     new ModelValidationMessage(
296                         (MetafacadeBase)contextElement ,
297                         "org::andromda::metafacades::uml::FrontEndControllerOperation::all arguments need an event parameter",
298                         "For each controller operation argument there must exist a parameter for each action deferring to that operation. This parameter must carry the same name and must be of the same type."));
299             }
300         }
301         catch (Throwable th)
302         {
303             Throwable cause = th.getCause();
304             int depth = 0; // Some throwables have infinite recursion
305             while (cause != null && depth < 7)
306             {
307                 th = cause;
308                 depth++;
309             }
310             logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndControllerOperation::all arguments need an event parameter' ON "
311                 + this.THIS().toString() + ": " + th.getMessage(), th);
312         }
313         try
314         {
315             final Object contextElement = this.THIS();
316             boolean constraintValid = OCLResultEnsurer.ensure(OCLExpressions.notEqual(OCLIntrospector.invoke(contextElement,"name"),OCLIntrospector.invoke(contextElement,"owner.useCase.name")));
317             if (!constraintValid)
318             {
319                 validationMessages.add(
320                     new ModelValidationMessage(
321                         (MetafacadeBase)contextElement ,
322                         "org::andromda::metafacades::uml::FrontEndControllerOperation::the operation name may not be the same as the use-case name",
323                         "It is not allowed to give a controller operation the same name as the use-case for which it is defined, please either rename your operation or your use-case."));
324             }
325         }
326         catch (Throwable th)
327         {
328             Throwable cause = th.getCause();
329             int depth = 0; // Some throwables have infinite recursion
330             while (cause != null && depth < 7)
331             {
332                 th = cause;
333                 depth++;
334             }
335             logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndControllerOperation::the operation name may not be the same as the use-case name' ON "
336                 + this.THIS().toString() + ": " + th.getMessage(), th);
337         }
338     }
339 }