jaroslav@601: /* jaroslav@601: * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved. jaroslav@601: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@601: * jaroslav@601: * This code is free software; you can redistribute it and/or modify it jaroslav@601: * under the terms of the GNU General Public License version 2 only, as jaroslav@601: * published by the Free Software Foundation. Oracle designates this jaroslav@601: * particular file as subject to the "Classpath" exception as provided jaroslav@601: * by Oracle in the LICENSE file that accompanied this code. jaroslav@601: * jaroslav@601: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@601: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@601: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@601: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@601: * accompanied this code). jaroslav@601: * jaroslav@601: * You should have received a copy of the GNU General Public License version jaroslav@601: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@601: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@601: * jaroslav@601: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@601: * or visit www.oracle.com if you need additional information or have any jaroslav@601: * questions. jaroslav@601: */ jaroslav@601: jaroslav@601: package java.lang.reflect; jaroslav@601: jaroslav@601: /** jaroslav@601: * {@code InvocationHandler} is the interface implemented by jaroslav@601: * the invocation handler of a proxy instance. jaroslav@601: * jaroslav@601: *

Each proxy instance has an associated invocation handler. jaroslav@601: * When a method is invoked on a proxy instance, the method jaroslav@601: * invocation is encoded and dispatched to the {@code invoke} jaroslav@601: * method of its invocation handler. jaroslav@601: * jaroslav@601: * @author Peter Jones jaroslav@601: * @see Proxy jaroslav@601: * @since 1.3 jaroslav@601: */ jaroslav@601: public interface InvocationHandler { jaroslav@601: jaroslav@601: /** jaroslav@601: * Processes a method invocation on a proxy instance and returns jaroslav@601: * the result. This method will be invoked on an invocation handler jaroslav@601: * when a method is invoked on a proxy instance that it is jaroslav@601: * associated with. jaroslav@601: * jaroslav@601: * @param proxy the proxy instance that the method was invoked on jaroslav@601: * jaroslav@601: * @param method the {@code Method} instance corresponding to jaroslav@601: * the interface method invoked on the proxy instance. The declaring jaroslav@601: * class of the {@code Method} object will be the interface that jaroslav@601: * the method was declared in, which may be a superinterface of the jaroslav@601: * proxy interface that the proxy class inherits the method through. jaroslav@601: * jaroslav@601: * @param args an array of objects containing the values of the jaroslav@601: * arguments passed in the method invocation on the proxy instance, jaroslav@601: * or {@code null} if interface method takes no arguments. jaroslav@601: * Arguments of primitive types are wrapped in instances of the jaroslav@601: * appropriate primitive wrapper class, such as jaroslav@601: * {@code java.lang.Integer} or {@code java.lang.Boolean}. jaroslav@601: * jaroslav@601: * @return the value to return from the method invocation on the jaroslav@601: * proxy instance. If the declared return type of the interface jaroslav@601: * method is a primitive type, then the value returned by jaroslav@601: * this method must be an instance of the corresponding primitive jaroslav@601: * wrapper class; otherwise, it must be a type assignable to the jaroslav@601: * declared return type. If the value returned by this method is jaroslav@601: * {@code null} and the interface method's return type is jaroslav@601: * primitive, then a {@code NullPointerException} will be jaroslav@601: * thrown by the method invocation on the proxy instance. If the jaroslav@601: * value returned by this method is otherwise not compatible with jaroslav@601: * the interface method's declared return type as described above, jaroslav@601: * a {@code ClassCastException} will be thrown by the method jaroslav@601: * invocation on the proxy instance. jaroslav@601: * jaroslav@601: * @throws Throwable the exception to throw from the method jaroslav@601: * invocation on the proxy instance. The exception's type must be jaroslav@601: * assignable either to any of the exception types declared in the jaroslav@601: * {@code throws} clause of the interface method or to the jaroslav@601: * unchecked exception types {@code java.lang.RuntimeException} jaroslav@601: * or {@code java.lang.Error}. If a checked exception is jaroslav@601: * thrown by this method that is not assignable to any of the jaroslav@601: * exception types declared in the {@code throws} clause of jaroslav@601: * the interface method, then an jaroslav@601: * {@link UndeclaredThrowableException} containing the jaroslav@601: * exception that was thrown by this method will be thrown by the jaroslav@601: * method invocation on the proxy instance. jaroslav@601: * jaroslav@601: * @see UndeclaredThrowableException jaroslav@601: */ jaroslav@601: public Object invoke(Object proxy, Method method, Object[] args) jaroslav@601: throws Throwable; jaroslav@601: }