1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.annotations;
15
16 import java.util.List;
17
18 import org.eclipse.jetty.annotations.AnnotationParser.AnnotationHandler;
19 import org.eclipse.jetty.annotations.AnnotationParser.Value;
20 import org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection;
21 import org.eclipse.jetty.plus.annotation.PostConstructCallback;
22 import org.eclipse.jetty.util.log.Log;
23 import org.eclipse.jetty.webapp.WebAppContext;
24
25 public class PostConstructAnnotationHandler implements AnnotationHandler
26 {
27 protected WebAppContext _wac;
28 protected LifeCycleCallbackCollection _callbacks;
29
30 public PostConstructAnnotationHandler (WebAppContext wac)
31 {
32 _wac = wac;
33 _callbacks = (LifeCycleCallbackCollection)_wac.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
34 }
35
36
37 public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation,
38 List<Value> values)
39 {
40 Log.warn ("@PostConstruct annotation not applicable to classes: "+className);
41 }
42
43 public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
44 List<Value> values)
45 {
46 Log.warn("@PostConstruct annotation not applicable to fields: "+className+"."+fieldName);
47 }
48
49 public void handleMethod(String className, String methodName, int access, String desc, String signature, String[] exceptions, String annotation,
50 List<Value> values)
51 {
52 try
53 {
54 org.objectweb.asm.Type[] args = org.objectweb.asm.Type.getArgumentTypes(desc);
55
56 if (args.length != 0)
57 {
58 Log.warn("Skipping PostConstruct annotation on "+className+"."+methodName+": has parameters");
59 return;
60 }
61 if (org.objectweb.asm.Type.getReturnType(desc) != org.objectweb.asm.Type.VOID_TYPE)
62 {
63 Log.warn("Skipping PostConstruct annotation on "+className+"."+methodName+": is not void");
64 return;
65 }
66
67 if (exceptions != null && exceptions.length != 0)
68 {
69 Log.warn("Skipping PostConstruct annotation on "+className+"."+methodName+": throws checked exceptions");
70 return;
71 }
72
73 if ((access & org.objectweb.asm.Opcodes.ACC_STATIC) > 0)
74 {
75 Log.warn("Skipping PostConstruct annotation on "+className+"."+methodName+": is static");
76 return;
77 }
78
79 PostConstructCallback callback = new PostConstructCallback();
80 callback.setTarget(className, methodName);
81 _callbacks.add(callback);
82 }
83 catch (Exception e)
84 {
85 Log.warn(e);
86 }
87 }
88
89 }