1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.contract.model.util;
17
18 import javax.xml.bind.annotation.XmlEnum;
19
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import com.thoughtworks.qdox.model.Annotation;
24 import com.thoughtworks.qdox.model.JavaClass;
25 import com.thoughtworks.qdox.model.annotation.AnnotationValue;
26
27
28
29
30
31
32
33 public final class JavaClassAnnotationUtils {
34
35 private static final Logger log = LoggerFactory.getLogger(JavaClassAnnotationUtils.class);
36
37
38
39 private JavaClassAnnotationUtils() {
40
41 }
42
43 public static boolean doesAnnotationExist(String simpleAnnotationName, JavaClass javaClass) {
44
45 Annotation[] as = javaClass.getAnnotations();
46
47 for (Annotation annotation : as) {
48 if (annotation.getType().getJavaClass().getName().equals(simpleAnnotationName))
49 return true;
50 }
51
52 return false;
53
54 }
55
56
57
58
59
60
61
62
63
64
65 public static Class<?>extractXmlEnumValue (JavaClass javaClass) {
66
67 Annotation[] as = javaClass.getAnnotations();
68
69 for (Annotation annotation : as) {
70 if (annotation.getType().getJavaClass().getName().equals(XmlEnum.class.getSimpleName())) {
71
72 AnnotationValue value = annotation.getProperty("value");
73
74 if (value == null) {
75
76
77
78 return String.class;
79 }
80
81
82 String clazz = (String) value.getParameterValue();
83
84 String className = clazz.replaceFirst("\\.class", "");
85
86 try {
87 return ClassLoader.getSystemClassLoader().loadClass(className);
88 } catch (ClassNotFoundException e) {
89 log.error("No class found for name: " + className);
90
91 return null;
92 }
93
94 }
95 }
96
97
98 return null;
99 }
100 }