1. /*
  2. * @(#)InvocationHandler.java 1.7 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.lang.reflect;
  8. /**
  9. * <code>InvocationHandler</code> is the interface implemented by
  10. * the <i>invocation handler</i> of a proxy instance.
  11. *
  12. * <p>Each proxy instance has an associated invocation handler.
  13. * When a method is invoked on a proxy instance, the method
  14. * invocation is encoded and dispatched to the <code>invoke</code>
  15. * method of its invocation handler.
  16. *
  17. * @author Peter Jones
  18. * @version 1.7, 03/01/23
  19. * @see Proxy
  20. * @since JDK1.3
  21. */
  22. public interface InvocationHandler {
  23. /**
  24. * Processes a method invocation on a proxy instance and returns
  25. * the result. This method will be invoked on an invocation handler
  26. * when a method is invoked on a proxy instance that it is
  27. * associated with.
  28. *
  29. * @param proxy the proxy instance that the method was invoked on
  30. *
  31. * @param method the <code>Method</code> instance corresponding to
  32. * the interface method invoked on the proxy instance. The declaring
  33. * class of the <code>Method</code> object will be the interface that
  34. * the method was declared in, which may be a superinterface of the
  35. * proxy interface that the proxy class inherits the method through.
  36. *
  37. * @param args an array of objects containing the values of the
  38. * arguments passed in the method invocation on the proxy instance,
  39. * or <code>null</code> if interface method takes no arguments.
  40. * Arguments of primitive types are wrapped in instances of the
  41. * appropriate primitive wrapper class, such as
  42. * <code>java.lang.Integer</code> or <code>java.lang.Boolean</code>.
  43. *
  44. * @return the value to return from the method invocation on the
  45. * proxy instance. If the declared return type of the interface
  46. * method is a primitive type, then the value returned by
  47. * this method must be an instance of the corresponding primitive
  48. * wrapper class; otherwise, it must be a type assignable to the
  49. * declared return type. If the value returned by this method is
  50. * <code>null</code> and the interface method's return type is
  51. * primitive, then a <code>NullPointerException</code> will be
  52. * thrown by the method invocation on the proxy instance. If the
  53. * value returned by this method is otherwise not compatible with
  54. * the interface method's declared return type as described above,
  55. * a <code>ClassCastException</code> will be thrown by the method
  56. * invocation on the proxy instance.
  57. *
  58. * @throws Throwable the exception to throw from the method
  59. * invocation on the proxy instance. The exception's type must be
  60. * assignable either to any of the exception types declared in the
  61. * <code>throws</code> clause of the interface method or to the
  62. * unchecked exception types <code>java.lang.RuntimeException</code>
  63. * or <code>java.lang.Error</code>. If a checked exception is
  64. * thrown by this method that is not assignable to any of the
  65. * exception types declared in the <code>throws</code> clause of
  66. * the interface method, then an
  67. * {@link UndeclaredThrowableException} containing the
  68. * exception that was thrown by this method will be thrown by the
  69. * method invocation on the proxy instance.
  70. *
  71. * @see UndeclaredThrowableException
  72. */
  73. public Object invoke(Object proxy, Method method, Object[] args)
  74. throws Throwable;
  75. }