001: package com.bm.ejb3metadata.annotations.analyzer;
002:
003: import org.ejb3unit.asm.AnnotationVisitor;
004: import org.ejb3unit.asm.MethodVisitor;
005:
006: import com.bm.ejb3metadata.annotations.JMethod;
007: import com.bm.ejb3metadata.annotations.analyzer.method.JavaxAnnotationPostConstructVisitor;
008: import com.bm.ejb3metadata.annotations.analyzer.method.JavaxAnnotationPreDestroyVisitor;
009: import com.bm.ejb3metadata.annotations.analyzer.method.JavaxEjbInitVisitor;
010: import com.bm.ejb3metadata.annotations.analyzer.method.JavaxEjbPostActivateVisitor;
011: import com.bm.ejb3metadata.annotations.analyzer.method.JavaxEjbPrePassivateVisitor;
012: import com.bm.ejb3metadata.annotations.analyzer.method.JavaxEjbRemoveVisitor;
013: import com.bm.ejb3metadata.annotations.analyzer.method.JavaxEjbTimeoutVisitor;
014: import com.bm.ejb3metadata.annotations.analyzer.method.JavaxInterceptorAroundInvokeVisitor;
015: import com.bm.ejb3metadata.annotations.analyzer.method.JavaxInterceptorExcludeClassInterceptorsVisitor;
016: import com.bm.ejb3metadata.annotations.metadata.ClassAnnotationMetadata;
017: import com.bm.ejb3metadata.annotations.metadata.MethodAnnotationMetadata;
018:
019: /**
020: * This classes analyses a given method and build/fill meta data information.
021: *
022: * @author Daniel Wiese
023: */
024: public class ScanMethodVisitor extends
025: ScanCommonVisitor<MethodAnnotationMetadata> implements
026: MethodVisitor {
027:
028: /**
029: * Class generated by the visitor which correspond to meta data contained in
030: * the parsed method.
031: */
032: private MethodAnnotationMetadata methodAnnotationMetadata = null;
033:
034: /**
035: * Parent of method annotation meta data that are built by this visitor.
036: */
037: private ClassAnnotationMetadata classAnnotationMetadata = null;
038:
039: /**
040: * Constructor.
041: *
042: * @param jMethod
043: * Method object on which we set meta data.
044: * @param classAnnotationMetadata
045: * the parent object on which add generated meta-data.
046: */
047: public ScanMethodVisitor(final JMethod jMethod,
048: final ClassAnnotationMetadata classAnnotationMetadata) {
049:
050: // object build and to fill
051: this .methodAnnotationMetadata = new MethodAnnotationMetadata(
052: jMethod, classAnnotationMetadata);
053:
054: // parent
055: this .classAnnotationMetadata = classAnnotationMetadata;
056:
057: initVisitors();
058: }
059:
060: /**
061: * Build visitors used by this one.
062: */
063: private void initVisitors() {
064: super .initVisitors(methodAnnotationMetadata);
065:
066: // add @Init
067: getAnnotationVisitors().put(JavaxEjbInitVisitor.TYPE,
068: new JavaxEjbInitVisitor(methodAnnotationMetadata));
069:
070: // add @Remove
071: getAnnotationVisitors().put(JavaxEjbRemoveVisitor.TYPE,
072: new JavaxEjbRemoveVisitor(methodAnnotationMetadata));
073:
074: // add @TransactionAttribute
075: getAnnotationVisitors()
076: .put(
077: JavaxEjbTransactionAttributeVisitor.TYPE,
078: new JavaxEjbTransactionAttributeVisitor<MethodAnnotationMetadata>(
079: methodAnnotationMetadata));
080:
081: // add @PostConstruct
082: getAnnotationVisitors().put(
083: JavaxAnnotationPostConstructVisitor.TYPE,
084: new JavaxAnnotationPostConstructVisitor(
085: methodAnnotationMetadata));
086: // add @PreDestroy
087: getAnnotationVisitors().put(
088: JavaxAnnotationPreDestroyVisitor.TYPE,
089: new JavaxAnnotationPreDestroyVisitor(
090: methodAnnotationMetadata));
091: // add @PostActivate
092: getAnnotationVisitors().put(
093: JavaxEjbPostActivateVisitor.TYPE,
094: new JavaxEjbPostActivateVisitor(
095: methodAnnotationMetadata));
096: // add @PrePassivate
097: getAnnotationVisitors().put(
098: JavaxEjbPrePassivateVisitor.TYPE,
099: new JavaxEjbPrePassivateVisitor(
100: methodAnnotationMetadata));
101:
102: // add @Timeout
103: getAnnotationVisitors().put(JavaxEjbTimeoutVisitor.TYPE,
104: new JavaxEjbTimeoutVisitor(methodAnnotationMetadata));
105:
106: // add @AroundInvoke
107: getAnnotationVisitors().put(
108: JavaxInterceptorAroundInvokeVisitor.TYPE,
109: new JavaxInterceptorAroundInvokeVisitor(
110: methodAnnotationMetadata));
111:
112: // add @Interceptors
113: getAnnotationVisitors()
114: .put(
115: JavaxInterceptorInterceptorsVisitor.TYPE,
116: new JavaxInterceptorInterceptorsVisitor<MethodAnnotationMetadata>(
117: methodAnnotationMetadata));
118:
119: // add @ExcludeClassInterceptors
120: getAnnotationVisitors().put(
121: JavaxInterceptorExcludeClassInterceptorsVisitor.TYPE,
122: new JavaxInterceptorExcludeClassInterceptorsVisitor(
123: methodAnnotationMetadata));
124:
125: }
126:
127: /**
128: * Visits the default value of this annotation interface method (ignore it).
129: *
130: * @return a non null visitor to the visit the actual default value of this
131: * annotation interface method. The 'name' parameters passed to the
132: * methods of this annotation visitor are ignored. Moreover, exacly
133: * one visit method must be called on this annotation visitor,
134: * followed by visitEnd.
135: */
136: @Override
137: public AnnotationVisitor visitAnnotationDefault() {
138: return getEmptyVisitor();
139: }
140:
141: /**
142: * Visits an annotation of a parameter this method (ignore it).
143: *
144: * @param parameter
145: * the parameter index.
146: * @param desc
147: * the class descriptor of the annotation class.
148: * @param visible
149: * <tt>true</tt> if the annotation is visible at runtime.
150: * @return a non null visitor to visit the annotation values.
151: */
152: @Override
153: public AnnotationVisitor visitParameterAnnotation(
154: final int parameter, final String desc,
155: final boolean visible) {
156: return getEmptyVisitor();
157: }
158:
159: /**
160: * Visits the end of the method. This method, which is the last one to be
161: * called, is used to inform the visitor that all the annotations and
162: * attributes of the method have been visited.
163: */
164: @Override
165: public void visitEnd() {
166: classAnnotationMetadata
167: .addMethodAnnotationMetadata(methodAnnotationMetadata);
168: }
169:
170: }
|