View Javadoc

1   //========================================================================
2   //$Id: PreDestroyCallback.java 1540 2007-01-19 12:24:10Z janb $
3   //Copyright 2006 Mort Bay Consulting Pty. Ltd.
4   //------------------------------------------------------------------------
5   //Licensed under the Apache License, Version 2.0 (the "License");
6   //you may not use this file except in compliance with the License.
7   //You may obtain a copy of the License at 
8   //http://www.apache.org/licenses/LICENSE-2.0
9   //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      /** 
32       * Commons Annotations Specification section 2.6:
33       * - no params to method
34       * - returns void
35       * - no checked exceptions
36       * - not static
37       * @see org.mortbay.jetty.plus.annotation.LifeCycleCallback#validate(java.lang.Class, java.lang.reflect.Method)
38       */
39      public void validate(Class clazz, Method method)
40      {        
41  
42          if (method.getExceptionTypes().length > 0)
43              throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot not throw a checked exception");
44          
45          if (!method.getReturnType().equals(Void.TYPE))
46              throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot not have a return type");
47          
48          if (Modifier.isStatic(method.getModifiers()))
49              throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot be static");
50          
51      }
52  
53      
54      public void callback(Object instance)
55      {
56          try
57          {
58              super.callback(instance);
59          }
60          catch (Exception e)
61          {
62              Log.warn("Ignoring exception thrown on preDestroy call to "+getTargetClass()+"."+getTarget().getName(), e);
63          }
64      }
65      
66      public boolean equals(Object o)
67      {
68          if (super.equals(o) && (o instanceof PreDestroyCallback))
69              return true;
70          return false;
71      }
72  }