001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ScanMethodVisitor.java 2059 2007-11-22 17:22:33Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.deployment.annotations.analyzer;
025:
026: import org.ow2.easybeans.asm.AnnotationVisitor;
027: import org.ow2.easybeans.asm.MethodVisitor;
028: import org.ow2.easybeans.deployment.annotations.JMethod;
029: import org.ow2.easybeans.deployment.annotations.analyzer.method.JavaxAnnotationPostConstructVisitor;
030: import org.ow2.easybeans.deployment.annotations.analyzer.method.JavaxAnnotationPreDestroyVisitor;
031: import org.ow2.easybeans.deployment.annotations.analyzer.method.JavaxAnnotationSecurityDenyAllVisitor;
032: import org.ow2.easybeans.deployment.annotations.analyzer.method.JavaxEjbInitVisitor;
033: import org.ow2.easybeans.deployment.annotations.analyzer.method.JavaxEjbPostActivateVisitor;
034: import org.ow2.easybeans.deployment.annotations.analyzer.method.JavaxEjbPrePassivateVisitor;
035: import org.ow2.easybeans.deployment.annotations.analyzer.method.JavaxEjbRemoveVisitor;
036: import org.ow2.easybeans.deployment.annotations.analyzer.method.JavaxEjbTimeoutVisitor;
037: import org.ow2.easybeans.deployment.annotations.analyzer.method.JavaxInterceptorAroundInvokeVisitor;
038: import org.ow2.easybeans.deployment.annotations.analyzer.method.JavaxInterceptorExcludeClassInterceptorsVisitor;
039: import org.ow2.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
040: import org.ow2.easybeans.deployment.annotations.metadata.MethodAnnotationMetadata;
041:
042: /**
043: * This classes analyses a given method and build/fill meta data information.
044: * @author Florent Benoit
045: */
046: public class ScanMethodVisitor extends
047: ScanCommonVisitor<MethodAnnotationMetadata> implements
048: MethodVisitor {
049:
050: /**
051: * Class generated by the visitor which correspond to meta data contained in the parsed method.
052: */
053: private MethodAnnotationMetadata methodAnnotationMetadata = null;
054:
055: /**
056: * Parent of method annotation meta data that are built by this visitor.
057: */
058: private ClassAnnotationMetadata classAnnotationMetadata = null;
059:
060: /**
061: * Constructor.
062: * @param jMethod Method object on which we set meta data.
063: * @param classAnnotationMetadata the parent object on which add generated meta-data.
064: */
065: public ScanMethodVisitor(final JMethod jMethod,
066: final ClassAnnotationMetadata classAnnotationMetadata) {
067:
068: // object build and to fill
069: this .methodAnnotationMetadata = new MethodAnnotationMetadata(
070: jMethod, classAnnotationMetadata);
071:
072: // parent
073: this .classAnnotationMetadata = classAnnotationMetadata;
074:
075: initVisitors();
076: }
077:
078: /**
079: * Build visitors used by this one.
080: */
081: private void initVisitors() {
082: super .initVisitors(methodAnnotationMetadata);
083:
084: // add @Init
085: getAnnotationVisitors().put(JavaxEjbInitVisitor.TYPE,
086: new JavaxEjbInitVisitor(methodAnnotationMetadata));
087:
088: // add @Remove
089: getAnnotationVisitors().put(JavaxEjbRemoveVisitor.TYPE,
090: new JavaxEjbRemoveVisitor(methodAnnotationMetadata));
091:
092: // add @TransactionAttribute
093: getAnnotationVisitors()
094: .put(
095: JavaxEjbTransactionAttributeVisitor.TYPE,
096: new JavaxEjbTransactionAttributeVisitor<MethodAnnotationMetadata>(
097: methodAnnotationMetadata));
098:
099: // add @PostConstruct
100: getAnnotationVisitors().put(
101: JavaxAnnotationPostConstructVisitor.TYPE,
102: new JavaxAnnotationPostConstructVisitor(
103: methodAnnotationMetadata));
104: // add @PreDestroy
105: getAnnotationVisitors().put(
106: JavaxAnnotationPreDestroyVisitor.TYPE,
107: new JavaxAnnotationPreDestroyVisitor(
108: methodAnnotationMetadata));
109: // add @PostActivate
110: getAnnotationVisitors().put(
111: JavaxEjbPostActivateVisitor.TYPE,
112: new JavaxEjbPostActivateVisitor(
113: methodAnnotationMetadata));
114: // add @PrePassivate
115: getAnnotationVisitors().put(
116: JavaxEjbPrePassivateVisitor.TYPE,
117: new JavaxEjbPrePassivateVisitor(
118: methodAnnotationMetadata));
119:
120: // add @Timeout
121: getAnnotationVisitors().put(JavaxEjbTimeoutVisitor.TYPE,
122: new JavaxEjbTimeoutVisitor(methodAnnotationMetadata));
123:
124: // add @AroundInvoke
125: getAnnotationVisitors().put(
126: JavaxInterceptorAroundInvokeVisitor.TYPE,
127: new JavaxInterceptorAroundInvokeVisitor(
128: methodAnnotationMetadata));
129:
130: // add @Interceptors
131: getAnnotationVisitors()
132: .put(
133: JavaxInterceptorInterceptorsVisitor.TYPE,
134: new JavaxInterceptorInterceptorsVisitor<MethodAnnotationMetadata>(
135: methodAnnotationMetadata));
136:
137: // add @ExcludeClassInterceptors
138: getAnnotationVisitors().put(
139: JavaxInterceptorExcludeClassInterceptorsVisitor.TYPE,
140: new JavaxInterceptorExcludeClassInterceptorsVisitor(
141: methodAnnotationMetadata));
142:
143: // add @RolesAllowed
144: getAnnotationVisitors()
145: .put(
146: JavaxAnnotationSecurityRolesAllowedVisitor.TYPE,
147: new JavaxAnnotationSecurityRolesAllowedVisitor<MethodAnnotationMetadata>(
148: methodAnnotationMetadata));
149:
150: // add @PermitAll
151: getAnnotationVisitors()
152: .put(
153: JavaxAnnotationSecurityPermitAllVisitor.TYPE,
154: new JavaxAnnotationSecurityPermitAllVisitor<MethodAnnotationMetadata>(
155: methodAnnotationMetadata));
156:
157: // add @DenyAll
158: getAnnotationVisitors().put(
159: JavaxAnnotationSecurityDenyAllVisitor.TYPE,
160: new JavaxAnnotationSecurityDenyAllVisitor(
161: methodAnnotationMetadata));
162:
163: // add @ExcludeDefaultInterceptors
164: getAnnotationVisitors()
165: .put(
166: JavaxInterceptorExcludeDefaultInterceptorsVisitor.TYPE,
167: new JavaxInterceptorExcludeDefaultInterceptorsVisitor<MethodAnnotationMetadata>(
168: methodAnnotationMetadata));
169:
170: }
171:
172: /**
173: * Visits the default value of this annotation interface method (ignore it).
174: *
175: * @return a non null visitor to the visit the actual default value of this
176: * annotation interface method. The 'name' parameters passed to the
177: * methods of this annotation visitor are ignored. Moreover, exacly
178: * one visit method must be called on this annotation visitor,
179: * followed by visitEnd.
180: */
181: @Override
182: public AnnotationVisitor visitAnnotationDefault() {
183: return getEmptyVisitor();
184: }
185:
186: /**
187: * Visits an annotation of a parameter this method (ignore it).
188: *
189: * @param parameter the parameter index.
190: * @param desc the class descriptor of the annotation class.
191: * @param visible <tt>true</tt> if the annotation is visible at runtime.
192: * @return a non null visitor to visit the annotation values.
193: */
194: @Override
195: public AnnotationVisitor visitParameterAnnotation(
196: final int parameter, final String desc,
197: final boolean visible) {
198: return getEmptyVisitor();
199: }
200:
201: /**
202: * Visits the end of the method. This method, which is the last one to be
203: * called, is used to inform the visitor that all the annotations and
204: * attributes of the method have been visited.
205: */
206: @Override
207: public void visitEnd() {
208: classAnnotationMetadata
209: .addMethodAnnotationMetadata(methodAnnotationMetadata);
210: }
211:
212: }
|