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.PreDestroyCallback;
22 import org.eclipse.jetty.util.log.Log;
23 import org.eclipse.jetty.webapp.WebAppContext;
24
25 public class PreDestroyAnnotationHandler implements AnnotationHandler
26 {
27 WebAppContext _wac;
28 LifeCycleCallbackCollection _callbacks;
29
30 public PreDestroyAnnotationHandler (WebAppContext wac)
31 {
32 _wac = wac;
33 _callbacks = (LifeCycleCallbackCollection)_wac.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
34 }
35
36 public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation,
37 List<Value> values)
38 {
39 Log.warn("@PreDestroy annotation not applicable for classes: "+className);
40 }
41
42 public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
43 List<Value> values)
44 {
45 Log.warn("@PreDestroy annotation not applicable for fields: "+className+"."+fieldName);
46 }
47
48 public void handleMethod(String className, String methodName, int access, String desc, String signature, String[] exceptions, String annotation,
49 List<Value> values)
50 {
51 try
52 {
53 org.objectweb.asm.Type[] args = org.objectweb.asm.Type.getArgumentTypes(desc);
54
55 if (args.length != 0)
56 {
57 Log.warn("Skipping PreDestroy annotation on "+className+"."+methodName+": has parameters");
58 return;
59 }
60 if (org.objectweb.asm.Type.getReturnType(desc) != org.objectweb.asm.Type.VOID_TYPE)
61 {
62 Log.warn("Skipping PreDestroy annotation on "+className+"."+methodName+": is not void");
63 return;
64 }
65
66 if (exceptions != null && exceptions.length != 0)
67 {
68 Log.warn("Skipping PreDestroy annotation on "+className+"."+methodName+": throws checked exceptions");
69 return;
70 }
71
72 if ((access & org.objectweb.asm.Opcodes.ACC_STATIC) > 0)
73 {
74 Log.warn("Skipping PreDestroy annotation on "+className+"."+methodName+": is static");
75 return;
76 }
77
78 PreDestroyCallback callback = new PreDestroyCallback();
79 callback.setTarget(className, methodName);
80 _callbacks.add(callback);
81 }
82 catch (Exception e)
83 {
84 Log.warn(e);
85 }
86 }
87 }