KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > deployment > annotations > analyzer > ScanMethodVisitor


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: ScanMethodVisitor.java 1121 2006-09-27 08:51:06Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations.analyzer;
27
28 import org.objectweb.asm.AnnotationVisitor;
29 import org.objectweb.asm.MethodVisitor;
30 import org.objectweb.easybeans.deployment.annotations.JMethod;
31 import org.objectweb.easybeans.deployment.annotations.analyzer.method.JavaxAnnotationPostConstructVisitor;
32 import org.objectweb.easybeans.deployment.annotations.analyzer.method.JavaxAnnotationPreDestroyVisitor;
33 import org.objectweb.easybeans.deployment.annotations.analyzer.method.JavaxAnnotationSecurityDenyAllVisitor;
34 import org.objectweb.easybeans.deployment.annotations.analyzer.method.JavaxEjbInitVisitor;
35 import org.objectweb.easybeans.deployment.annotations.analyzer.method.JavaxEjbPostActivateVisitor;
36 import org.objectweb.easybeans.deployment.annotations.analyzer.method.JavaxEjbPrePassivateVisitor;
37 import org.objectweb.easybeans.deployment.annotations.analyzer.method.JavaxEjbRemoveVisitor;
38 import org.objectweb.easybeans.deployment.annotations.analyzer.method.JavaxEjbTimeoutVisitor;
39 import org.objectweb.easybeans.deployment.annotations.analyzer.method.JavaxInterceptorAroundInvokeVisitor;
40 import org.objectweb.easybeans.deployment.annotations.analyzer.method.JavaxInterceptorExcludeClassInterceptorsVisitor;
41 import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
42 import org.objectweb.easybeans.deployment.annotations.metadata.MethodAnnotationMetadata;
43
44 /**
45  * This classes analyses a given method and build/fill meta data information.
46  * @author Florent Benoit
47  */

