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.DependencyFacade;
12  import org.andromda.metafacades.uml.FrontEndAction;
13  import org.andromda.metafacades.uml.FrontEndController;
14  import org.andromda.metafacades.uml.FrontEndUseCase;
15  import org.andromda.translation.ocl.validation.OCLCollections;
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   * A front end controller is assigned as the context of a use-case. The controller provides the
23   * "controlling" of the use case's activity.
24   * MetafacadeLogic for FrontEndController
25   *
26   * @see FrontEndController
27   */
28  public abstract class FrontEndControllerLogic
29      extends ClassifierFacadeLogicImpl
30      implements FrontEndController
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 FrontEndControllerLogic(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(FrontEndControllerLogic.class);
52  
53      /**
54       * Gets the context for this metafacade logic instance.
55       * @param context String. Set to FrontEndController 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.FrontEndController";
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 FrontEndController
83       */
84      public boolean isFrontEndControllerMetaType()
85      {
86          return true;
87      }
88  
89      // ------------- associations ------------------
90  
91      private FrontEndUseCase __getUseCase1r;
92      private boolean __getUseCase1rSet = false;
93  
94      /**
95       * Returns the controller for this use-case.
96       * @return (FrontEndUseCase)handleGetUseCase()
97       */
98      public final FrontEndUseCase getUseCase()
99      {
100         FrontEndUseCase getUseCase1r = this.__getUseCase1r;
101         if (!this.__getUseCase1rSet)
102         {
103             // controller has no pre constraints
104             Object result = handleGetUseCase();
105             MetafacadeBase shieldedResult = this.shieldedElement(result);
106             try
107             {
108                 getUseCase1r = (FrontEndUseCase)shieldedResult;
109             }
110             catch (ClassCastException ex)
111             {
112                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
113                 FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getUseCase FrontEndUseCase " + result + ": " + shieldedResult);
114             }
115             // controller has no post constraints
116             this.__getUseCase1r = getUseCase1r;
117             if (isMetafacadePropertyCachingEnabled())
118             {
119                 this.__getUseCase1rSet = true;
120             }
121         }
122         return getUseCase1r;
123     }
124 
125     /**
126      * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type
127      * @return Object
128      */
129     protected abstract Object handleGetUseCase();
130 
131     private List<DependencyFacade> __getServiceReferences2r;
132     private boolean __getServiceReferences2rSet = false;
133 
134     /**
135      * A front end controller is assigned as the context of a use-case. The controller provides the
136      * "controlling" of the use case's activity.
137      * @return (List<DependencyFacade>)handleGetServiceReferences()
138      */
139     public final List<DependencyFacade> getServiceReferences()
140     {
141         List<DependencyFacade> getServiceReferences2r = this.__getServiceReferences2r;
142         if (!this.__getServiceReferences2rSet)
143         {
144             // frontEndController has no pre constraints
145             List result = handleGetServiceReferences();
146             List shieldedResult = this.shieldedElements(result);
147             try
148             {
149                 getServiceReferences2r = (List<DependencyFacade>)shieldedResult;
150             }
151             catch (ClassCastException ex)
152             {
153                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
154                 FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getServiceReferences List<DependencyFacade> " + result + ": " + shieldedResult);
155             }
156             // frontEndController has no post constraints
157             this.__getServiceReferences2r = getServiceReferences2r;
158             if (isMetafacadePropertyCachingEnabled())
159             {
160                 this.__getServiceReferences2rSet = true;
161             }
162         }
163         return getServiceReferences2r;
164     }
165 
166     /**
167      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
168      * @return  List
169      */
170     protected abstract List handleGetServiceReferences();
171 
172     private List<FrontEndAction> __getDeferringActions3r;
173     private boolean __getDeferringActions3rSet = false;
174 
175     /**
176      * The controller that will handle the execution of this front-end action. This controller is
177      * set as the context of the activity graph (and therefore also of the use-case).
178      * @return (List<FrontEndAction>)handleGetDeferringActions()
179      */
180     public final List<FrontEndAction> getDeferringActions()
181     {
182         List<FrontEndAction> getDeferringActions3r = this.__getDeferringActions3r;
183         if (!this.__getDeferringActions3rSet)
184         {
185             // controller has no pre constraints
186             List result = handleGetDeferringActions();
187             List shieldedResult = this.shieldedElements(result);
188             try
189             {
190                 getDeferringActions3r = (List<FrontEndAction>)shieldedResult;
191             }
192             catch (ClassCastException ex)
193             {
194                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
195                 FrontEndControllerLogic.logger.warn("incorrect metafacade cast for FrontEndControllerLogic.getDeferringActions List<FrontEndAction> " + result + ": " + shieldedResult);
196             }
197             // controller has no post constraints
198             this.__getDeferringActions3r = getDeferringActions3r;
199             if (isMetafacadePropertyCachingEnabled())
200             {
201                 this.__getDeferringActions3rSet = true;
202             }
203         }
204         return getDeferringActions3r;
205     }
206 
207     /**
208      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
209      * @return  List
210      */
211     protected abstract List handleGetDeferringActions();
212 
213     /**
214      * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndController::front-end controllers need a package</p>
215      * <p><b>Error:</b> Each front-end controller is required to be modeled in a package, doing otherwise will result in uncompileable code due to filename collisions.</p>
216      * <p><b>OCL:</b> context FrontEndController inv: packageName->notEmpty()</p>
217      * @param validationMessages Collection<ModelValidationMessage>
218      * @see ClassifierFacadeLogicImpl#validateInvariants(Collection validationMessages)
219      */
220     @Override
221     public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
222     {
223         super.validateInvariants(validationMessages);
224         try
225         {
226             final Object contextElement = this.THIS();
227             boolean constraintValid = OCLResultEnsurer.ensure(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"packageName")));
228             if (!constraintValid)
229             {
230                 validationMessages.add(
231                     new ModelValidationMessage(
232                         (MetafacadeBase)contextElement ,
233                         "org::andromda::metafacades::uml::FrontEndController::front-end controllers need a package",
234                         "Each front-end controller is required to be modeled in a package, doing otherwise will result in uncompileable code due to filename collisions."));
235             }
236         }
237         catch (Throwable th)
238         {
239             Throwable cause = th.getCause();
240             int depth = 0; // Some throwables have infinite recursion
241             while (cause != null && depth < 7)
242             {
243                 th = cause;
244                 depth++;
245             }
246             logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndController::front-end controllers need a package' ON "
247                 + this.THIS().toString() + ": " + th.getMessage(), th);
248         }
249     }
250 }