KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > deployment > annotations > metadata > EjbJarAnnotationMetadata


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: EjbJarAnnotationMetadata.java 941 2006-07-26 09:06:13Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations.metadata;
27
28 import java.util.Collection JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Map JavaDoc;
31
32 import javax.ejb.ApplicationException JavaDoc;
33
34 import org.objectweb.easybeans.deployment.annotations.impl.JApplicationException;
35 import org.objectweb.easybeans.deployment.xml.struct.EJB3;
36 import org.objectweb.easybeans.log.JLog;
37 import org.objectweb.easybeans.log.JLogFactory;
38
39 /**
40  * This class represents the annotation metadata of all classes of an EjbJar file.
41  * From this class, we can get metadata of all beans.
42  * @author Florent Benoit
43  */

44 public class EjbJarAnnotationMetadata {
45
46     /**
47      * Logger.
48      */

49     private static JLog logger = JLogFactory.getLog(EjbJarAnnotationMetadata.class);
50
51     /**
52      * List of class annotations metadata.
53      */

54     private Map JavaDoc<String JavaDoc, ClassAnnotationMetadata> classesAnnotationMetadata = null;
55
56     /**
57      * Link to the Deployment Descriptor object.
58      */

59     private EJB3 ejb3 = null;
60
61     /**
62      * List of application exceptions used on this ejb-jar.
63      */

64     private Map JavaDoc<String JavaDoc, ApplicationException JavaDoc> applicationExceptions = null;
65
66     /**
67      * Constructor.
68      */

69     public EjbJarAnnotationMetadata() {
70         classesAnnotationMetadata = new HashMap JavaDoc<String JavaDoc, ClassAnnotationMetadata>();
71     }
72
73     /**
74      * Add annotation metadata for a given class.
75      * @param classAnnotationMetadata annotation metadata of a class.
76      */

77     public void addClassAnnotationMetadata(final ClassAnnotationMetadata classAnnotationMetadata) {
78         String JavaDoc key = classAnnotationMetadata.getClassName();
79         // already exists ?
80
if (classesAnnotationMetadata.containsKey(key)) {
81             String JavaDoc msg = logger.getI18n().getMessage("EjbJarAnnotationMetadata.addClassAnnotationMetadata.alreadyPresent", key);
82             logger.debug(msg);
83             throw new IllegalStateException JavaDoc(msg);
84         }
85         classesAnnotationMetadata.put(key, classAnnotationMetadata);
86     }
87
88
89     /**
90      * Get class annotation metadata.
91      * @param className key of the map of annotations bean.
92      * @return Bean annotation metadata of a given name.
93      */

94     public ClassAnnotationMetadata getClassAnnotationMetadata(final String JavaDoc className) {
95         return classesAnnotationMetadata.get(className);
96     }
97
98     /**
99      * Get collections of bean annotation metadata.
100      * @return collections of bean annotation metadata.
101      */

102     public Collection JavaDoc<ClassAnnotationMetadata> getClassAnnotationMetadataCollection() {
103         return classesAnnotationMetadata.values();
104     }
105
106     /**
107      * @return the ejb3 deployment descriptor object.
108      */

109     public EJB3 getEjb3() {
110         return ejb3;
111     }
112
113     /**
114      * Sets the ejb3 deployment descriptor object.
115      * @param ejb3 the ejb3 deployment descriptor object.
116      */

117     public void setEjb3(final EJB3 ejb3) {
118         this.ejb3 = ejb3;
119     }
120
121     /**
122      * Gets the list of application exceptions defined on this ejb jar metadata.
123      * @return the list of application exceptions defined on this ejb jar metadata.
124      */

125     public Map JavaDoc<String JavaDoc, ApplicationException JavaDoc> getApplicationExceptions() {
126         if (applicationExceptions != null) {
127             return applicationExceptions;
128         }
129
130         // compute it
131
applicationExceptions = new HashMap JavaDoc<String JavaDoc, ApplicationException JavaDoc>();
132
133         // For each class, look if it is an application exception
134
for (ClassAnnotationMetadata classMetadata : getClassAnnotationMetadataCollection()) {
135             ApplicationException JavaDoc appException = classMetadata.getApplicationException();
136             // found it then add it in the map.
137
if (appException != null) {
138                 applicationExceptions.put(classMetadata.getClassName().replaceAll("/", "."), appException);
139             }
140         }
141
142         // Add a default application exception (for checked exception)
143
applicationExceptions.put("DEFAULT", new JApplicationException());
144
145         return applicationExceptions;
146     }
147
148 }
149
Popular Tags