View Javadoc

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  
21  /**
22   * PreDestroyCallback
23   *
24   *
25   */
26  public class PreDestroyCallback extends LifeCycleCallback
27  {
28  
29      /** 
30       * Commons Annotations Specification section 2.6:
31       * - no params to method
32       * - returns void
33       * - no checked exceptions
34       * - not static
35       * @see org.eclipse.jetty.plus.annotation.LifeCycleCallback#validate(java.lang.Class, java.lang.reflect.Method)
36       */
37      public void validate(Class clazz, Method method)
38      {        
39  
40          if (method.getExceptionTypes().length > 0)
41              throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot not throw a checked exception");
42          
43          if (!method.getReturnType().equals(Void.TYPE))
44              throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot not have a return type");
45          
46          if (Modifier.isStatic(method.getModifiers()))
47              throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot be static");
48          
49      }
50  
51      
52      public void callback(Object instance)
53      {
54          try
55          {
56              super.callback(instance);
57          }
58          catch (Exception e)
59          {
60              Log.warn("Ignoring exception thrown on preDestroy call to "+getTargetClass()+"."+getTarget().getName(), e);
61          }
62      }
63      
64      public boolean equals(Object o)
65      {
66          if (super.equals(o) && (o instanceof PreDestroyCallback))
67              return true;
68          return false;
69      }
70  }