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.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
23
24
25
26
27 public abstract class FrontEndPackageLogic
28 extends PackageFacadeLogicImpl
29 implements FrontEndPackage
30 {
31
32
33
34
35 protected Object metaObject;
36
37
38
39
40
41 protected FrontEndPackageLogic(Object metaObjectIn, String context)
42 {
43 super((UmlPackage)metaObjectIn, getContext(context));
44 this.metaObject = metaObjectIn;
45 }
46
47
48
49
50 private static final Logger logger = Logger.getLogger(FrontEndPackageLogic.class);
51
52
53
54
55
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
67
68
69 @Override
70 public void resetMetafacadeContext(String context)
71 {
72 if (!this.contextRoot)
73 {
74 context = getContext(context);
75 setMetafacadeContext (context);
76 }
77 }
78
79
80
81
82
83 public boolean isFrontEndPackageMetaType()
84 {
85 return true;
86 }
87
88
89
90 private List<FrontEndAction> __getFrontEndUseCases1r;
91 private boolean __getFrontEndUseCases1rSet = false;
92
93
94
95
96
97 public final List<FrontEndAction> getFrontEndUseCases()
98 {
99 List<FrontEndAction> getFrontEndUseCases1r = this.__getFrontEndUseCases1r;
100 if (!this.__getFrontEndUseCases1rSet)
101 {
102
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
112 FrontEndPackageLogic.logger.warn("incorrect metafacade cast for FrontEndPackageLogic.getFrontEndUseCases List<FrontEndAction> " + result + ": " + shieldedResult);
113 }
114
115 this.__getFrontEndUseCases1r = getFrontEndUseCases1r;
116 if (isMetafacadePropertyCachingEnabled())
117 {
118 this.__getFrontEndUseCases1rSet = true;
119 }
120 }
121 return getFrontEndUseCases1r;
122 }
123
124
125
126
127
128 protected abstract List handleGetFrontEndUseCases();
129
130 private List<FrontEndController> __getFrontEndControllers2r;
131 private boolean __getFrontEndControllers2rSet = false;
132
133
134
135
136
137 public final List<FrontEndController> getFrontEndControllers()
138 {
139 List<FrontEndController> getFrontEndControllers2r = this.__getFrontEndControllers2r;
140 if (!this.__getFrontEndControllers2rSet)
141 {
142
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
152 FrontEndPackageLogic.logger.warn("incorrect metafacade cast for FrontEndPackageLogic.getFrontEndControllers List<FrontEndController> " + result + ": " + shieldedResult);
153 }
154
155 this.__getFrontEndControllers2r = getFrontEndControllers2r;
156 if (isMetafacadePropertyCachingEnabled())
157 {
158 this.__getFrontEndControllers2rSet = true;
159 }
160 }
161 return getFrontEndControllers2r;
162 }
163
164
165
166
167
168 protected abstract List handleGetFrontEndControllers();
169
170
171
172
173
174
175
176
177
178
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;
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;
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 }