1 // ========================================================================
2 // Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
3 // ------------------------------------------------------------------------
4 // All rights reserved. This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v1.0
6 // and Apache License v2.0 which accompanies this distribution.
7 // The Eclipse Public License is available at
8 // http://www.eclipse.org/legal/epl-v10.html
9 // The Apache License v2.0 is available at
10 // http://www.opensource.org/licenses/apache2.0.php
11 // You may elect to redistribute this code under either of these licenses.
12 // ========================================================================
13
14 package org.eclipse.jetty.plus.annotation;
15
16 import java.lang.reflect.Method;
17 import java.lang.reflect.Modifier;
18
19 import org.eclipse.jetty.util.log.Log;
20 import org.eclipse.jetty.util.log.Logger;
21
22 /**
23 * PreDestroyCallback
24 *
25 *
26 */
27 public class PreDestroyCallback extends LifeCycleCallback
28 {
29 private static final Logger LOG = Log.getLogger(PreDestroyCallback.class);
30
31
32 /**
33 * Commons Annotations Specification section 2.6:
34 * - no params to method
35 * - returns void
36 * - no checked exceptions
37 * - not static
38 * @see org.eclipse.jetty.plus.annotation.LifeCycleCallback#validate(java.lang.Class, java.lang.reflect.Method)
39 */
40 public void validate(Class<?> clazz, Method method)
41 {
42
43 if (method.getExceptionTypes().length > 0)
44 throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot not throw a checked exception");
45
46 if (!method.getReturnType().equals(Void.TYPE))
47 throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot not have a return type");
48
49 if (Modifier.isStatic(method.getModifiers()))
50 throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot be static");
51
52 }
53
54
55 public void callback(Object instance)
56 {
57 try
58 {
59 super.callback(instance);
60 }
61 catch (Exception e)
62 {
63 LOG.warn("Ignoring exception thrown on preDestroy call to "+getTargetClass()+"."+getTarget().getName(), e);
64 }
65 }
66
67 public boolean equals(Object o)
68 {
69 if (super.equals(o) && (o instanceof PreDestroyCallback))
70 return true;
71 return false;
72 }
73 }