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