001: package com.bm.ejb3metadata.annotations.analyzer;
002:
003: import java.util.HashMap;
004: import java.util.Map;
005:
006: import org.ejb3unit.asm.AnnotationVisitor;
007: import org.ejb3unit.asm.commons.EmptyVisitor;
008:
009: import com.bm.ejb3metadata.annotations.metadata.interfaces.ISharedMetadata;
010:
011: /**
012: * This classes analyses annotation (could be class, method, attribute, etc). It
013: * is extended by classes for a specific type Class, Method, Attribute.
014: *
015: * @param <T>
016: * the kind of metadata visited by this visitor.
017: * @author Daniel Wiese
018: */
019: public abstract class ScanCommonVisitor<T extends ISharedMetadata>
020: extends EmptyVisitor {
021:
022: /**
023: * Annotation visitor which do nothing.
024: */
025: private EmptyVisitor emptyVisitor = null;
026:
027: /**
028: * Map of annotation visitors used by this visitor.<br>
029: * The key is the annotation descriptor (asm)
030: */
031: private Map<String, AnnotationVisitor> annotationVisitors = null;
032:
033: /**
034: * Constructor Build map of visitors.
035: */
036: public ScanCommonVisitor() {
037: annotationVisitors = new HashMap<String, AnnotationVisitor>();
038: }
039:
040: /**
041: * Build visitors used by this one.
042: *
043: * @param annotationMetadata
044: * metadata used
045: */
046: protected void initVisitors(final T annotationMetadata) {
047: emptyVisitor = new EmptyVisitor();
048:
049: // add @EJB
050: annotationVisitors.put(JavaxEjbEJBVisitor.TYPE,
051: new JavaxEjbEJBVisitor<T>(annotationMetadata));
052:
053: // add @Resource
054: annotationVisitors.put(JavaxAnnotationResourceVisitor.TYPE,
055: new JavaxAnnotationResourceVisitor<T>(
056: annotationMetadata));
057:
058: // add @PersistenceContext
059: annotationVisitors.put(
060: JavaxPersistencePersistenceContextVisitor.TYPE,
061: new JavaxPersistencePersistenceContextVisitor<T>(
062: annotationMetadata));
063:
064: // add @PersistenceUnit
065: annotationVisitors.put(
066: JavaxPersistencePersistenceUnitVisitor.TYPE,
067: new JavaxPersistencePersistenceUnitVisitor<T>(
068: annotationMetadata));
069:
070: }
071:
072: /**
073: * @return empty visitor
074: */
075: protected EmptyVisitor getEmptyVisitor() {
076: return emptyVisitor;
077: }
078:
079: /**
080: * Visits an annotation of the class.
081: *
082: * @param desc
083: * the class descriptor of the annotation class.
084: * @param visible
085: * <tt>true</tt> if the annotation is visible at runtime.
086: * @return a non null visitor to visit the annotation values.
087: */
088: @Override
089: public AnnotationVisitor visitAnnotation(final String desc,
090: final boolean visible) {
091: AnnotationVisitor av = annotationVisitors.get(desc);
092: if (av != null) {
093: return av;
094: }
095: return emptyVisitor;
096: }
097:
098: /**
099: * @return the visitors used by this scanner.
100: */
101: protected Map<String, AnnotationVisitor> getAnnotationVisitors() {
102: return annotationVisitors;
103: }
104:
105: }
|