1
2
3
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
24
25
26
27
28 public abstract class ServiceLogic
29 extends ClassifierFacadeLogicImpl
30 implements Service
31 {
32
33
34
35
36 protected Object metaObject;
37
38
39
40
41
42 protected ServiceLogic(Object metaObjectIn, String context)
43 {
44 super((Classifier)metaObjectIn, getContext(context));
45 this.metaObject = metaObjectIn;
46 }
47
48
49
50
51 private static final Logger logger = Logger.getLogger(ServiceLogic.class);
52
53
54
55
56
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
68
69
70 @Override
71 public void resetMetafacadeContext(String context)
72 {
73 if (!this.contextRoot)
74 {
75 context = getContext(context);
76 setMetafacadeContext (context);
77 }
78 }
79
80
81
82
83
84 public boolean isServiceMetaType()
85 {
86 return true;
87 }
88
89
90
91
92
93
94
95 public final Collection<DependencyFacade> getServiceReferences()
96 {
97 Collection<DependencyFacade> getServiceReferences1r = null;
98
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
108 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getServiceReferences Collection<DependencyFacade> " + result + ": " + shieldedResult);
109 }
110
111 return getServiceReferences1r;
112 }
113
114
115
116
117
118 protected abstract Collection handleGetServiceReferences();
119
120
121
122
123
124 public final Collection<DependencyFacade> getEntityReferences()
125 {
126 Collection<DependencyFacade> getEntityReferences2r = null;
127
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
137 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getEntityReferences Collection<DependencyFacade> " + result + ": " + shieldedResult);
138 }
139
140 return getEntityReferences2r;
141 }
142
143
144
145
146
147 protected abstract Collection handleGetEntityReferences();
148
149
150
151
152
153 public final Collection<Role> getAllRoles()
154 {
155 Collection<Role> getAllRoles3r = null;
156
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
166 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllRoles Collection<Role> " + result + ": " + shieldedResult);
167 }
168
169 return getAllRoles3r;
170 }
171
172
173
174
175
176 protected abstract Collection handleGetAllRoles();
177
178
179
180
181
182 public final Collection<Role> getRoles()
183 {
184 Collection<Role> getRoles4r = null;
185
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
195 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getRoles Collection<Role> " + result + ": " + shieldedResult);
196 }
197
198 return getRoles4r;
199 }
200
201
202
203
204
205 protected abstract Collection handleGetRoles();
206
207
208
209
210
211 public final Collection<DependencyFacade> getAllServiceReferences()
212 {
213 Collection<DependencyFacade> getAllServiceReferences5r = null;
214
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
224 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllServiceReferences Collection<DependencyFacade> " + result + ": " + shieldedResult);
225 }
226
227 return getAllServiceReferences5r;
228 }
229
230
231
232
233
234 protected abstract Collection handleGetAllServiceReferences();
235
236
237
238
239
240 public final Collection<Destination> getAllMessagingDestinations()
241 {
242 Collection<Destination> getAllMessagingDestinations6r = null;
243
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
253 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllMessagingDestinations Collection<Destination> " + result + ": " + shieldedResult);
254 }
255
256 return getAllMessagingDestinations6r;
257 }
258
259
260
261
262
263 protected abstract Collection handleGetAllMessagingDestinations();
264
265
266
267
268
269 public final Collection<Destination> getMessagingDestinations()
270 {
271 Collection<Destination> getMessagingDestinations7r = null;
272
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
282 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getMessagingDestinations Collection<Destination> " + result + ": " + shieldedResult);
283 }
284
285 return getMessagingDestinations7r;
286 }
287
288
289
290
291
292 protected abstract Collection handleGetMessagingDestinations();
293
294
295
296
297
298 public final Collection<DependencyFacade> getAllEntityReferences()
299 {
300 Collection<DependencyFacade> getAllEntityReferences8r = null;
301
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
311 ServiceLogic.logger.warn("incorrect metafacade cast for ServiceLogic.getAllEntityReferences Collection<DependencyFacade> " + result + ": " + shieldedResult);
312 }
313
314 return getAllEntityReferences8r;
315 }
316
317
318
319
320
321 protected abstract Collection handleGetAllEntityReferences();
322
323
324
325
326
327
328
329
330
331
332
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;
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;
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 }