1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.annotations;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24
25
26
27
28
29 public class AnnotationIntrospector
30 {
31 protected List<IntrospectableAnnotationHandler> _handlers = new ArrayList<IntrospectableAnnotationHandler>();
32
33
34
35
36
37
38
39 public interface IntrospectableAnnotationHandler
40 {
41 public void handle(Class<?> clazz);
42 }
43
44
45
46
47
48
49
50
51
52 public static abstract class AbstractIntrospectableAnnotationHandler implements IntrospectableAnnotationHandler
53 {
54 private boolean _introspectAncestors;
55
56 public abstract void doHandle(Class<?> clazz);
57
58
59 public AbstractIntrospectableAnnotationHandler(boolean introspectAncestors)
60 {
61 _introspectAncestors = introspectAncestors;
62 }
63
64 public void handle(Class<?> clazz)
65 {
66 Class<?> c = clazz;
67
68
69 while (c!=null && (!c.equals(Object.class)))
70 {
71 doHandle(c);
72 if (!_introspectAncestors)
73 break;
74
75 c = c.getSuperclass();
76 }
77 }
78 }
79
80 public void registerHandler (IntrospectableAnnotationHandler handler)
81 {
82 _handlers.add(handler);
83 }
84
85 public void introspect (Class<?> clazz)
86 {
87 if (_handlers == null)
88 return;
89 if (clazz == null)
90 return;
91
92 for (IntrospectableAnnotationHandler handler:_handlers)
93 {
94 try
95 {
96 handler.handle(clazz);
97 }
98 catch (RuntimeException e)
99 {
100 throw e;
101 }
102 catch (Exception e)
103 {
104 throw new RuntimeException(e);
105 }
106 }
107
108 }
109 }