| 1 32 package net.sf.retrotranslator.runtime.impl; 33 34 import java.io.Serializable ; 35 import java.lang.annotation.IncompleteAnnotationException ; 36 import java.lang.reflect.*; 37 import java.util.*; 38 import net.sf.retrotranslator.runtime.java.lang.annotation.Annotation_; 39 40 43 public class AnnotationHandler implements InvocationHandler, Serializable { 44 45 private Class annotationType; 46 private String asString; 47 private Map<String , Object > values = new HashMap<String , Object >(); 48 49 public AnnotationHandler(Class annotationType, String asString, Map<String , Object > values) { 50 this.annotationType = annotationType; 51 this.asString = asString; 52 this.values = values; 53 } 54 55 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable { 56 String name = method.getName(); 57 if (args != null) { 58 if (name.equals("equals") && args.length == 1 && method.getParameterTypes()[0] == Object .class) { 59 return args[0] instanceof Annotation_ && asString.equals(args[0].toString()); 60 } 61 throw new IncompleteAnnotationException (annotationType, name); 62 } 63 if (name.equals("hashCode")) return asString.hashCode(); 64 if (name.equals("toString")) return asString; 65 if (name.equals("annotationType")) return annotationType; 66 Object value = values.get(name); 67 if (value != null) return RuntimeTools.cloneNonEmptyArray(value); 68 throw new IncompleteAnnotationException (annotationType, name); 69 } 70 71 } 72 | Popular Tags |