48 public class ScanMethodVisitor extends ScanCommonVisitor<MethodAnnotationMetadata> implements MethodVisitor {
49
50     /**
51      * Class generated by the visitor which correspond to meta data contained in the parsed method.
52      */

53     private MethodAnnotationMetadata methodAnnotationMetadata = null;
54
55
56     /**
57      * Parent of method annotation meta data that are built by this visitor.
58      */

59     private ClassAnnotationMetadata classAnnotationMetadata = null;
60
61     /**
62      * Constructor.
63      * @param jMethod Method object on which we set meta data.
64      * @param classAnnotationMetadata the parent object on which add generated meta-data.
65      */

66     public ScanMethodVisitor(final JMethod jMethod, final ClassAnnotationMetadata classAnnotationMetadata) {
67
68         // object build and to fill
69
this.methodAnnotationMetadata = new MethodAnnotationMetadata(jMethod, classAnnotationMetadata);
70
71         // parent
72
this.classAnnotationMetadata = classAnnotationMetadata;
73
74         initVisitors();
75     }
76
77     /**
78      * Build visitors used by this one.
79      */

80     private void initVisitors() {
81         super.initVisitors(methodAnnotationMetadata);
82
83         // add @Init
84
getAnnotationVisitors().put(JavaxEjbInitVisitor.TYPE, new JavaxEjbInitVisitor(methodAnnotationMetadata));
85
86         // add @Remove
87
getAnnotationVisitors().put(JavaxEjbRemoveVisitor.TYPE, new JavaxEjbRemoveVisitor(methodAnnotationMetadata));
88
89         // add @TransactionAttribute
90
getAnnotationVisitors().put(JavaxEjbTransactionAttributeVisitor.TYPE,
91                 new JavaxEjbTransactionAttributeVisitor<MethodAnnotationMetadata>(methodAnnotationMetadata));
92
93         // add @PostConstruct
94
getAnnotationVisitors().put(JavaxAnnotationPostConstructVisitor.TYPE,
95                 new JavaxAnnotationPostConstructVisitor(methodAnnotationMetadata));
96         // add @PreDestroy
97
getAnnotationVisitors().put(JavaxAnnotationPreDestroyVisitor.TYPE,
98                 new JavaxAnnotationPreDestroyVisitor(methodAnnotationMetadata));
99         // add @PostActivate
100
getAnnotationVisitors().put(JavaxEjbPostActivateVisitor.TYPE, new JavaxEjbPostActivateVisitor(methodAnnotationMetadata));
101         // add @PrePassivate
102
getAnnotationVisitors().put(JavaxEjbPrePassivateVisitor.TYPE, new JavaxEjbPrePassivateVisitor(methodAnnotationMetadata));
103
104         // add @Timeout
105
getAnnotationVisitors().put(JavaxEjbTimeoutVisitor.TYPE, new JavaxEjbTimeoutVisitor(methodAnnotationMetadata));
106
107         // add @AroundInvoke
108
getAnnotationVisitors().put(JavaxInterceptorAroundInvokeVisitor.TYPE,
109                 new JavaxInterceptorAroundInvokeVisitor(methodAnnotationMetadata));
110
111         // add @Interceptors
112
getAnnotationVisitors().put(JavaxInterceptorInterceptorsVisitor.TYPE,
113                 new JavaxInterceptorInterceptorsVisitor<MethodAnnotationMetadata>(methodAnnotationMetadata));
114
115         // add @ExcludeClassInterceptors
116
getAnnotationVisitors().put(JavaxInterceptorExcludeClassInterceptorsVisitor.TYPE,
117                 new JavaxInterceptorExcludeClassInterceptorsVisitor(methodAnnotationMetadata));
118
119         // add @RolesAllowed
120
getAnnotationVisitors().put(JavaxAnnotationSecurityRolesAllowedVisitor.TYPE,
121                 new JavaxAnnotationSecurityRolesAllowedVisitor<MethodAnnotationMetadata>(methodAnnotationMetadata));
122
123         // add @PermitAll
124
getAnnotationVisitors().put(JavaxAnnotationSecurityPermitAllVisitor.TYPE,
125                 new JavaxAnnotationSecurityPermitAllVisitor<MethodAnnotationMetadata>(methodAnnotationMetadata));
126
127         // add @DenyAll
128
getAnnotationVisitors().put(JavaxAnnotationSecurityDenyAllVisitor.TYPE,
129                 new JavaxAnnotationSecurityDenyAllVisitor(methodAnnotationMetadata));
130
131     }
132
133     /**
134      * Visits the default value of this annotation interface method (ignore it).
135      *
136      * @return a non null visitor to the visit the actual default value of this
137      * annotation interface method. The 'name' parameters passed to the
138      * methods of this annotation visitor are ignored. Moreover, exacly
139      * one visit method must be called on this annotation visitor,
140      * followed by visitEnd.
141      */

142     @Override JavaDoc
143     public AnnotationVisitor visitAnnotationDefault() {
144         return getEmptyVisitor();
145     }
146
147
148     /**
149      * Visits an annotation of a parameter this method (ignore it).
150      *
151      * @param parameter the parameter index.
152      * @param desc the class descriptor of the annotation class.
153      * @param visible <tt>true</tt> if the annotation is visible at runtime.
154      * @return a non null visitor to visit the annotation values.
155      */

156     @Override JavaDoc
157     public AnnotationVisitor visitParameterAnnotation(final int parameter, final String JavaDoc desc, final boolean visible) {
158         return getEmptyVisitor();
159     }
160
161     /**
162      * Visits the end of the method. This method, which is the last one to be
163      * called, is used to inform the visitor that all the annotations and
164      * attributes of the method have been visited.
165      */

166     @Override JavaDoc
167     public void visitEnd() {
168         classAnnotationMetadata.addMethodAnnotationMetadata(methodAnnotationMetadata);
169     }
170
171
172
173 }
174
Popular Tags