151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/*
251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is free software; you can redistribute it and/or modify it
651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * under the terms of the GNU General Public License version 2 only, as
751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * published by the Free Software Foundation.  Oracle designates this
851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * particular file as subject to the "Classpath" exception as provided
951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * by Oracle in the LICENSE file that accompanied this code.
1051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
1151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is distributed in the hope that it will be useful, but WITHOUT
1251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * version 2 for more details (a copy is included in the LICENSE file that
1551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * accompanied this code).
1651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
1751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * You should have received a copy of the GNU General Public License version
1851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2 along with this work; if not, write to the Free Software Foundation,
1951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
2151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * or visit www.oracle.com if you need additional information or have any
2351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * questions.
2451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */
2551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
2651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipackage java.lang.reflect;
2751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
2851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/**
2951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code InvocationHandler} is the interface implemented by
3051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * the <i>invocation handler</i> of a proxy instance.
3151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
3251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>Each proxy instance has an associated invocation handler.
3351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * When a method is invoked on a proxy instance, the method
3451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * invocation is encoded and dispatched to the {@code invoke}
3551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * method of its invocation handler.
3651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
3751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @author      Peter Jones
3851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see         Proxy
3951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since       1.3
4051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */
4151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipublic interface InvocationHandler {
4251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
4351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
4451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Processes a method invocation on a proxy instance and returns
4551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the result.  This method will be invoked on an invocation handler
4651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * when a method is invoked on a proxy instance that it is
4751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * associated with.
4851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
4951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   proxy the proxy instance that the method was invoked on
5051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
5151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   method the {@code Method} instance corresponding to
5251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the interface method invoked on the proxy instance.  The declaring
5351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * class of the {@code Method} object will be the interface that
5451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the method was declared in, which may be a superinterface of the
5551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * proxy interface that the proxy class inherits the method through.
5651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
5751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   args an array of objects containing the values of the
5851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * arguments passed in the method invocation on the proxy instance,
5951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * or {@code null} if interface method takes no arguments.
6051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Arguments of primitive types are wrapped in instances of the
6151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * appropriate primitive wrapper class, such as
6251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code java.lang.Integer} or {@code java.lang.Boolean}.
6351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
6451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the value to return from the method invocation on the
6551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * proxy instance.  If the declared return type of the interface
6651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * method is a primitive type, then the value returned by
6751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * this method must be an instance of the corresponding primitive
6851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * wrapper class; otherwise, it must be a type assignable to the
6951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * declared return type.  If the value returned by this method is
7051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code null} and the interface method's return type is
7151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * primitive, then a {@code NullPointerException} will be
7251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * thrown by the method invocation on the proxy instance.  If the
7351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value returned by this method is otherwise not compatible with
7451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the interface method's declared return type as described above,
7551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * a {@code ClassCastException} will be thrown by the method
7651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * invocation on the proxy instance.
7751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
7851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws  Throwable the exception to throw from the method
7951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * invocation on the proxy instance.  The exception's type must be
8051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * assignable either to any of the exception types declared in the
8151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code throws} clause of the interface method or to the
8251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * unchecked exception types {@code java.lang.RuntimeException}
8351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * or {@code java.lang.Error}.  If a checked exception is
8451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * thrown by this method that is not assignable to any of the
8551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * exception types declared in the {@code throws} clause of
8651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the interface method, then an
8751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link UndeclaredThrowableException} containing the
8851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * exception that was thrown by this method will be thrown by the
8951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * method invocation on the proxy instance.
9051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
9151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @see     UndeclaredThrowableException
9251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
9351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public Object invoke(Object proxy, Method method, Object[] args)
9451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        throws Throwable;
9551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski}
96