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.FrontEndController;
13  import org.andromda.metafacades.uml.FrontEndPackage;
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.modelmanagement.UmlPackage;
20  
21  /**
22   * Represents a package storing "front-end" components.
23   * MetafacadeLogic for FrontEndPackage
24   *
25   * @see FrontEndPackage
26   */
27  public abstract class FrontEndPackageLogic
28      extends PackageFacadeLogicImpl
29      implements FrontEndPackage
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 FrontEndPackageLogic(Object metaObjectIn, String context)
42      {
43          super((UmlPackage)metaObjectIn, getContext(context));
44          this.metaObject = metaObjectIn;
45      }
46  
47      /**
48       * The logger instance.
49       */
50      private static final Logger logger = Logger.getLogger(FrontEndPackageLogic.class);
51  
52      /**
53       * Gets the context for this metafacade logic instance.
54       * @param context String. Set to FrontEndPackage 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.FrontEndPackage";
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 FrontEndPackage
82       */
83      public boolean isFrontEndPackageMetaType()
84      {
85          return true;
86      }
87  
88      // ------------- associations ------------------
89  
90      private List<FrontEndAction> __getFrontEndUseCases1r;
91      private boolean __getFrontEndUseCases1rSet = false;
92  
93      /**
94       * Represents a package storing "front-end" components.
95       * @return (List<FrontEndAction>)handleGetFrontEndUseCases()
96       */
97      public final List<FrontEndAction> getFrontEndUseCases()
98      {
99          List<FrontEndAction> getFrontEndUseCases1r = this.__getFrontEndUseCases1r;
100         if (!this.__getFrontEndUseCases1rSet)
101         {
102             // frontEndPackage has no pre constraints
103             List result = handleGetFrontEndUseCases();
104             List shieldedResult = this.shieldedElements(result);
105             try
106             {
107                 getFrontEndUseCases1r = (List<FrontEndAction>)shieldedResult;
108             }
109             catch (ClassCastException ex)
110             {
111                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
112                 FrontEndPackageLogic.logger.warn("incorrect metafacade cast for FrontEndPackageLogic.getFrontEndUseCases List<FrontEndAction> " + result + ": " + shieldedResult);
113             }
114             // frontEndPackage has no post constraints
115             this.__getFrontEndUseCases1r = getFrontEndUseCases1r;
116             if (isMetafacadePropertyCachingEnabled())
117             {
118                 this.__getFrontEndUseCases1rSet = true;
119             }
120         }
121         return getFrontEndUseCases1r;
122     }
123 
124     /**
125      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
126      * @return  List
127      */
128     protected abstract List handleGetFrontEndUseCases();
129 
130     private List<FrontEndController> __getFrontEndControllers2r;
131     private boolean __getFrontEndControllers2rSet = false;
132 
133     /**
134      * Represents a package storing "front-end" components.
135      * @return (List<FrontEndController>)handleGetFrontEndControllers()
136      */
137     public final List<FrontEndController> getFrontEndControllers()
138     {
139         List<FrontEndController> getFrontEndControllers2r = this.__getFrontEndControllers2r;
140         if (!this.__getFrontEndControllers2rSet)
141         {
142             // frontEndPackage has no pre constraints
143             List result = handleGetFrontEndControllers();
144             List shieldedResult = this.shieldedElements(result);
145             try
146             {
147                 getFrontEndControllers2r = (List<FrontEndController>)shieldedResult;
148             }
149             catch (ClassCastException ex)
150             {
151                 // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
152                 FrontEndPackageLogic.logger.warn("incorrect metafacade cast for FrontEndPackageLogic.getFrontEndControllers List<FrontEndController> " + result + ": " + shieldedResult);
153             }
154             // frontEndPackage has no post constraints
155             this.__getFrontEndControllers2r = getFrontEndControllers2r;
156             if (isMetafacadePropertyCachingEnabled())
157             {
158                 this.__getFrontEndControllers2rSet = true;
159             }
160         }
161         return getFrontEndControllers2r;
162     }
163 
164     /**
165      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
166      * @return  List
167      */
168     protected abstract List handleGetFrontEndControllers();
169 
170     /**
171      * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndPackage::no more than one controller per package</p>
172      * <p><b>Error:</b> In order to avoid possible naming collisions at most one controller per package is allowed. It is recommended to refactor your model.</p>
173      * <p><b>OCL:</b> context FrontEndPackage inv: frontEndControllers->size() < 2</p>
174      * <p><b>Constraint:</b> org::andromda::metafacades::uml::FrontEndPackage::no more than one usecase per package</p>
175      * <p><b>Error:</b> In order to avoid possible naming collisions at most one FrontEndUseCase per package is allowed. It is recommended to refactor your model.</p>
176      * <p><b>OCL:</b> context FrontEndPackage inv: frontEndUseCases->size() < 2</p>
177      * @param validationMessages Collection<ModelValidationMessage>
178      * @see PackageFacadeLogicImpl#validateInvariants(Collection validationMessages)
179      */
180     @Override
181     public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
182     {
183         super.validateInvariants(validationMessages);
184         try
185         {
186             final Object contextElement = this.THIS();
187             boolean constraintValid = OCLResultEnsurer.ensure(OCLExpressions.less(OCLCollections.size(OCLIntrospector.invoke(contextElement,"frontEndControllers")),2));
188             if (!constraintValid)
189             {
190                 validationMessages.add(
191                     new ModelValidationMessage(
192                         (MetafacadeBase)contextElement ,
193                         "org::andromda::metafacades::uml::FrontEndPackage::no more than one controller per package",
194                         "In order to avoid possible naming collisions at most one controller per package is allowed. It is recommended to refactor your model."));
195             }
196         }
197         catch (Throwable th)
198         {
199             Throwable cause = th.getCause();
200             int depth = 0; // Some throwables have infinite recursion
201             while (cause != null && depth < 7)
202             {
203                 th = cause;
204                 depth++;
205             }
206             logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndPackage::no more than one controller per package' ON "
207                 + this.THIS().toString() + ": " + th.getMessage(), th);
208         }
209         try
210         {
211             final Object contextElement = this.THIS();
212             boolean constraintValid = OCLResultEnsurer.ensure(OCLExpressions.less(OCLCollections.size(OCLIntrospector.invoke(contextElement,"frontEndUseCases")),2));
213             if (!constraintValid)
214             {
215                 validationMessages.add(
216                     new ModelValidationMessage(
217                         (MetafacadeBase)contextElement ,
218                         "org::andromda::metafacades::uml::FrontEndPackage::no more than one usecase per package",
219                         "In order to avoid possible naming collisions at most one FrontEndUseCase per package is allowed. It is recommended to refactor your model."));
220             }
221         }
222         catch (Throwable th)
223         {
224             Throwable cause = th.getCause();
225             int depth = 0; // Some throwables have infinite recursion
226             while (cause != null && depth < 7)
227             {
228                 th = cause;
229                 depth++;
230             }
231             logger.error("Error validating constraint 'org::andromda::metafacades::uml::FrontEndPackage::no more than one usecase per package' ON "
232                 + this.THIS().toString() + ": " + th.getMessage(), th);
233         }
234     }
235 }