1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
package org.argouml.profile.internal; |
42 | |
|
43 | |
import java.net.MalformedURLException; |
44 | |
import java.util.ArrayList; |
45 | |
import java.util.Collection; |
46 | |
import java.util.Collections; |
47 | |
import java.util.HashSet; |
48 | |
import java.util.Set; |
49 | |
|
50 | |
import org.apache.log4j.Logger; |
51 | |
import org.argouml.cognitive.Critic; |
52 | |
import org.argouml.cognitive.ToDoItem; |
53 | |
import org.argouml.cognitive.Translator; |
54 | |
import org.argouml.model.Model; |
55 | |
import org.argouml.profile.CoreProfileReference; |
56 | |
import org.argouml.profile.DefaultTypeStrategy; |
57 | |
import org.argouml.profile.FormatingStrategy; |
58 | |
import org.argouml.profile.Profile; |
59 | |
import org.argouml.profile.ProfileException; |
60 | |
import org.argouml.profile.ProfileModelLoader; |
61 | |
import org.argouml.profile.ProfileReference; |
62 | |
import org.argouml.profile.ResourceModelLoader; |
63 | |
import org.argouml.profile.internal.ocl.CrOCL; |
64 | |
import org.argouml.profile.internal.ocl.InvalidOclException; |
65 | |
import org.argouml.uml.cognitive.critics.CrAssocNameConflict; |
66 | |
import org.argouml.uml.cognitive.critics.CrAttrNameConflict; |
67 | |
import org.argouml.uml.cognitive.critics.CrCircularAssocClass; |
68 | |
import org.argouml.uml.cognitive.critics.CrCircularInheritance; |
69 | |
import org.argouml.uml.cognitive.critics.CrClassMustBeAbstract; |
70 | |
import org.argouml.uml.cognitive.critics.CrCrossNamespaceAssoc; |
71 | |
import org.argouml.uml.cognitive.critics.CrDupParamName; |
72 | |
import org.argouml.uml.cognitive.critics.CrDupRoleNames; |
73 | |
import org.argouml.uml.cognitive.critics.CrFinalSubclassed; |
74 | |
import org.argouml.uml.cognitive.critics.CrForkOutgoingTransition; |
75 | |
import org.argouml.uml.cognitive.critics.CrIllegalGeneralization; |
76 | |
import org.argouml.uml.cognitive.critics.CrInterfaceAllPublic; |
77 | |
import org.argouml.uml.cognitive.critics.CrInterfaceOperOnly; |
78 | |
import org.argouml.uml.cognitive.critics.CrInvalidBranch; |
79 | |
import org.argouml.uml.cognitive.critics.CrInvalidFork; |
80 | |
import org.argouml.uml.cognitive.critics.CrInvalidHistory; |
81 | |
import org.argouml.uml.cognitive.critics.CrInvalidInitial; |
82 | |
import org.argouml.uml.cognitive.critics.CrInvalidJoin; |
83 | |
import org.argouml.uml.cognitive.critics.CrInvalidJoinTriggerOrGuard; |
84 | |
import org.argouml.uml.cognitive.critics.CrInvalidPseudoStateTrigger; |
85 | |
import org.argouml.uml.cognitive.critics.CrInvalidSynch; |
86 | |
import org.argouml.uml.cognitive.critics.CrJoinIncomingTransition; |
87 | |
import org.argouml.uml.cognitive.critics.CrMultiComposite; |
88 | |
import org.argouml.uml.cognitive.critics.CrMultipleAgg; |
89 | |
import org.argouml.uml.cognitive.critics.CrMultipleDeepHistoryStates; |
90 | |
import org.argouml.uml.cognitive.critics.CrMultipleShallowHistoryStates; |
91 | |
import org.argouml.uml.cognitive.critics.CrNWayAgg; |
92 | |
import org.argouml.uml.cognitive.critics.CrNameConflict; |
93 | |
import org.argouml.uml.cognitive.critics.CrNameConflictAC; |
94 | |
import org.argouml.uml.cognitive.critics.CrNameConfusion; |
95 | |
import org.argouml.uml.cognitive.critics.CrOppEndConflict; |
96 | |
import org.argouml.uml.cognitive.critics.CrOppEndVsAttr; |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | 7632 | public class ProfileUML extends Profile { |
104 | |
|
105 | 900 | private static final Logger LOG = Logger.getLogger(ProfileUML.class); |
106 | |
|
107 | |
private static final String PROFILE_UML14_FILE = "default-uml14.xmi"; |
108 | |
private static final String PROFILE_UML22_FILE = "default-uml22.xmi"; |
109 | |
|
110 | |
static final String NAME_UML14 = "UML 1.4"; |
111 | |
static final String NAME_UML22 = "UML 2.2"; |
112 | |
|
113 | |
private FormatingStrategy formatingStrategy; |
114 | |
private ProfileModelLoader profileModelLoader; |
115 | |
private Collection model; |
116 | |
|
117 | 900 | private Set<Critic> critics = null; |
118 | |
|
119 | 900 | private ProfileReference profileReference = null; |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
@SuppressWarnings("unchecked") |
126 | 900 | ProfileUML() throws ProfileException { |
127 | 900 | formatingStrategy = new FormatingStrategyUML(); |
128 | |
try { |
129 | 900 | if (Model.getFacade().getUmlVersion().charAt(0) == '1') { |
130 | 900 | profileReference = |
131 | |
new CoreProfileReference(PROFILE_UML14_FILE); |
132 | |
} else { |
133 | |
|
134 | 0 | CoreProfileReference.setProfileDirectory("uml22"); |
135 | 0 | profileReference = |
136 | |
new CoreProfileReference(PROFILE_UML22_FILE); |
137 | |
} |
138 | 0 | } catch (MalformedURLException e) { |
139 | 0 | throw new ProfileException( |
140 | |
"Exception while creating profile reference.", e); |
141 | 900 | } |
142 | 900 | } |
143 | |
|
144 | |
private Collection getModel() { |
145 | 10494 | if (model == null) { |
146 | 900 | profileModelLoader = new ResourceModelLoader(); |
147 | |
try { |
148 | 900 | model = profileModelLoader.loadModel(profileReference); |
149 | 0 | } catch (ProfileException e) { |
150 | 0 | LOG.error("Error loading UML profile", e); |
151 | 900 | } |
152 | |
|
153 | 900 | if (model == null) { |
154 | 0 | model = new ArrayList(); |
155 | 0 | model.add(Model.getModelManagementFactory().createProfile()); |
156 | |
} |
157 | |
} |
158 | 10494 | return model; |
159 | |
} |
160 | |
|
161 | |
private void loadWellFormednessRules() { |
162 | 900 | critics = new HashSet<Critic>(); |
163 | |
|
164 | 900 | critics.add(new CrAssocNameConflict()); |
165 | 900 | critics.add(new CrAttrNameConflict()); |
166 | 900 | critics.add(new CrCircularAssocClass()); |
167 | 900 | critics.add(new CrCircularInheritance()); |
168 | 900 | critics.add(new CrClassMustBeAbstract()); |
169 | 900 | critics.add(new CrCrossNamespaceAssoc()); |
170 | 900 | critics.add(new CrDupParamName()); |
171 | 900 | critics.add(new CrDupRoleNames()); |
172 | 900 | critics.add(new CrNameConfusion()); |
173 | |
|
174 | 900 | critics.add(new CrInvalidHistory()); |
175 | 900 | critics.add(new CrInvalidSynch()); |
176 | 900 | critics.add(new CrInvalidJoinTriggerOrGuard()); |
177 | 900 | critics.add(new CrInvalidPseudoStateTrigger()); |
178 | 900 | critics.add(new CrInvalidInitial()); |
179 | |
|
180 | 900 | critics.add(new CrInvalidJoin()); |
181 | 900 | critics.add(new CrInvalidFork()); |
182 | 900 | critics.add(new CrInvalidBranch()); |
183 | |
|
184 | 900 | critics.add(new CrMultipleDeepHistoryStates()); |
185 | 900 | critics.add(new CrMultipleShallowHistoryStates()); |
186 | 900 | critics.add(new CrForkOutgoingTransition()); |
187 | 900 | critics.add(new CrJoinIncomingTransition()); |
188 | |
|
189 | 900 | critics.add(new CrFinalSubclassed()); |
190 | 900 | critics.add(new CrIllegalGeneralization()); |
191 | 900 | critics.add(new CrInterfaceAllPublic()); |
192 | 900 | critics.add(new CrInterfaceOperOnly()); |
193 | 900 | critics.add(new CrMultipleAgg()); |
194 | 900 | critics.add(new CrNWayAgg()); |
195 | 900 | critics.add(new CrNameConflictAC()); |
196 | |
|
197 | 900 | critics.add(new CrOppEndConflict()); |
198 | 900 | critics.add(new CrMultiComposite()); |
199 | 900 | critics.add(new CrNameConflict()); |
200 | 900 | critics.add(new CrOppEndVsAttr()); |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
try { |
208 | 900 | critics.add(new CrOCL("context AssociationClass inv:" |
209 | |
+ "self.allConnections->" |
210 | |
+ "forAll( ar | self.allFeatures->" |
211 | |
+ "forAll( f | f.oclIsKindOf(StructuralFeature) " |
212 | |
+ "implies ar.name <> f.name ))", |
213 | |
Translator.localize("wfr.UML142.AssociationClass.1-head"), |
214 | |
Translator.localize("wfr.UML142.AssociationClass.1-desc"), |
215 | |
ToDoItem.HIGH_PRIORITY, null, null, "http://www.uml.org/")); |
216 | 0 | } catch (InvalidOclException e) { |
217 | 0 | e.printStackTrace(); |
218 | 900 | } |
219 | |
|
220 | |
|
221 | |
|
222 | |
try { |
223 | 900 | critics.add(new CrOCL("context AssociationClass inv:" |
224 | |
+ "self.allConnections->" |
225 | |
+ "forAll(ar | ar.participant <> self)", |
226 | |
Translator.localize("wfr.UML142.AssociationClass.2-head"), |
227 | |
Translator.localize("wfr.UML142.AssociationClass.2-desc"), |
228 | |
ToDoItem.HIGH_PRIORITY, null, null, "http://www.uml.org/")); |
229 | 0 | } catch (InvalidOclException e) { |
230 | 0 | e.printStackTrace(); |
231 | 900 | } |
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
try { |
256 | 900 | critics.add(new CrOCL("context Classifier inv:" |
257 | |
+ "self.oppositeAssociationEnds->" |
258 | |
+ "forAll( o | not self.allAttributes->" |
259 | |
+ "union (self.allContents)->" |
260 | |
+ "collect ( q | q.name )->includes (o.name) )", |
261 | |
Translator.localize("wfr.UML142.Classifier.5-head"), |
262 | |
Translator.localize("wfr.UML142.Classifier.5-desc"), |
263 | |
ToDoItem.HIGH_PRIORITY, null, null, "http://www.uml.org/")); |
264 | 0 | } catch (InvalidOclException e) { |
265 | 0 | e.printStackTrace(); |
266 | 900 | } |
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
try { |
272 | 900 | critics.add(new CrOCL("context DataType inv:" |
273 | |
+ "self.allFeatures->forAll(f | f.oclIsKindOf(Operation)" |
274 | |
+ " and f.oclAsType(Operation).isQuery)", |
275 | |
Translator.localize("wfr.UML142.DataType.1-head"), |
276 | |
Translator.localize("wfr.UML142.DataType.1-desc"), |
277 | |
ToDoItem.HIGH_PRIORITY, null, null, "http://www.uml.org/")); |
278 | 0 | } catch (InvalidOclException e) { |
279 | 0 | e.printStackTrace(); |
280 | 900 | } |
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
try { |
286 | 900 | critics.add(new CrOCL("context GeneralizableElement inv:" |
287 | |
+ "self.isRoot implies self.generalization->isEmpty", |
288 | |
Translator.localize("wfr.UML142.GeneralizableElement.1-head"), |
289 | |
Translator.localize("wfr.UML142.GeneralizableElement.1-desc"), |
290 | |
ToDoItem.HIGH_PRIORITY, null, null, "http://www.uml.org/")); |
291 | 0 | } catch (InvalidOclException e) { |
292 | 0 | e.printStackTrace(); |
293 | 900 | } |
294 | |
|
295 | |
|
296 | |
|
297 | |
try { |
298 | 900 | critics.add(new CrOCL("context GeneralizableElement inv:" |
299 | |
+ "self.generalization->" |
300 | |
+ "forAll(g |self.namespace.allContents->" |
301 | |
+ "includes(g.parent) )", |
302 | |
Translator.localize("wfr.UML142.GeneralizableElement.4-head"), |
303 | |
Translator.localize("wfr.UML142.GeneralizableElement.4-desc"), |
304 | |
ToDoItem.HIGH_PRIORITY, null, null, "http://www.uml.org/")); |
305 | 0 | } catch (InvalidOclException e) { |
306 | 0 | e.printStackTrace(); |
307 | 900 | } |
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
try { |
313 | 900 | critics.add(new CrOCL("context Namespace inv:" |
314 | |
+ "self.allContents -> " |
315 | |
+ "select(x|x.oclIsKindOf(Association))->" |
316 | |
+ "forAll(a1, a2 |a1.name = a2.name and " |
317 | |
+ "a1.connection.participant = a2.connection.participant" |
318 | |
+ " implies a1 = a2)", |
319 | |
Translator.localize("wfr.UML142.Namespace.2-head"), |
320 | |
Translator.localize("wfr.UML142.Namespace.2-desc"), |
321 | |
ToDoItem.HIGH_PRIORITY, null, null, |
322 | |
"http://www.uml.org/")); |
323 | 0 | } catch (InvalidOclException e) { |
324 | 0 | e.printStackTrace(); |
325 | 900 | } |
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
try { |
331 | 900 | critics.add(new CrOCL("context Actor inv: " |
332 | |
+ "self.associations->forAll(a | " |
333 | |
+ "a.connection->size = 2)", |
334 | |
Translator.localize("wfr.UML142.Actor.1a-head"), |
335 | |
Translator.localize("wfr.UML142.Actor.1a-desc"), |
336 | |
ToDoItem.HIGH_PRIORITY, null, null, |
337 | |
"http://www.uml.org/")); |
338 | 0 | } catch (InvalidOclException e) { |
339 | 0 | e.printStackTrace(); |
340 | 900 | } |
341 | |
|
342 | |
try { |
343 | 900 | critics.add(new CrOCL("context Actor inv: " |
344 | |
+ "self.associations->forAll(a | " |
345 | |
|
346 | |
+ "a.allConnections->exists(r | " |
347 | |
+ "r.type.oclIsKindOf(UseCase) or " |
348 | |
+ "r.type.oclIsKindOf(Subsystem) or " |
349 | |
+ "r.type.oclIsKindOf(Class)))", |
350 | |
Translator.localize("wfr.UML142.Actor.1b-head"), |
351 | |
Translator.localize("wfr.UML142.Actor.1b-desc"), |
352 | |
ToDoItem.HIGH_PRIORITY, null, null, |
353 | |
"http://www.uml.org/")); |
354 | 0 | } catch (InvalidOclException e) { |
355 | 0 | e.printStackTrace(); |
356 | 900 | } |
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
try { |
362 | 900 | critics.add(new CrOCL("context Actor inv:" |
363 | |
+ "self.contents->isEmpty", |
364 | |
Translator.localize("wfr.UML142.Actor.2-head"), |
365 | |
Translator.localize("wfr.UML142.Actor.2-desc"), |
366 | |
ToDoItem.HIGH_PRIORITY, null, null, |
367 | |
"http://www.uml.org/")); |
368 | 0 | } catch (InvalidOclException e) { |
369 | 0 | e.printStackTrace(); |
370 | 900 | } |
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
try { |
376 | 900 | critics.add(new CrOCL("context UseCase inv:" |
377 | |
+ "self.associations->forAll(a | a.connection->size = 2)", |
378 | |
Translator.localize("wfr.UML142.UseCase.1-head"), |
379 | |
Translator.localize("wfr.UML142.UseCase.1-desc"), |
380 | |
ToDoItem.HIGH_PRIORITY, null, null, |
381 | |
"http://www.uml.org/")); |
382 | 0 | } catch (InvalidOclException e) { |
383 | 0 | e.printStackTrace(); |
384 | 900 | } |
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
try { |
390 | 900 | critics.add(new CrOCL("context UseCase inv:" |
391 | |
+ "self.associations->forAll(a | " |
392 | |
+ "a.allConnections->forAll(s, o| " |
393 | |
+ "(s.type.specificationPath->isEmpty and " |
394 | |
+ "o.type.specificationPath->isEmpty ) " |
395 | |
+ "or " |
396 | |
+ "(not s.type.specificationPath->includesAll( " |
397 | |
+ "o.type.specificationPath) and " |
398 | |
+ "not o.type.specificationPath->includesAll( " |
399 | |
+ "s.type.specificationPath)) " |
400 | |
+ "))", |
401 | |
Translator.localize("wfr.UML142.UseCase.2-head"), |
402 | |
Translator.localize("wfr.UML142.UseCase.2-desc"), |
403 | |
ToDoItem.HIGH_PRIORITY, null, null, |
404 | |
"http://www.uml.org/")); |
405 | 0 | } catch (InvalidOclException e) { |
406 | 0 | e.printStackTrace(); |
407 | 900 | } |
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
try { |
413 | 900 | critics.add(new CrOCL("context UseCase inv:" |
414 | |
+ "self.contents->isEmpty", |
415 | |
Translator.localize("wfr.UML142.UseCase.3-head"), |
416 | |
Translator.localize("wfr.UML142.UseCase.3-desc"), |
417 | |
ToDoItem.HIGH_PRIORITY, null, null, |
418 | |
"http://www.uml.org/")); |
419 | 0 | } catch (InvalidOclException e) { |
420 | 0 | e.printStackTrace(); |
421 | 900 | } |
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
try { |
429 | 900 | critics.add(new CrOCL("context UseCase inv:" |
430 | |
+ "self.allExtensionPoints -> forAll (x, y | " |
431 | |
+ "x.name = y.name implies x = y )", |
432 | |
Translator.localize("wfr.UML142.UseCase.4-head"), |
433 | |
Translator.localize("wfr.UML142.UseCase.4-desc"), |
434 | |
ToDoItem.HIGH_PRIORITY, null, null, |
435 | |
"http://www.uml.org/")); |
436 | 0 | } catch (InvalidOclException e) { |
437 | 0 | e.printStackTrace(); |
438 | 900 | } |
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
try { |
444 | 900 | critics.add(new CrOCL("context ActionState inv:" |
445 | |
+ "self.outgoing->forAll(t | t.trigger->size = 0)", |
446 | |
Translator.localize("wfr.UML142.ActionState.3-head"), |
447 | |
Translator.localize("wfr.UML142.ActionState.3-desc"), |
448 | |
ToDoItem.HIGH_PRIORITY, null, null, |
449 | |
"http://www.uml.org/")); |
450 | 0 | } catch (InvalidOclException e) { |
451 | 0 | e.printStackTrace(); |
452 | 900 | } |
453 | |
|
454 | 900 | setCritics(critics); |
455 | 900 | } |
456 | |
|
457 | |
@Override |
458 | |
public FormatingStrategy getFormatingStrategy() { |
459 | 7632 | return formatingStrategy; |
460 | |
} |
461 | |
|
462 | |
@Override |
463 | |
public String getDisplayName() { |
464 | 1149 | if (Model.getFacade().getUmlVersion().charAt(0) == '1') { |
465 | 1149 | return NAME_UML14; |
466 | |
} |
467 | 0 | return NAME_UML22; |
468 | |
} |
469 | |
|
470 | |
|
471 | |
@Override |
472 | |
public Set<Critic> getCritics() { |
473 | 2846 | if (critics == null) { |
474 | 900 | loadWellFormednessRules(); |
475 | |
} |
476 | 2846 | return super.getCritics(); |
477 | |
} |
478 | |
|
479 | |
@Override |
480 | |
public Collection getProfilePackages() { |
481 | 2862 | return Collections.unmodifiableCollection(getModel()); |
482 | |
} |
483 | |
|
484 | |
|
485 | |
@Override |
486 | |
public Collection<Object> getLoadedPackages() { |
487 | 0 | if (model == null) { |
488 | 0 | return Collections.emptyList(); |
489 | |
} else { |
490 | 0 | return Collections.unmodifiableCollection(model); |
491 | |
} |
492 | |
} |
493 | |
|
494 | |
@Override |
495 | |
public DefaultTypeStrategy getDefaultTypeStrategy() { |
496 | 7632 | return new DefaultTypeStrategy() { |
497 | 7632 | private Collection model = getModel(); |
498 | |
public Object getDefaultAttributeType() { |
499 | 0 | return ModelUtils.findTypeInModel("Integer", model.iterator() |
500 | |
.next()); |
501 | |
} |
502 | |
|
503 | |
public Object getDefaultParameterType() { |
504 | 0 | return ModelUtils.findTypeInModel("Integer", model.iterator() |
505 | |
.next()); |
506 | |
} |
507 | |
|
508 | |
public Object getDefaultReturnType() { |
509 | 0 | return null; |
510 | |
} |
511 | |
|
512 | |
}; |
513 | |
} |
514 | |
} |