1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.nuiton.eugene.java.extension;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.nuiton.eugene.models.object.ObjectModelClassifier;
28 import org.nuiton.eugene.models.object.ObjectModelElement;
29
30 import java.util.Collections;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35
36
37
38
39
40 public class AnnotationsManagerExtension {
41
42 private static final Log log = LogFactory.getLog(AnnotationsManagerExtension.class);
43
44
45
46
47
48 public static final String OBJECTMODEL_EXTENSION = "annotations";
49
50
51
52
53
54 protected Map<String, AnnotationsManager> managers;
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 public List<ObjectModelAnnotation> getAnnotations(ObjectModelClassifier classifier,
71 ObjectModelElement element) {
72 AnnotationsManager annotationsManager = getManager(classifier);
73 List<ObjectModelAnnotation> result = null;
74 if (annotationsManager != null) {
75 result = annotationsManager.getAnnotations(element);
76 }
77 return result == null ? Collections.<ObjectModelAnnotation>emptyList() : result;
78 }
79
80
81
82
83
84
85
86
87 public AnnotationsManager getManager(ObjectModelClassifier classifier) {
88 Map<String, AnnotationsManager> managers = getManagers();
89 String fqn = classifier.getQualifiedName();
90 AnnotationsManager manager = managers.get(fqn);
91 if (manager == null) {
92 manager = new AnnotationsManager();
93 managers.put(fqn, manager);
94 if (log.isDebugEnabled()) {
95 log.debug("Add new annotationsManager for : " + fqn);
96 }
97 }
98 return manager;
99 }
100
101 protected Map<String, AnnotationsManager> getManagers() {
102 if (managers == null) {
103 managers = new HashMap<>();
104 }
105 return managers;
106 }
107 }