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: ScanCommonVisitor.java 2059 2007-11-22 17:22:33Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.deployment.annotations.analyzer;
025:
026: import java.util.HashMap;
027: import java.util.Map;
028:
029: import org.ow2.easybeans.asm.AnnotationVisitor;
030: import org.ow2.easybeans.asm.commons.EmptyVisitor;
031: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.ISharedMetadata;
032:
033: /**
034: * This classes analyses annotation (could be class, method, attribute, etc).
035: * It is extended by classes for a specific type Class, Method, Attribute.
036: * @param <T> the kind of metadata visited by this visitor.
037: * @author Florent Benoit
038: */
039: public abstract class ScanCommonVisitor<T extends ISharedMetadata>
040: extends EmptyVisitor {
041:
042: /**
043: * Annotation visitor which do nothing.
044: */
045: private EmptyVisitor emptyVisitor = null;
046:
047: /**
048: * Map of annotation visitors used by this visitor.<br>
049: * The key is the annotation descriptor (asm)
050: */
051: private Map<String, AnnotationVisitor> annotationVisitors = null;
052:
053: /**
054: * Constructor
055: * Build map of visitors.
056: */
057: public ScanCommonVisitor() {
058: annotationVisitors = new HashMap<String, AnnotationVisitor>();
059: }
060:
061: /**
062: * Build visitors used by this one.
063: * @param annotationMetadata metadata used
064: */
065: protected void initVisitors(final T annotationMetadata) {
066: emptyVisitor = new EmptyVisitor();
067:
068: // add @EJB
069: annotationVisitors.put(JavaxEjbEJBVisitor.TYPE,
070: new JavaxEjbEJBVisitor<T>(annotationMetadata));
071:
072: // add @Resource
073: annotationVisitors.put(JavaxAnnotationResourceVisitor.TYPE,
074: new JavaxAnnotationResourceVisitor<T>(
075: annotationMetadata));
076:
077: // add @PersistenceContext
078: annotationVisitors.put(
079: JavaxPersistencePersistenceContextVisitor.TYPE,
080: new JavaxPersistencePersistenceContextVisitor<T>(
081: annotationMetadata));
082:
083: // add @PersistenceUnit
084: annotationVisitors.put(
085: JavaxPersistencePersistenceUnitVisitor.TYPE,
086: new JavaxPersistencePersistenceUnitVisitor<T>(
087: annotationMetadata));
088:
089: }
090:
091: /**
092: * @return empty visitor
093: */
094: protected EmptyVisitor getEmptyVisitor() {
095: return emptyVisitor;
096: }
097:
098: /**
099: * Visits an annotation of the class.
100: * @param desc the class descriptor of the annotation class.
101: * @param visible <tt>true</tt> if the annotation is visible at runtime.
102: * @return a non null visitor to visit the annotation values.
103: */
104: @Override
105: public AnnotationVisitor visitAnnotation(final String desc,
106: final boolean visible) {
107: AnnotationVisitor av = annotationVisitors.get(desc);
108: if (av != null) {
109: return av;
110: }
111: return emptyVisitor;
112: }
113:
114: /**
115: * @return the visitors used by this scanner.
116: */
117: protected Map<String, AnnotationVisitor> getAnnotationVisitors() {
118: return annotationVisitors;
119: }
120:
121: }
|