KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > deployment > annotations > analyzer > classes > JavaxEjbMessageDrivenVisitor


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: JavaxEjbMessageDrivenVisitor.java 77 2006-03-01 13:02:50Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations.analyzer.classes;
27
28 import static org.objectweb.easybeans.deployment.annotations.ClassType.MDB;
29
30 import org.objectweb.asm.AnnotationVisitor;
31 import org.objectweb.asm.Type;
32 import org.objectweb.asm.commons.EmptyVisitor;
33
34 import org.objectweb.easybeans.deployment.annotations.analyzer.AnnotationType;
35 import org.objectweb.easybeans.deployment.annotations.impl.JActivationConfigProperty;
36 import org.objectweb.easybeans.deployment.annotations.impl.JMessageDriven;
37 import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
38
39 /**
40  * This class manages the handling of @{@link javax.ejb.MessageDriven}
41  * annotation.
42  * @author Florent Benoit
43  */

44 public class JavaxEjbMessageDrivenVisitor extends AbsCommonEjbVisitor<JMessageDriven> implements AnnotationType {
45
46     /**
47      * Type of annotation.
48      */

49     public static final String JavaDoc TYPE = "Ljavax/ejb/MessageDriven;";
50
51     /**
52      * messageListenerInterface attribute of the annotation.
53      */

54     private static final String JavaDoc MESSAGE_LISTENER_INTERFACE = "messageListenerInterface";
55
56     /**
57      * activationConfig attribute of the annotation.
58      */

59     private static final String JavaDoc ACTIVATION_CONFIG = "activationConfig";
60
61     /**
62      * Message listener Interface.
63      */

64     private String JavaDoc messageListenerInterface = null;
65
66     /**
67      * Constructor.
68      * @param classAnnotationMetadata linked to a class metadata
69      */

70     public JavaxEjbMessageDrivenVisitor(final ClassAnnotationMetadata classAnnotationMetadata) {
71         super(classAnnotationMetadata);
72     }
73
74     /**
75      * Visits a primitive value of the annotation.<br>
76      * @param name the value name.
77      * @param value the actual value, whose type must be {@link Byte},
78      * {@link Boolean}, {@link Character}, {@link Short},
79      * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
80      * {@link String} or {@link Type}.
81      */

82     @Override JavaDoc
83     public void visit(final String JavaDoc name, final Object JavaDoc value) {
84         super.visit(name, value);
85         if (name.equals(MESSAGE_LISTENER_INTERFACE)) {
86             this.messageListenerInterface = ((Type) value).getInternalName();
87         }
88     }
89
90     /**
91      * Visits an enumeration value of the annotation.
92      * @param name the value name.
93      * @param desc the class descriptor of the enumeration class.
94      * @param value the actual enumeration value.
95      */

96     @Override JavaDoc
97     public void visitEnum(final String JavaDoc name, final String JavaDoc desc, final String JavaDoc value) {
98
99     }
100
101     /**
102      * Visits a nested annotation value of the annotation.
103      * @param name the value name.
104      * @param desc the class descriptor of the nested annotation class.
105      * @return a non null visitor to visit the actual nested annotation value.
106      * <i>The nested annotation value must be fully visited before
107      * calling other methods on this annotation visitor</i>.
108      */

109     @Override JavaDoc
110     public AnnotationVisitor visitAnnotation(final String JavaDoc name, final String JavaDoc desc) {
111         return this;
112     }
113
114     /**
115      * Visits an array value of the annotation.
116      * @param name the value name.
117      * @return a non null visitor to visit the actual array value elements. The
118      * 'name' parameters passed to the methods of this visitor are
119      * ignored. <i>All the array values must be visited before calling
120      * other methods on this annotation visitor</i>.
121      */

122     @Override JavaDoc
123     public AnnotationVisitor visitArray(final String JavaDoc name) {
124         if (name.equals(ACTIVATION_CONFIG)) {
125             return new ActivationConfigPropertyVisitor();
126         }
127         return this;
128     }
129
130     /**
131      * Visits the end of the annotation. Creates the object and store it
132      */

133     @Override JavaDoc
134     public void visitEnd() {
135         super.visitEnd();
136
137         // message listener interface
138
getJCommonBean().setMessageListenerInterface(messageListenerInterface);
139
140         // Set type
141
getAnnotationMetadata().setClassType(MDB);
142
143     }
144
145     /**
146      * @return type of the annotation (its description)
147      */

148     public String JavaDoc getType() {
149         return TYPE;
150     }
151
152     /**
153      * Classes manages the parsing of activationConfig[] array of &#64;{@link javax.ejb.MessageDriven}
154      * annotation.
155      * @author Florent Benoit
156      */

157     class ActivationConfigPropertyVisitor extends EmptyVisitor {
158
159         /**
160          * Attribute for property name.
161          */

162         private static final String JavaDoc PROPERTY_NAME = "propertyName";
163
164         /**
165          * Attribute for property value.
166          */

167         private static final String JavaDoc PROPERTY_VALUE = "propertyValue";
168
169         /**
170          * Property name.
171          */

172         private String JavaDoc propertyName = null;
173
174         /**
175          * Property value.
176          */

177         private String JavaDoc propertyValue = null;
178
179         /**
180          * Visits a primitive value of the annotation.
181          * @param name the value name.
182          * @param value the actual value, whose type must be {@link Byte},
183          * {@link Boolean}, {@link Character}, {@link Short},
184          * {@link Integer}, {@link Long}, {@link Float},
185          * {@link Double}, {@link String} or {@link Type}.
186          */

187         @Override JavaDoc
188         public void visit(final String JavaDoc name, final Object JavaDoc value) {
189             if (name.equals(PROPERTY_NAME)) {
190                 propertyName = (String JavaDoc) value;
191             } else if (name.equals(PROPERTY_VALUE)) {
192                 propertyValue = (String JavaDoc) value;
193             }
194         }
195
196         /**
197          * Visits the end of the annotation. Creates the object and store it
198          */

199         @Override JavaDoc
200         public void visitEnd() {
201             // Add an activation property
202
JActivationConfigProperty jActivationConfigProperty = new JActivationConfigProperty(propertyName,
203                     propertyValue);
204             getJCommonBean().addActivationConfigProperty(jActivationConfigProperty);
205
206         }
207     }
208
209     /**
210      * @return the object representing common bean.
211      */

212     @Override JavaDoc
213     public JMessageDriven getJCommonBean() {
214         JMessageDriven jMessageDriven = getAnnotationMetadata().getJMessageDriven();
215         if (jMessageDriven == null) {
216             jMessageDriven = new JMessageDriven();
217             getAnnotationMetadata().setJMessageDriven(jMessageDriven);
218         }
219         return jMessageDriven;
220     }
221
222 }
223
Popular Tags