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.FrontEndActionState;
13  import org.andromda.metafacades.uml.FrontEndExceptionHandler;
14  import org.andromda.metafacades.uml.FrontEndForward;
15  import org.andromda.metafacades.uml.OperationFacade;
16  import org.andromda.translation.ocl.validation.OCLCollections;
17  import org.andromda.translation.ocl.validation.OCLExpressions;
18  import org.andromda.translation.ocl.validation.OCLIntrospector;
19  import org.andromda.translation.ocl.validation.OCLResultEnsurer;
20  import org.apache.log4j.Logger;
21  import org.omg.uml.behavioralelements.activitygraphs.ActionState;
22  
23  /**
24   * Represents an operation on the server called by an action. Optionally may defer operations to the
25   * controller.
26   * MetafacadeLogic for FrontEndActionState
27   *
28   * @see FrontEndActionState
29   */
30  public abstract class FrontEndActionStateLogic
31      extends ActionStateFacadeLogicImpl
32      implements FrontEndActionState
33  {
34      /**
35       * The underlying UML object
36       * @see Object
37       */
38      protected Object metaObject;
39  
40      /** Create Metafacade implementation instance using the MetafacadeFactory from the context
41       * @param metaObjectIn
42       * @param context
43       */
44      protected FrontEndActionStateLogic(Object metaObjectIn, String context)
45      {
46          super((ActionState)metaObjectIn, getContext(context));
47          this.metaObject = metaObjectIn;
48      }
49  
50      /**
51       * The logger instance.
52       */
53      private static final Logger logger = Logger.getLogger(FrontEndActionStateLogic.class);
54  
55      /**
56       * Gets the context for this metafacade logic instance.
57       * @param context String. Set to FrontEndActionState if null
58       * @return context String
59       */
60      private static String getContext(String context)
61      {
62          if (context == null)
63          {
64              context = "org.andromda.metafacades.uml.FrontEndActionState";
65          }
66          return context;
67      }
68  
69      /** Reset context only for non-root metafacades
70       * @param context
71       */
72      @Override
73      public void resetMetafacadeContext(String context)
74      {
75          if (!this.contextRoot) // reset context only for non-root metafacades
76          {
77              context = getContext(context);  // to have same value as in original constructor call
78              setMetafacadeContext (context);
79          }
80      }
81  
82      /**
83       * @return boolean true always
84       * @see FrontEndActionState
85       */
86      public boolean isFrontEndActionStateMetaType()
87      {
88          return true;
89      }
90  
91      // --------------- attributes ---------------------
92  
93     /**
94      * @see FrontEndActionState#isServerSide()
95      * @return boolean
96      */
97      protected abstract boolean handleIsServerSide();
98  
99      private boolean __serverSide1a;
100     private boolean __serverSide1aSet = false;
101 
102     /**
103      * Indicates whether or not this front end action state is server side. Pages, for example, are
104      * also action states but they return control to the client.
105      * @return (boolean)handleIsServerSide()
106      */
107     public final boolean isServerSide()
108     {
109         boolean serverSide1a = this.__serverSide1a;
110         if (!this.__serverSide1aSet)
111         {
112             // serverSide has no pre constraints
113             serverSide1a = handleIsServerSide();
114             // serverSide has no post constraints
115             this.__serverSide1a = serverSide1a;
116             if (isMetafacadePropertyCachingEnabled())
117             {
118                 this.__serverSide1aSet = true;
119             }
120         }
121         return serverSide1a;
122     }
123 
124    /**
125     * @see FrontEndActionState#isContainedInFrontEndUseCase()
126     * @return boolean
127     */
128     protected abstract boolean handleIsContainedInFrontEndUseCase();
129 
130     private boolean __containedInFrontEndUseCase2a;
131     private boolean __containedInFrontEndUseCase2aSet = false;
132 
133     /**
134      * True if this element is contained in a FrontEndUseCase.
135      * @return (boolean)handleIsContainedInFrontEndUseCase()
136      */
137     public final boolean isContainedInFrontEndUseCase()
138     {
139         boolean containedInFrontEndUseCase2a = this.__containedInFrontEndUseCase2a;
140         if (!this.__containedInFrontEndUseCase2aSet)
141         {
142             // containedInFrontEndUseCase has no pre constraints
143             containedInFrontEndUseCase2a = handleIsContainedInFrontEndUseCase();
144             // containedInFrontEndUseCase has no post constraints
145             this.__containedInFrontEndUseCase2a = containedInFrontEndUseCase2a;
146             if (isMetafacadePropertyCachingEnabled())
147             {
148                 this.__containedInFrontEndUseCase2aSet = true;
149             }
150         }
151         return containedInFrontEndUseCase2a;
152     }
153 
154    /**
155     * @see FrontEndActionState#getActionMethodName()
156     * @return String
157     */
158     protected abstract String handleGetActionMethodName();
159 
160     private String __actionMethodName3a;
161     private boolean __actionMethodName3aSet = false;
162 
163     /**
164      * The method name representing this action state.
165      * @return (String)handleGetActionMethodName()
166      */
167     public final String getActionMethodName()
168     {
169         String actionMethodName3a = this.__actionMethodName3a;
170         if (!this.__actionMethodName3aSet)
171         {
172             // actionMethodName has no pre constraints
173             actionMethodName3a = handleGetActionMethodName();
174             // actionMethodName has no post constraints
175             this.__actionMethodName3a = actionMethodName3a;
176             if (isMetafacadePropertyCachingEnabled())
177             {
178                 this.__actionMethodName3aSet = true;
179             }
180         }
181         return actionMethodName3a;
182     }
183 
184    /**
185     * @see FrontEndActionState#getServiceCalls()
186     * @return List<OperationFacade>
187     */
188     protected abstract List<OperationFacade> handleGetServiceCalls();
189 
190     private List<OperationFacade> __serviceCalls4a;
191     private boolean __serviceCalls4aSet = false;
192 
193     /**
194      * All calls deferred to the controller by this action state.
195      * @return (List<OperationFacade>)handleGetServiceCalls()
196      */
197     public final List<OperationFacade> getServiceCalls()
198     {
199         List<OperationFacade> serviceCalls4a = this.__serviceCalls4a;
200         if (!this.__serviceCalls4aSet)
201         {
202             // serviceCalls has no pre constraints
203             serviceCalls4a = handleGetServiceCalls();
204             // serviceCalls has no post constraints
205             this.__serviceCalls4a = serviceCalls4a;
206             if (isMetafacadePropertyCachingEnabled())
207             {
208                 this.__serviceCalls4aSet = true;
209             }
210         }
211         return serviceCalls4a;
212     }
213 
214     // ------------- associations ------------------
215 
216     private List<FrontEndAction> __getContainerActions1r;
217     private boolean __getContainerActions1rSet = false;
218 
219     /**
220      * All action states visited by this action.
221      * @return (List<FrontEndAction>)handleGetContainerActions()
222      */
223     public final List<FrontEndAction> getContainerActions()
224     {
225         List<FrontEndAction> getContainerActions1r = this.__getContainerActions1r;
226         if (!this.__getContainerActions1rSet)
227         {
228             // actionStates has no pre constraints
229             List result = handleGetContainerActions();
230             List shieldedResult = this.shieldedElements(result);
231             try
232             {
233                 getContainerActions1r = (List<FrontEndAction>)shieldedResult;
234             }
235             catch (ClassCastException ex)
236             {
237                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
238                 FrontEndActionStateLogic.logger.warn("incorrect metafacade cast for FrontEndActionStateLogic.getContainerActions List<FrontEndAction> " + result + ": " + shieldedResult);
239             }
240             // actionStates has no post constraints
241             this.__getContainerActions1r = getContainerActions1r;
242             if (isMetafacadePropertyCachingEnabled())
243             {
244                 this.__getContainerActions1rSet = true;
245             }
246         }
247         return getContainerActions1r;
248     }
249 
250     /**
251      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
252      * @return  List
253      */
254     protected abstract List handleGetContainerActions();
255 
256     private List<OperationFacade> __getControllerCalls2r;
257     private boolean __getControllerCalls2rSet = false;
258 
259     /**
260      * Represents an operation on the server called by an action. Optionally may defer operations to
261      * the
262      * controller.
263      * @return (List<OperationFacade>)handleGetControllerCalls()
264      */
265     public final List<OperationFacade> getControllerCalls()
266     {
267         List<OperationFacade> getControllerCalls2r = this.__getControllerCalls2r;
268         if (!this.__getControllerCalls2rSet)
269         {
270             // frontEndActionState has no pre constraints
271             List result = handleGetControllerCalls();
272             List shieldedResult = this.shieldedElements(result);
273             try
274             {
275                 getControllerCalls2r = (List<OperationFacade>)shieldedResult;
276             }
277             catch (ClassCastException ex)
278             {
279                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
280                 FrontEndActionStateLogic.logger.warn("incorrect metafacade cast for FrontEndActionStateLogic.getControllerCalls List<OperationFacade> " + result + ": " + shieldedResult);
281             }
282             // frontEndActionState has no post constraints
283             this.__getControllerCalls2r = getControllerCalls2r;
284             if (isMetafacadePropertyCachingEnabled())
285             {
286                 this.__getControllerCalls2rSet = true;
287             }
288         }
289         return getControllerCalls2r;
290     }
291 
292     /**
293      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
294      * @return  List
295      */
296     protected abstract List handleGetControllerCalls();
297 
298     private List<FrontEndExceptionHandler> __getExceptions3r;
299     private boolean __getExceptions3rSet = false;
300 
301     /**
302      * Represents an operation on the server called by an action. Optionally may defer operations to
303      * the
304      * controller.
305      * @return (List<FrontEndExceptionHandler>)handleGetExceptions()
306      */
307     public final List<FrontEndExceptionHandler> getExceptions()
308     {
309         List<FrontEndExceptionHandler> getExceptions3r = this.__getExceptions3r;
310         if (!this.__getExceptions3rSet)
311         {
312             // frontEndActionState has no pre constraints
313             List result = handleGetExceptions();
314             List shieldedResult = this.shieldedElements(result);
315             try
316             {
317                 getExceptions3r = (List<FrontEndExceptionHandler>)shieldedResult;
318             }
319             catch (ClassCastException ex)
320             {
321                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
322                 FrontEndActionStateLogic.logger.warn("incorrect metafacade cast for FrontEndActionStateLogic.getExceptions List<FrontEndExceptionHandler> " + result + ": " + shieldedResult);
323             }
324             // frontEndActionState has no post constraints
325             this.__getExceptions3r = getExceptions3r;
326             if (isMetafacadePropertyCachingEnabled())
327             {
328                 this.__getExceptions3rSet = true;
329             }
330         }
331         return getExceptions3r;
332     }
333 
334     /**
335      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
336      * @return  List
337      */
338     protected abstract List handleGetExceptions();
339 
340     private FrontEndForward __getForward4r;
341     private boolean __getForward4rSet = false;
342 
343     /**
344      * Represents an operation on the server called by an action. Optionally may defer operations to
345      * the
346      * controller.
347      * @return (FrontEndForward)handleGetForward()
348      */
349     public final FrontEndForward getForward()
350     {
351         FrontEndForward getForward4r = this.__getForward4r;
352         if (!this.__getForward4rSet)
353         {
354             // frontEndActionState has no pre constraints
355             Object result = handleGetForward();
356             MetafacadeBase shieldedResult = this.shieldedElement(result);
357             try
358             {
359                 getForward4r = (FrontEndForward)shieldedResult;
360             }
361             catch (ClassCastException ex)
362             {
363                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
364                 FrontEndActionStateLogic.logger.warn("incorrect metafacade cast for FrontEndActionStateLogic.getForward FrontEndForward " + result + ": " + shieldedResult);
365             }
366             // frontEndActionState has no post constraints
367             this.__getForward4r = getForward4r;
368             if (isMetafacadePropertyCachingEnabled())
369             {
370                 this.__getForward4rSet = true;
371             }
372         }
373         return getForward4r;
374     }
375 
376     /**
377      * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type
378      * @return Object
379      */
380     protected abstract Object handleGetForward();
381 
382     /**
383      * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndActionState::each front-end action state must have a name</p>
384      * <p><b>Error:</b> A "front-end" action state must have a non-empty name.</p>
385      * <p><b>OCL:</b> context FrontEndActionState inv: name->notEmpty()</p>
386      * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndActionState::front-end action states can have at most one outgoing transition</p>
387      * <p><b>Error:</b> A "front-end" action state needs at most one outgoing transition that is not an exception-transition.</p>
388      * <p><b>OCL:</b> context FrontEndActionState inv: serverSide implies (exceptions->size() + 1 = outgoings->size() or exceptions->size() = outgoings->size())</p>
389      * @param validationMessages Collection<ModelValidationMessage>
390      * @see ActionStateFacadeLogicImpl#validateInvariants(Collection validationMessages)
391      */
392     @Override
393     public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
394     {
395         super.validateInvariants(validationMessages);
396         try
397         {
398             final Object contextElement = this.THIS();
399             boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"name")));
400             if (!constraintValid)
401             {
402                 validationMessages.add(
403                     new ModelValidationMessage(
404                         (MetafacadeBase)contextElement ,
405                         "org::andromda::metafacades::uml::FrontEndActionState::each front-end action state must have a name",
406                         "A \"front-end\" action state must have a non-empty name."));
407             }
408         }
409         catch (Throwable th)
410         {
411             Throwable cause = th.getCause();
412             int depth = 0; // Some throwables have infinite recursion
413             while (cause != null && depth < 7)
414             {
415                 th = cause;
416                 depth++;
417             }
418             logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndActionState::each front-end action state must have a name' ON "
419                 + this.THIS().toString() + ": " + th.getMessage(), th);
420         }
421         try
422         {
423             final Object contextElement = this.THIS();
424             boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(contextElement,"serverSide"))).booleanValue()?(OCLExpressions.equal(OCLCollections.size(OCLIntrospector.invoke(contextElement,"exceptions"))+1,OCLCollections.size(OCLIntrospector.invoke(contextElement,"outgoings")))||OCLExpressions.equal(OCLCollections.size(OCLIntrospector.invoke(contextElement,"exceptions")),OCLCollections.size(OCLIntrospector.invoke(contextElement,"outgoings")))):true));
425             if (!constraintValid)
426             {
427                 validationMessages.add(
428                     new ModelValidationMessage(
429                         (MetafacadeBase)contextElement ,
430                         "org::andromda::metafacades::uml::FrontEndActionState::front-end action states can have at most one outgoing transition",
431                         "A \"front-end\" action state needs at most one outgoing transition that is not an exception-transition."));
432             }
433         }
434         catch (Throwable th)
435         {
436             Throwable cause = th.getCause();
437             int depth = 0; // Some throwables have infinite recursion
438             while (cause != null && depth < 7)
439             {
440                 th = cause;
441                 depth++;
442             }
443             logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndActionState::front-end action states can have at most one outgoing transition' ON "
444                 + this.THIS().toString() + ": " + th.getMessage(), th);
445         }
446     }
447 }