01: //========================================================================
02: //$Id: PreDestroyCallback.java 1448 2006-12-29 20:46:57Z janb $
03: //Copyright 2006 Mort Bay Consulting Pty. Ltd.
04: //------------------------------------------------------------------------
05: //Licensed under the Apache License, Version 2.0 (the "License");
06: //you may not use this file except in compliance with the License.
07: //You may obtain a copy of the License at
08: //http://www.apache.org/licenses/LICENSE-2.0
09: //Unless required by applicable law or agreed to in writing, software
10: //distributed under the License is distributed on an "AS IS" BASIS,
11: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: //See the License for the specific language governing permissions and
13: //limitations under the License.
14: //========================================================================
15:
16: package org.mortbay.jetty.plus.annotation;
17:
18: import java.lang.reflect.Method;
19: import java.lang.reflect.Modifier;
20:
21: import org.mortbay.log.Log;
22:
23: /**
24: * PreDestroyCallback
25: *
26: *
27: */
28: public class PreDestroyCallback extends LifeCycleCallback {
29:
30: /**
31: * Commons Annotations Specification section 2.6:
32: * - no params to method
33: * - returns void
34: * - no checked exceptions
35: * - not static
36: * @see org.mortbay.jetty.plus.annotation.LifeCycleCallback#validate(java.lang.Class, java.lang.reflect.Method)
37: */
38: public void validate(Class clazz, Method method) {
39:
40: if (method.getExceptionTypes().length > 0)
41: throw new IllegalArgumentException(clazz.getName() + "."
42: + method.getName()
43: + " cannot not throw a checked exception");
44:
45: if (!method.getReturnType().equals(Void.TYPE))
46: throw new IllegalArgumentException(clazz.getName() + "."
47: + method.getName()
48: + " cannot not have a return type");
49:
50: if (Modifier.isStatic(method.getModifiers()))
51: throw new IllegalArgumentException(clazz.getName() + "."
52: + method.getName() + " cannot be static");
53:
54: }
55:
56: public void callback(Object instance) {
57: try {
58: super .callback(instance);
59: } catch (Exception e) {
60: Log.warn("Ignoring exception thrown on preDestroy call to "
61: + getClassName() + "." + getTarget().getName(), e);
62: }
63: }
64: }
|