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.Destination;
13  import org.andromda.metafacades.uml.Role;
14  import org.andromda.metafacades.uml.Service;
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.commons.collections.Predicate;
19  import org.apache.log4j.Logger;
20  import org.omg.uml.foundation.core.Classifier;
21  
22  /**
23   * Represents a service.
24   * MetafacadeLogic for Service
25   *
26   * @see Service
27   */
28  public abstract class ServiceLogic
29      extends ClassifierFacadeLogicImpl
30      implements Service
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 ServiceLogic(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(ServiceLogic.class);
52  
53      /**
54       * Gets the context for this metafacade logic instance.
55       * @param context String. Set to Service 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.Service";
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 Service
83       */
84      public boolean isServiceMetaType()
85      {
86          return true;
87      }
88  
89      // ------------- associations ------------------
90  
91      /**
92       * Represents a service.
93       * @return (Collection<DependencyFacade>)handleGetServiceReferences()
94       */
95      public final Collection<DependencyFacade> getServiceReferences()
96      {
97          Collection<DependencyFacade> getServiceReferences1r = null;
98          // service has no pre constraints
99          Collection result = handleGetServiceReferences();
100         List shieldedResult = this.shieldedElements(result);
101         try
102         {
103             getServiceReferences1r = (Collection<DependencyFacade>)shieldedResult;
104         }
105         catch (ClassCastException ex)
106         {
107             // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
108             ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getServiceReferences Collection<DependencyFacade> " + result + ": " + shieldedResult);
109         }
110         // service has no post constraints
111         return getServiceReferences1r;
112     }
113 
114     /**
115      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
116      * @return  Collection
117      */
118     protected abstract Collection handleGetServiceReferences();
119 
120     /**
121      * Represents a service.
122      * @return (Collection<DependencyFacade>)handleGetEntityReferences()
123      */
124     public final Collection<DependencyFacade> getEntityReferences()
125     {
126         Collection<DependencyFacade> getEntityReferences2r = null;
127         // service has no pre constraints
128         Collection result = handleGetEntityReferences();
129         List shieldedResult = this.shieldedElements(result);
130         try
131         {
132             getEntityReferences2r = (Collection<DependencyFacade>)shieldedResult;
133         }
134         catch (ClassCastException ex)
135         {
136             // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
137             ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getEntityReferences Collection<DependencyFacade> " + result + ": " + shieldedResult);
138         }
139         // service has no post constraints
140         return getEntityReferences2r;
141     }
142 
143     /**
144      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
145      * @return  Collection
146      */
147     protected abstract Collection handleGetEntityReferences();
148 
149     /**
150      * Represents a service.
151      * @return (Collection<Role>)handleGetAllRoles()
152      */
153     public final Collection<Role> getAllRoles()
154     {
155         Collection<Role> getAllRoles3r = null;
156         // service has no pre constraints
157         Collection result = handleGetAllRoles();
158         List shieldedResult = this.shieldedElements(result);
159         try
160         {
161             getAllRoles3r = (Collection<Role>)shieldedResult;
162         }
163         catch (ClassCastException ex)
164         {
165             // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
166             ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllRoles Collection<Role> " + result + ": " + shieldedResult);
167         }
168         // service has no post constraints
169         return getAllRoles3r;
170     }
171 
172     /**
173      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
174      * @return  Collection
175      */
176     protected abstract Collection handleGetAllRoles();
177 
178     /**
179      * Represents a service.
180      * @return (Collection<Role>)handleGetRoles()
181      */
182     public final Collection<Role> getRoles()
183     {
184         Collection<Role> getRoles4r = null;
185         // service has no pre constraints
186         Collection result = handleGetRoles();
187         List shieldedResult = this.shieldedElements(result);
188         try
189         {
190             getRoles4r = (Collection<Role>)shieldedResult;
191         }
192         catch (ClassCastException ex)
193         {
194             // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
195             ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getRoles Collection<Role> " + result + ": " + shieldedResult);
196         }
197         // service has no post constraints
198         return getRoles4r;
199     }
200 
201     /**
202      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
203      * @return  Collection
204      */
205     protected abstract Collection handleGetRoles();
206 
207     /**
208      * Represents a service.
209      * @return (Collection<DependencyFacade>)handleGetAllServiceReferences()
210      */
211     public final Collection<DependencyFacade> getAllServiceReferences()
212     {
213         Collection<DependencyFacade> getAllServiceReferences5r = null;
214         // service has no pre constraints
215         Collection result = handleGetAllServiceReferences();
216         List shieldedResult = this.shieldedElements(result);
217         try
218         {
219             getAllServiceReferences5r = (Collection<DependencyFacade>)shieldedResult;
220         }
221         catch (ClassCastException ex)
222         {
223             // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
224             ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllServiceReferences Collection<DependencyFacade> " + result + ": " + shieldedResult);
225         }
226         // service has no post constraints
227         return getAllServiceReferences5r;
228     }
229 
230     /**
231      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
232      * @return  Collection
233      */
234     protected abstract Collection handleGetAllServiceReferences();
235 
236     /**
237      * Represents a service.
238      * @return (Collection<Destination>)handleGetAllMessagingDestinations()
239      */
240     public final Collection<Destination> getAllMessagingDestinations()
241     {
242         Collection<Destination> getAllMessagingDestinations6r = null;
243         // service has no pre constraints
244         Collection result = handleGetAllMessagingDestinations();
245         List shieldedResult = this.shieldedElements(result);
246         try
247         {
248             getAllMessagingDestinations6r = (Collection<Destination>)shieldedResult;
249         }
250         catch (ClassCastException ex)
251         {
252             // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
253             ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllMessagingDestinations Collection<Destination> " + result + ": " + shieldedResult);
254         }
255         // service has no post constraints
256         return getAllMessagingDestinations6r;
257     }
258 
259     /**
260      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
261      * @return  Collection
262      */
263     protected abstract Collection handleGetAllMessagingDestinations();
264 
265     /**
266      * Represents a service.
267      * @return (Collection<Destination>)handleGetMessagingDestinations()
268      */
269     public final Collection<Destination> getMessagingDestinations()
270     {
271         Collection<Destination> getMessagingDestinations7r = null;
272         // service has no pre constraints
273         Collection result = handleGetMessagingDestinations();
274         List shieldedResult = this.shieldedElements(result);
275         try
276         {
277             getMessagingDestinations7r = (Collection<Destination>)shieldedResult;
278         }
279         catch (ClassCastException ex)
280         {
281             // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
282             ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getMessagingDestinations Collection<Destination> " + result + ": " + shieldedResult);
283         }
284         // service has no post constraints
285         return getMessagingDestinations7r;
286     }
287 
288     /**
289      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
290      * @return  Collection
291      */
292     protected abstract Collection handleGetMessagingDestinations();
293 
294     /**
295      * Represents a service.
296      * @return (Collection<DependencyFacade>)handleGetAllEntityReferences()
297      */
298     public final Collection<DependencyFacade> getAllEntityReferences()
299     {
300         Collection<DependencyFacade> getAllEntityReferences8r = null;
301         // service has no pre constraints
302         Collection result = handleGetAllEntityReferences();
303         List shieldedResult = this.shieldedElements(result);
304         try
305         {
306             getAllEntityReferences8r = (Collection<DependencyFacade>)shieldedResult;
307         }
308         catch (ClassCastException ex)
309         {
310             // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
311             ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllEntityReferences Collection<DependencyFacade> " + result + ": " + shieldedResult);
312         }
313         // service has no post constraints
314         return getAllEntityReferences8r;
315     }
316 
317     /**
318      * UML Specific type is returned in Collection, transformed by shieldedElements to AndroMDA Metafacade type
319      * @return  Collection
320      */
321     protected abstract Collection handleGetAllEntityReferences();
322 
323     /**
324      * <p><b>Constraint:</b> org::andromda::metafacades::uml::Service::a service can only generalize another service</p>
325      * <p><b>Error:</b> A service can only generalize another service.</p>
326      * <p><b>OCL:</b> context Service 
327 inv : generalization -> notEmpty() implies generalization.oclIsKindOf(Service)</p>
328      * <p><b>Constraint:</b> org::andromda::metafacades::uml::Service::services can only specialize other service</p>
329      * <p><b>Error:</b> A service can only specialize another service.</p>
330      * <p><b>OCL:</b> context ServiceFacade inv : specializations -> notEmpty() implies specializations -> forAll(oclIsKindOf(Service))</p>
331      * @param validationMessages Collection<ModelValidationMessage>
332      * @see ClassifierFacadeLogicImpl#validateInvariants(Collection validationMessages)
333      */
334     @Override
335     public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
336     {
337         super.validateInvariants(validationMessages);
338         try
339         {
340             final Object contextElement = this.THIS();
341             boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"generalization")))).booleanValue()?OCLIntrospector.invoke(contextElement,"generalization") instanceof Service:true));
342             if (!constraintValid)
343             {
344                 validationMessages.add(
345                     new ModelValidationMessage(
346                         (MetafacadeBase)contextElement ,
347                         "org::andromda::metafacades::uml::Service::a service can only generalize another service",
348                         "A service can only generalize another service."));
349             }
350         }
351         catch (Throwable th)
352         {
353             Throwable cause = th.getCause();
354             int depth = 0; // Some throwables have infinite recursion
355             while (cause != null && depth < 7)
356             {
357                 th = cause;
358                 depth++;
359             }
360             logger.error("Error validating constraint 'org::andromda::metafacades::uml::Service::a service can only generalize another service' ON "
361                 + this.THIS().toString() + ": " + th.getMessage(), th);
362         }
363         try
364         {
365             final Object contextElement = this.THIS();
366             boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(OCLCollections.notEmpty(OCLIntrospector.invoke(contextElement,"specializations")))).booleanValue()?OCLCollections.forAll(OCLIntrospector.invoke(contextElement,"specializations"),new Predicate(){public boolean evaluate(Object object){return Boolean.valueOf(String.valueOf(object instanceof Service)).booleanValue();}}):true));
367             if (!constraintValid)
368             {
369                 validationMessages.add(
370                     new ModelValidationMessage(
371                         (MetafacadeBase)contextElement ,
372                         "org::andromda::metafacades::uml::Service::services can only specialize other service",
373                         "A service can only specialize another service."));
374             }
375         }
376         catch (Throwable th)
377         {
378             Throwable cause = th.getCause();
379             int depth = 0; // Some throwables have infinite recursion
380             while (cause != null && depth < 7)
381             {
382                 th = cause;
383                 depth++;
384             }
385             logger.error("Error validating constraint 'org::andromda::metafacades::uml::Service::services can only specialize other service' ON "
386                 + this.THIS().toString() + ": " + th.getMessage(), th);
387         }
388     }
389 }