1 package com.bm.ejb3metadata.annotations.metadata;
2
3 import java.util.Collection;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import javax.ejb.ApplicationException;
8
9 import com.bm.ejb3metadata.xml.struct.EJB3;
10
11
12
13
14
15
16
17 public class EjbJarAnnotationMetadata {
18
19 private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory
20 .getLogger(EjbJarAnnotationMetadata.class);
21
22
23
24
25 private Map<String, ClassAnnotationMetadata> classesAnnotationMetadata = null;
26
27
28
29
30
31
32 private Map<String, String> interface2implemantation = null;
33
34
35
36
37 private EJB3 ejb3 = null;
38
39
40
41
42 private Map<String, ApplicationException> applicationExceptions = null;
43
44
45
46
47 public EjbJarAnnotationMetadata() {
48 classesAnnotationMetadata = new HashMap<String, ClassAnnotationMetadata>();
49 }
50
51
52
53
54
55
56 public void mergeClassAnnotationMetadata(EjbJarAnnotationMetadata other) {
57 classesAnnotationMetadata.putAll(other.classesAnnotationMetadata);
58 }
59
60
61
62
63
64
65
66 public void addClassAnnotationMetadata(final ClassAnnotationMetadata classAnnotationMetadata) {
67 String key = classAnnotationMetadata.getClassName();
68
69 if (classesAnnotationMetadata.containsKey(key)) {
70 String msg = "EjbJarAnnotationMetadata.addClassAnnotationMetadata.alreadyPresent";
71 logger.trace(msg);
72
73 }
74 classesAnnotationMetadata.put(key, classAnnotationMetadata);
75 }
76
77
78
79
80
81
82
83
84
85
86 public String getBeanImplementationForInterface(String interfaceName) {
87 return this.interface2implemantation.get(interfaceName);
88 }
89
90
91
92
93
94
95
96
97
98
99 public String getBeanImplementationForInterface(Class interfaceName) {
100 final String name = interfaceName.getName();
101 if (interface2implemantation == null) {
102 buildInterfaceImplementationMap();
103 }
104 return this.interface2implemantation.get(name.replace('.', '/'));
105 }
106
107
108
109
110 private void buildInterfaceImplementationMap() {
111 interface2implemantation = new HashMap<String, String>();
112 for (ClassAnnotationMetadata current : this.getClassAnnotationMetadataCollection()) {
113 if (current.getLocalInterfaces() != null) {
114 for (String interfaze : current.getLocalInterfaces().getInterfaces()) {
115
116
117 if (current.getClassName().indexOf('$') < 0) {
118 this.interface2implemantation.put(interfaze, current.getClassName());
119 }
120 }
121 }
122 if (current.getRemoteInterfaces() != null) {
123 for (String interfaze : current.getRemoteInterfaces().getInterfaces()) {
124
125
126 if (current.getClassName().indexOf('$') < 0) {
127 this.interface2implemantation.put(interfaze, current.getClassName());
128 }
129 }
130 }
131 }
132 }
133
134
135
136
137
138
139
140
141 public ClassAnnotationMetadata getClassAnnotationMetadata(final String className) {
142 return classesAnnotationMetadata.get(className);
143 }
144
145
146
147
148
149
150 public Collection<ClassAnnotationMetadata> getClassAnnotationMetadataCollection() {
151 return classesAnnotationMetadata.values();
152 }
153
154
155
156
157 public EJB3 getEjb3() {
158 return ejb3;
159 }
160
161
162
163
164
165
166
167 public void setEjb3(final EJB3 ejb3) {
168 this.ejb3 = ejb3;
169 }
170
171
172
173
174
175
176
177 public Map<String, ApplicationException> getApplicationExceptions() {
178 if (applicationExceptions != null) {
179 return applicationExceptions;
180 }
181
182
183 applicationExceptions = new HashMap<String, ApplicationException>();
184
185
186 for (ClassAnnotationMetadata classMetadata : getClassAnnotationMetadataCollection()) {
187 ApplicationException appException = classMetadata.getApplicationException();
188
189 if (appException != null) {
190 applicationExceptions.put(classMetadata.getClassName().replaceAll("/", "."),
191 appException);
192 }
193 }
194 return applicationExceptions;
195 }
196
197
198
199
200
201
202 public Map<String, String> getInterface2implemantation() {
203 if (interface2implemantation == null) {
204 buildInterfaceImplementationMap();
205 }
206 return interface2implemantation;
207 }
208
209 }