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; |
42 | |
|
43 | |
import java.awt.Image; |
44 | |
import java.io.BufferedInputStream; |
45 | |
import java.io.File; |
46 | |
import java.io.FileInputStream; |
47 | |
import java.io.IOException; |
48 | |
import java.net.MalformedURLException; |
49 | |
import java.net.URL; |
50 | |
import java.util.ArrayList; |
51 | |
import java.util.Collection; |
52 | |
import java.util.Collections; |
53 | |
import java.util.HashMap; |
54 | |
import java.util.List; |
55 | |
import java.util.Map; |
56 | |
import java.util.Set; |
57 | |
import java.util.StringTokenizer; |
58 | |
|
59 | |
import javax.swing.ImageIcon; |
60 | |
|
61 | |
import org.apache.log4j.Logger; |
62 | |
import org.argouml.cognitive.Critic; |
63 | |
import org.argouml.cognitive.Decision; |
64 | |
import org.argouml.cognitive.ToDoItem; |
65 | |
import org.argouml.cognitive.Translator; |
66 | |
import org.argouml.kernel.ProfileConfiguration; |
67 | |
import org.argouml.model.Model; |
68 | |
import org.argouml.profile.internal.ocl.CrOCL; |
69 | |
import org.argouml.profile.internal.ocl.InvalidOclException; |
70 | |
import org.argouml.uml.cognitive.UMLDecision; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
public class UserDefinedProfile extends Profile { |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | 0 | private static final Logger LOG = Logger |
83 | |
.getLogger(UserDefinedProfile.class); |
84 | |
|
85 | |
private String displayName; |
86 | |
|
87 | |
private File modelFile; |
88 | |
|
89 | 0 | private Collection profilePackages = null; |
90 | 0 | private Object packageLock = new Object(); |
91 | |
|
92 | 0 | private UserDefinedFigNodeStrategy figNodeStrategy |
93 | |
= new UserDefinedFigNodeStrategy(); |
94 | |
|
95 | |
private ProfileReference reference; |
96 | |
|
97 | |
private ProfileManager profileManager; |
98 | |
|
99 | 0 | private boolean criticsLoaded = false; |
100 | |
|
101 | 0 | private class UserDefinedFigNodeStrategy implements FigNodeStrategy { |
102 | |
|
103 | 0 | private Map<String, Image> images = new HashMap<String, Image>(); |
104 | |
|
105 | |
public Image getIconForStereotype(Object stereotype) { |
106 | 0 | return images.get(Model.getFacade().getName(stereotype)); |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public void addDesrciptor(FigNodeDescriptor fnd) { |
115 | 0 | images.put(fnd.stereotype, fnd.img); |
116 | 0 | } |
117 | |
} |
118 | |
|
119 | 0 | private class FigNodeDescriptor { |
120 | |
private String stereotype; |
121 | |
|
122 | |
private Image img; |
123 | |
|
124 | |
private String src; |
125 | |
|
126 | |
private int length; |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
public boolean isValid() { |
132 | 0 | return stereotype != null && src != null && length > 0; |
133 | |
} |
134 | |
} |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
public UserDefinedProfile(File file, ProfileManager manager) |
145 | 0 | throws ProfileException { |
146 | 0 | LOG.info("load " + file); |
147 | 0 | displayName = file.getName(); |
148 | 0 | modelFile = file; |
149 | |
try { |
150 | 0 | reference = new UserProfileReference(file.getPath()); |
151 | 0 | } catch (MalformedURLException e) { |
152 | 0 | throw new ProfileException( |
153 | |
"Failed to create the ProfileReference.", e); |
154 | 0 | } |
155 | 0 | profileManager = manager; |
156 | 0 | } |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
@Deprecated |
168 | |
public UserDefinedProfile(File file) throws ProfileException { |
169 | 0 | this(file, getSomeProfileManager()); |
170 | 0 | } |
171 | |
|
172 | 0 | private static class NullProfileManager implements ProfileManager { |
173 | |
|
174 | |
public void addSearchPathDirectory(String path) { |
175 | 0 | } |
176 | |
|
177 | |
public void addToDefaultProfiles(Profile profile) { |
178 | 0 | } |
179 | |
|
180 | |
public void applyConfiguration(ProfileConfiguration pc) { |
181 | 0 | } |
182 | |
|
183 | |
public List<Profile> getDefaultProfiles() { |
184 | 0 | return new ArrayList<Profile>(); |
185 | |
} |
186 | |
|
187 | |
public Profile getProfileForClass(String className) { |
188 | 0 | return null; |
189 | |
} |
190 | |
|
191 | |
public List<Profile> getRegisteredProfiles() { |
192 | 0 | return new ArrayList<Profile>(); |
193 | |
} |
194 | |
|
195 | |
public List<String> getSearchPathDirectories() { |
196 | 0 | return new ArrayList<String>(); |
197 | |
} |
198 | |
|
199 | |
public Profile getUMLProfile() { |
200 | 0 | return null; |
201 | |
} |
202 | |
|
203 | |
public Profile lookForRegisteredProfile(String profile) { |
204 | 0 | return null; |
205 | |
} |
206 | |
|
207 | |
public void refreshRegisteredProfiles() { |
208 | 0 | } |
209 | |
|
210 | |
public void registerProfile(Profile profile) { |
211 | 0 | } |
212 | |
|
213 | |
public void removeFromDefaultProfiles(Profile profile) { |
214 | 0 | } |
215 | |
|
216 | |
public void removeProfile(Profile profile) { |
217 | 0 | } |
218 | |
|
219 | |
public void removeSearchPathDirectory(String path) { |
220 | 0 | } |
221 | |
|
222 | |
} |
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
public UserDefinedProfile(URL url, ProfileManager manager) |
233 | 0 | throws ProfileException { |
234 | 0 | LOG.info("load " + url); |
235 | 0 | reference = new UserProfileReference(url.getPath(), url); |
236 | 0 | profileManager = manager; |
237 | 0 | } |
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
@Deprecated |
249 | |
public UserDefinedProfile(URL url) throws ProfileException { |
250 | 0 | this(url, getSomeProfileManager()); |
251 | 0 | } |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
public UserDefinedProfile(String dn, URL url, Set<Critic> critics, |
267 | |
Set<String> dependencies, ProfileManager manager) |
268 | 0 | throws ProfileException { |
269 | 0 | LOG.info("load " + url); |
270 | |
|
271 | 0 | this.displayName = dn; |
272 | 0 | reference = new UserProfileReference(url.getPath(), url); |
273 | |
|
274 | 0 | this.setCritics(critics); |
275 | |
|
276 | 0 | for (String profileID : dependencies) { |
277 | 0 | addProfileDependency(profileID); |
278 | |
} |
279 | 0 | profileManager = manager; |
280 | 0 | } |
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
@Deprecated |
296 | |
public UserDefinedProfile(String dn, URL url, Set<Critic> critics, |
297 | |
Set<String> dependencies) throws ProfileException { |
298 | 0 | this(dn, url, critics, dependencies, getSomeProfileManager()); |
299 | 0 | } |
300 | |
|
301 | |
private static ProfileManager getSomeProfileManager() { |
302 | 0 | if (ProfileFacade.isInitiated()) { |
303 | 0 | return ProfileFacade.getManager(); |
304 | |
} |
305 | 0 | return new NullProfileManager(); |
306 | |
} |
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
private void loadModel() { |
314 | 0 | synchronized (packageLock) { |
315 | 0 | if (profilePackages == null) { |
316 | |
try { |
317 | 0 | if (modelFile != null) { |
318 | 0 | profilePackages = new FileModelLoader() |
319 | |
.loadModel(reference); |
320 | |
} else { |
321 | 0 | profilePackages = new URLModelLoader() |
322 | |
.loadModel(reference); |
323 | |
} |
324 | 0 | } catch (ProfileException e1) { |
325 | 0 | LOG.error("Exception loading profile " |
326 | |
+ reference.getPath(), e1); |
327 | 0 | profilePackages = Collections.emptySet(); |
328 | 0 | return; |
329 | 0 | } |
330 | |
} |
331 | |
|
332 | 0 | Collection packagesInProfile = filterPackages(profilePackages); |
333 | |
|
334 | 0 | for (Object obj : packagesInProfile) { |
335 | |
|
336 | |
|
337 | |
|
338 | 0 | if (Model.getFacade().isAModelElement(obj) |
339 | |
&& (Model.getFacade().isAProfile(obj) |
340 | |
|| (packagesInProfile.size() == 1))) { |
341 | |
|
342 | |
|
343 | 0 | String name = Model.getFacade().getName(obj); |
344 | 0 | if (name != null) { |
345 | 0 | displayName = name; |
346 | |
} else { |
347 | 0 | if (displayName == null) { |
348 | 0 | displayName = Translator |
349 | |
.localize("misc.profile.unnamed"); |
350 | |
} |
351 | |
} |
352 | 0 | LOG.info("profile " + displayName); |
353 | |
|
354 | 0 | loadDependentProfiles(obj); |
355 | 0 | } |
356 | |
} |
357 | |
|
358 | 0 | loadFigNodes(packagesInProfile); |
359 | 0 | } |
360 | 0 | } |
361 | |
|
362 | |
|
363 | |
private void loadDependentProfiles(Object obj) { |
364 | 0 | if (Model.getFacade().getUmlVersion().charAt(0) == '1') { |
365 | 0 | loadDependentProfilesUml1(obj); |
366 | |
} |
367 | |
|
368 | 0 | } |
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
private void loadDependentProfilesUml1(Object pkg) { |
378 | |
|
379 | 0 | String dependencyListStr = Model.getFacade().getTaggedValueValue(pkg, |
380 | |
"Dependency"); |
381 | 0 | StringTokenizer st = new StringTokenizer(dependencyListStr, " ,;:"); |
382 | |
|
383 | 0 | String dependencyName = null; |
384 | |
|
385 | 0 | while (st.hasMoreTokens()) { |
386 | 0 | dependencyName = st.nextToken(); |
387 | 0 | if (dependencyName != null) { |
388 | 0 | LOG.debug("Adding dependency " + dependencyName); |
389 | 0 | Profile profile = profileManager |
390 | |
.lookForRegisteredProfile(dependencyName); |
391 | 0 | if (profile != null) { |
392 | 0 | addProfileDependency(profile); |
393 | |
} else { |
394 | 0 | LOG.warn("The profile \"" + displayName |
395 | |
+ "\" has a dependency named \"" + dependencyName |
396 | |
+ "\" which isn't solvable."); |
397 | |
} |
398 | 0 | } |
399 | |
} |
400 | 0 | } |
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
private void loadFigNodes(Collection packagesInProfile) { |
409 | 0 | Collection allStereotypes = Model.getExtensionMechanismsHelper() |
410 | |
.getStereotypes(packagesInProfile); |
411 | 0 | for (Object stereotype : allStereotypes) { |
412 | 0 | Collection tags = Model.getFacade().getTaggedValuesCollection( |
413 | |
stereotype); |
414 | |
|
415 | 0 | for (Object tag : tags) { |
416 | 0 | String tagName = Model.getFacade().getTag(tag); |
417 | 0 | if (tagName == null) { |
418 | 0 | LOG.debug("profile package with stereotype " |
419 | |
+ Model.getFacade().getName(stereotype) |
420 | |
+ " contains a null tag definition"); |
421 | 0 | } else if (tagName.toLowerCase().equals("figure")) { |
422 | 0 | LOG.debug("AddFigNode " |
423 | |
+ Model.getFacade().getName(stereotype)); |
424 | |
|
425 | 0 | String value = Model.getFacade().getValueOfTag(tag); |
426 | 0 | File f = new File(value); |
427 | 0 | FigNodeDescriptor fnd = null; |
428 | |
try { |
429 | 0 | fnd = loadImage(Model.getFacade().getName(stereotype) |
430 | |
.toString(), f); |
431 | 0 | figNodeStrategy.addDesrciptor(fnd); |
432 | 0 | } catch (IOException e) { |
433 | 0 | LOG.error("Error loading FigNode", e); |
434 | 0 | } |
435 | |
} |
436 | 0 | } |
437 | 0 | } |
438 | 0 | } |
439 | |
|
440 | |
@Override |
441 | |
public Set<Critic> getCritics() { |
442 | 0 | if (!criticsLoaded ) { |
443 | 0 | Set<Critic> myCritics = super.getCritics(); |
444 | 0 | myCritics.addAll(getAllCritiquesInModel()); |
445 | 0 | this.setCritics(myCritics); |
446 | 0 | criticsLoaded = true; |
447 | |
} |
448 | 0 | return super.getCritics(); |
449 | |
} |
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
private Collection filterPackages(Collection packages) { |
455 | 0 | Collection ret = new ArrayList(); |
456 | |
|
457 | |
|
458 | |
|
459 | 0 | for (Object object: packages) { |
460 | 0 | if (Model.getFacade().isAPackage(object)) { |
461 | 0 | ret.add(object); |
462 | |
} |
463 | |
} |
464 | 0 | return ret; |
465 | |
} |
466 | |
|
467 | |
private CrOCL generateCriticFromComment(Object critique) { |
468 | 0 | String ocl = "" + Model.getFacade().getBody(critique); |
469 | 0 | String headline = null; |
470 | 0 | String description = null; |
471 | 0 | int priority = ToDoItem.HIGH_PRIORITY; |
472 | 0 | List<Decision> supportedDecisions = new ArrayList<Decision>(); |
473 | 0 | List<String> knowledgeTypes = new ArrayList<String>(); |
474 | 0 | String moreInfoURL = null; |
475 | |
|
476 | 0 | Collection tags = Model.getFacade().getTaggedValuesCollection(critique); |
477 | 0 | boolean i18nFound = false; |
478 | |
|
479 | 0 | for (Object tag : tags) { |
480 | 0 | if (Model.getFacade().getTag(tag).toLowerCase().equals("i18n")) { |
481 | 0 | i18nFound = true; |
482 | 0 | String i18nSource = Model.getFacade().getValueOfTag(tag); |
483 | 0 | headline = Translator.localize(i18nSource + "-head"); |
484 | 0 | description = Translator.localize(i18nSource + "-desc"); |
485 | 0 | moreInfoURL = Translator.localize(i18nSource + "-moreInfoURL"); |
486 | 0 | } else if (!i18nFound |
487 | |
&& Model.getFacade().getTag(tag).toLowerCase().equals( |
488 | |
"headline")) { |
489 | 0 | headline = Model.getFacade().getValueOfTag(tag); |
490 | 0 | } else if (!i18nFound |
491 | |
&& Model.getFacade().getTag(tag).toLowerCase().equals( |
492 | |
"description")) { |
493 | 0 | description = Model.getFacade().getValueOfTag(tag); |
494 | 0 | } else if (Model.getFacade().getTag(tag).toLowerCase().equals( |
495 | |
"priority")) { |
496 | 0 | priority = str2Priority(Model.getFacade().getValueOfTag(tag)); |
497 | 0 | } else if (Model.getFacade().getTag(tag).toLowerCase().equals( |
498 | |
"supporteddecision")) { |
499 | 0 | String decStr = Model.getFacade().getValueOfTag(tag); |
500 | |
|
501 | 0 | StringTokenizer st = new StringTokenizer(decStr, ",;:"); |
502 | |
|
503 | 0 | while (st.hasMoreTokens()) { |
504 | 0 | Decision decision = str2Decision(st.nextToken().trim() |
505 | |
.toLowerCase()); |
506 | |
|
507 | 0 | if (decision != null) { |
508 | 0 | supportedDecisions.add(decision); |
509 | |
} |
510 | 0 | } |
511 | 0 | } else if (Model.getFacade().getTag(tag).toLowerCase().equals( |
512 | |
"knowledgetype")) { |
513 | 0 | String ktStr = Model.getFacade().getValueOfTag(tag); |
514 | |
|
515 | 0 | StringTokenizer st = new StringTokenizer(ktStr, ",;:"); |
516 | |
|
517 | 0 | while (st.hasMoreTokens()) { |
518 | 0 | String knowledge = str2KnowledgeType(st.nextToken().trim() |
519 | |
.toLowerCase()); |
520 | |
|
521 | 0 | if (knowledge != null) { |
522 | 0 | knowledgeTypes.add(knowledge); |
523 | |
} |
524 | 0 | } |
525 | 0 | } else if (!i18nFound |
526 | |
&& Model.getFacade().getTag(tag).toLowerCase().equals( |
527 | |
"moreinfourl")) { |
528 | 0 | moreInfoURL = Model.getFacade().getValueOfTag(tag); |
529 | |
} |
530 | |
|
531 | |
} |
532 | |
|
533 | 0 | LOG.debug("OCL-Critic: " + ocl); |
534 | |
|
535 | |
try { |
536 | 0 | return new CrOCL(ocl, headline, description, priority, |
537 | |
supportedDecisions, knowledgeTypes, moreInfoURL); |
538 | 0 | } catch (InvalidOclException e) { |
539 | 0 | LOG.error("Invalid OCL in XMI!", e); |
540 | |
|
541 | 0 | return null; |
542 | |
} |
543 | |
|
544 | |
} |
545 | |
|
546 | |
private String str2KnowledgeType(String token) { |
547 | 0 | String knowledge = null; |
548 | |
|
549 | 0 | if (token.equals("completeness")) { |
550 | 0 | knowledge = Critic.KT_COMPLETENESS; |
551 | |
} |
552 | 0 | if (token.equals("consistency")) { |
553 | 0 | knowledge = Critic.KT_CONSISTENCY; |
554 | |
} |
555 | 0 | if (token.equals("correctness")) { |
556 | 0 | knowledge = Critic.KT_CORRECTNESS; |
557 | |
} |
558 | 0 | if (token.equals("designers")) { |
559 | 0 | knowledge = Critic.KT_DESIGNERS; |
560 | |
} |
561 | 0 | if (token.equals("experiencial")) { |
562 | 0 | knowledge = Critic.KT_EXPERIENCIAL; |
563 | |
} |
564 | 0 | if (token.equals("optimization")) { |
565 | 0 | knowledge = Critic.KT_OPTIMIZATION; |
566 | |
} |
567 | 0 | if (token.equals("organizational")) { |
568 | 0 | knowledge = Critic.KT_ORGANIZATIONAL; |
569 | |
} |
570 | 0 | if (token.equals("presentation")) { |
571 | 0 | knowledge = Critic.KT_PRESENTATION; |
572 | |
} |
573 | 0 | if (token.equals("semantics")) { |
574 | 0 | knowledge = Critic.KT_SEMANTICS; |
575 | |
} |
576 | 0 | if (token.equals("syntax")) { |
577 | 0 | knowledge = Critic.KT_SYNTAX; |
578 | |
} |
579 | 0 | if (token.equals("tool")) { |
580 | 0 | knowledge = Critic.KT_TOOL; |
581 | |
} |
582 | 0 | return knowledge; |
583 | |
} |
584 | |
|
585 | |
private int str2Priority(String prioStr) { |
586 | 0 | int prio = ToDoItem.MED_PRIORITY; |
587 | |
|
588 | 0 | if (prioStr.toLowerCase().equals("high")) { |
589 | 0 | prio = ToDoItem.HIGH_PRIORITY; |
590 | 0 | } else if (prioStr.toLowerCase().equals("med")) { |
591 | 0 | prio = ToDoItem.MED_PRIORITY; |
592 | 0 | } else if (prioStr.toLowerCase().equals("low")) { |
593 | 0 | prio = ToDoItem.LOW_PRIORITY; |
594 | 0 | } else if (prioStr.toLowerCase().equals("interruptive")) { |
595 | 0 | prio = ToDoItem.INTERRUPTIVE_PRIORITY; |
596 | |
} |
597 | 0 | return prio; |
598 | |
} |
599 | |
|
600 | |
private Decision str2Decision(String token) { |
601 | 0 | Decision decision = null; |
602 | |
|
603 | 0 | if (token.equals("behavior")) { |
604 | 0 | decision = UMLDecision.BEHAVIOR; |
605 | |
} |
606 | 0 | if (token.equals("containment")) { |
607 | 0 | decision = UMLDecision.CONTAINMENT; |
608 | |
} |
609 | 0 | if (token.equals("classselection")) { |
610 | 0 | decision = UMLDecision.CLASS_SELECTION; |
611 | |
} |
612 | 0 | if (token.equals("codegen")) { |
613 | 0 | decision = UMLDecision.CODE_GEN; |
614 | |
} |
615 | 0 | if (token.equals("expectedusage")) { |
616 | 0 | decision = UMLDecision.EXPECTED_USAGE; |
617 | |
} |
618 | 0 | if (token.equals("inheritance")) { |
619 | 0 | decision = UMLDecision.INHERITANCE; |
620 | |
} |
621 | 0 | if (token.equals("instantiation")) { |
622 | 0 | decision = UMLDecision.INSTANCIATION; |
623 | |
} |
624 | 0 | if (token.equals("methods")) { |
625 | 0 | decision = UMLDecision.METHODS; |
626 | |
} |
627 | 0 | if (token.equals("modularity")) { |
628 | 0 | decision = UMLDecision.MODULARITY; |
629 | |
} |
630 | 0 | if (token.equals("naming")) { |
631 | 0 | decision = UMLDecision.NAMING; |
632 | |
} |
633 | 0 | if (token.equals("patterns")) { |
634 | 0 | decision = UMLDecision.PATTERNS; |
635 | |
} |
636 | 0 | if (token.equals("plannedextensions")) { |
637 | 0 | decision = UMLDecision.PLANNED_EXTENSIONS; |
638 | |
} |
639 | 0 | if (token.equals("relationships")) { |
640 | 0 | decision = UMLDecision.RELATIONSHIPS; |
641 | |
} |
642 | 0 | if (token.equals("statemachines")) { |
643 | 0 | decision = UMLDecision.STATE_MACHINES; |
644 | |
} |
645 | 0 | if (token.equals("stereotypes")) { |
646 | 0 | decision = UMLDecision.STEREOTYPES; |
647 | |
} |
648 | 0 | if (token.equals("storage")) { |
649 | 0 | decision = UMLDecision.STORAGE; |
650 | |
} |
651 | 0 | return decision; |
652 | |
} |
653 | |
|
654 | |
|
655 | |
private List<CrOCL> getAllCritiquesInModel() { |
656 | 0 | List<CrOCL> ret = new ArrayList<CrOCL>(); |
657 | |
|
658 | 0 | Collection<Object> comments = getAllCommentsInModel(getProfilePackages()); |
659 | |
|
660 | 0 | for (Object comment : comments) { |
661 | 0 | if (Model.getExtensionMechanismsHelper().hasStereotype(comment, |
662 | |
"Critic")) { |
663 | 0 | CrOCL cr = generateCriticFromComment(comment); |
664 | |
|
665 | 0 | if (cr != null) { |
666 | 0 | ret.add(cr); |
667 | |
} |
668 | 0 | } |
669 | |
} |
670 | 0 | return ret; |
671 | |
} |
672 | |
|
673 | |
@SuppressWarnings("unchecked") |
674 | |
private Collection<Object> getAllCommentsInModel(Collection objs) { |
675 | 0 | Collection<Object> col = new ArrayList<Object>(); |
676 | 0 | for (Object obj : objs) { |
677 | 0 | if (Model.getFacade().isAComment(obj)) { |
678 | 0 | col.add(obj); |
679 | 0 | } else if (Model.getFacade().isANamespace(obj)) { |
680 | 0 | Collection contents = Model |
681 | |
.getModelManagementHelper().getAllContents(obj); |
682 | 0 | if (contents != null) { |
683 | 0 | col.addAll(contents); |
684 | |
} |
685 | 0 | } |
686 | |
} |
687 | 0 | return col; |
688 | |
} |
689 | |
|
690 | |
|
691 | |
|
692 | |
|
693 | |
public String getDisplayName() { |
694 | |
|
695 | |
|
696 | 0 | loadModel(); |
697 | 0 | return displayName; |
698 | |
} |
699 | |
|
700 | |
|
701 | |
|
702 | |
|
703 | |
|
704 | |
|
705 | |
@Override |
706 | |
public FormatingStrategy getFormatingStrategy() { |
707 | 0 | return null; |
708 | |
} |
709 | |
|
710 | |
|
711 | |
|
712 | |
|
713 | |
|
714 | |
|
715 | |
@Override |
716 | |
public FigNodeStrategy getFigureStrategy() { |
717 | 0 | return figNodeStrategy; |
718 | |
} |
719 | |
|
720 | |
|
721 | |
|
722 | |
|
723 | |
public File getModelFile() { |
724 | 0 | return modelFile; |
725 | |
} |
726 | |
|
727 | |
|
728 | |
|
729 | |
|
730 | |
@Override |
731 | |
public String toString() { |
732 | 0 | File str = getModelFile(); |
733 | 0 | return super.toString() + (str != null ? " [" + str + "]" : ""); |
734 | |
} |
735 | |
|
736 | |
@Override |
737 | |
public Collection getProfilePackages() { |
738 | 0 | loadModel(); |
739 | 0 | return profilePackages; |
740 | |
} |
741 | |
|
742 | |
@Override |
743 | |
public Collection getLoadedPackages() { |
744 | 0 | if (profilePackages == null) { |
745 | 0 | return Collections.emptySet(); |
746 | |
} else { |
747 | 0 | return Collections.unmodifiableCollection(profilePackages); |
748 | |
} |
749 | |
} |
750 | |
|
751 | |
private FigNodeDescriptor loadImage(String stereotype, File f) |
752 | |
throws IOException { |
753 | 0 | FigNodeDescriptor descriptor = new FigNodeDescriptor(); |
754 | 0 | descriptor.length = (int) f.length(); |
755 | 0 | descriptor.src = f.getPath(); |
756 | 0 | descriptor.stereotype = stereotype; |
757 | |
|
758 | 0 | BufferedInputStream bis = new BufferedInputStream( |
759 | |
new FileInputStream(f)); |
760 | |
|
761 | 0 | byte[] buf = new byte[descriptor.length]; |
762 | |
try { |
763 | 0 | bis.read(buf); |
764 | 0 | } catch (IOException e) { |
765 | 0 | e.printStackTrace(); |
766 | 0 | } |
767 | |
|
768 | 0 | descriptor.img = new ImageIcon(buf).getImage(); |
769 | |
|
770 | 0 | return descriptor; |
771 | |
} |
772 | |
} |