1 22 package org.jboss.annotation.factory; 23 24 import java.lang.reflect.Method ; 25 import java.security.AccessController ; 26 import java.security.PrivilegedAction ; 27 import java.util.ArrayList ; 28 import java.util.Map ; 29 30 37 public class SimpleAnnotationValidator implements AnnotationValidator 38 { 39 40 public void validate(Map map, Class annotation) 41 { 42 ArrayList <String > notAssignedAttributes = null; 43 Method [] methods = getDeclaredMethods(annotation); 44 for (int i = 0 ; i < methods.length ; i++) 45 { 46 if (map.get(methods[i].getName()) == null) 47 { 48 if (notAssignedAttributes == null) 49 { 50 notAssignedAttributes = new ArrayList <String >(); 51 } 52 notAssignedAttributes.add(methods[i].getName()); 53 } 54 } 55 56 if (notAssignedAttributes != null) 57 { 58 throw new AnnotationValidationException("Unable to fill in default attributes for " + annotation + " " + notAssignedAttributes); 59 } 60 } 61 62 private Method [] getDeclaredMethods(final Class clazz) 63 { 64 return AccessController.doPrivileged(new PrivilegedAction <Method []>() 65 { 66 public Method [] run() 67 { 68 return clazz.getDeclaredMethods(); 69 }; 70 }); 71 } 72 73 } 74 | Popular Tags |