KickJava   Java API By Example, From Geeks To Geeks.

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


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: ScanCommonVisitor.java 377 2006-04-21 08:22:46Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations.analyzer;
27
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import org.objectweb.asm.AnnotationVisitor;
32 import org.objectweb.asm.commons.EmptyVisitor;
33 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.ISharedMetadata;
34
35 /**
36  * This classes analyses annotation (could be class, method, attribute, etc).
37  * It is extended by classes for a specific type Class, Method, Attribute.
38  * @param <T> the kind of metadata visited by this visitor.
39  * @author Florent Benoit
40  */

41 public abstract class ScanCommonVisitor<T extends ISharedMetadata> extends EmptyVisitor {
42
43     /**
44      * Annotation visitor which do nothing.
45      */

46     private EmptyVisitor emptyVisitor = null;
47
48     /**
49      * Map of annotation visitors used by this visitor.<br>
50      * The key is the annotation descriptor (asm)
51      */

52     private Map JavaDoc<String JavaDoc, AnnotationVisitor> annotationVisitors = null;
53
54     /**
55      * Constructor
56      * Build map of visitors.
57      */

58     public ScanCommonVisitor() {
59         annotationVisitors = new HashMap JavaDoc<String JavaDoc, AnnotationVisitor>();
60     }
61
62     /**
63      * Build visitors used by this one.
64      * @param annotationMetadata metadata used
65      */

66     protected void initVisitors(final T annotationMetadata) {
67         emptyVisitor = new EmptyVisitor();
68
69         // add @EJB
70
annotationVisitors.put(JavaxEjbEJBVisitor.TYPE,
71                 new JavaxEjbEJBVisitor<T>(annotationMetadata));
72
73         // add @Resource
74
annotationVisitors.put(JavaxAnnotationResourceVisitor.TYPE,
75                 new JavaxAnnotationResourceVisitor<T>(annotationMetadata));
76
77
78         // add @PersistenceContext
79
annotationVisitors.put(JavaxPersistencePersistenceContextVisitor.TYPE,
80                 new JavaxPersistencePersistenceContextVisitor<T>(annotationMetadata));
81
82         // add @PersistenceUnit
83
annotationVisitors.put(JavaxPersistencePersistenceUnitVisitor.TYPE,
84                 new JavaxPersistencePersistenceUnitVisitor<T>(annotationMetadata));
85
86     }
87
88
89     /**
90      * @return empty visitor
91      */

92     protected EmptyVisitor getEmptyVisitor() {
93         return emptyVisitor;
94     }
95
96     /**
97      * Visits an annotation of the class.
98      * @param desc the class descriptor of the annotation class.
99      * @param visible <tt>true</tt> if the annotation is visible at runtime.
100      * @return a non null visitor to visit the annotation values.
101      */

102     @Override JavaDoc
103     public AnnotationVisitor visitAnnotation(final String JavaDoc desc, final boolean visible) {
104         AnnotationVisitor av = annotationVisitors.get(desc);
105         if (av != null) {
106             return av;
107         }
108         return emptyVisitor;
109     }
110
111     /**
112      * @return the visitors used by this scanner.
113      */

114     protected Map JavaDoc<String JavaDoc, AnnotationVisitor> getAnnotationVisitors() {
115         return annotationVisitors;
116     }
117
118
119 }
120
Popular Tags