1 22 package org.jboss.reflect.plugins.javassist; 23 24 import java.util.HashMap ; 25 26 import org.jboss.reflect.plugins.AnnotationHelper; 27 import org.jboss.reflect.spi.AnnotatedInfo; 28 import org.jboss.reflect.spi.AnnotationInfo; 29 import org.jboss.reflect.spi.AnnotationValue; 30 import org.jboss.util.JBossObject; 31 32 38 public abstract class JavassistAnnotatedInfo extends JBossObject implements AnnotatedInfo 39 { 40 final static AnnotationValue[] NOT_CONFIGURED = new AnnotationValue[0]; 41 42 43 protected AnnotationValue[] annotationsArray = NOT_CONFIGURED; 44 45 46 protected HashMap <String , AnnotationValue> annotationMap; 47 48 protected AnnotationHelper annotationHelper; 49 50 public JavassistAnnotatedInfo(AnnotationHelper annotationHelper) 51 { 52 this.annotationHelper = annotationHelper; 53 } 54 55 protected AnnotationValue[] getAnnotations(Object obj) 56 { 57 synchronized (this) 58 { 59 if (annotationsArray == NOT_CONFIGURED) 60 { 61 annotationsArray = null; 62 setupAnnotations(annotationHelper.getAnnotations(obj)); 63 } 64 } 65 return annotationsArray; 66 } 67 68 public AnnotationValue getAnnotation(String name) 69 { 70 getAnnotations(); 71 return annotationMap.get(name); 72 } 73 74 public boolean isAnnotationPresent(String name) 75 { 76 getAnnotations(); 77 return annotationMap.containsKey(name); 78 } 79 80 85 protected void setupAnnotations(AnnotationValue[] annotations) 86 { 87 if (annotations != null && annotations.length > 0) 88 { 89 this.annotationsArray = annotations; 90 annotationMap = new HashMap <String , AnnotationValue>(); 91 for (int i = 0; i < annotations.length; i++) 92 { 93 AnnotationInfo type = annotations[i].getAnnotationType(); 94 annotationMap.put(type.getName(), annotations[i]); 95 } 96 } 97 } 98 99 } 100 | Popular Tags |