rt/emul/mini/src/main/java/java/lang/reflect/InvocationHandler.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Feb 2013 16:54:16 +0100
changeset 772 d382dacfd73f
parent 601 emul/mini/src/main/java/java/lang/reflect/InvocationHandler.java@5198affdb915
permissions -rw-r--r--
Moving modules around so the runtime is under one master pom and can be built without building other modules that are in the repository
jaroslav@601
     1
/*
jaroslav@601
     2
 * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
jaroslav@601
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@601
     4
 *
jaroslav@601
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@601
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@601
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@601
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@601
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@601
    10
 *
jaroslav@601
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@601
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@601
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@601
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@601
    15
 * accompanied this code).
jaroslav@601
    16
 *
jaroslav@601
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@601
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@601
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@601
    20
 *
jaroslav@601
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@601
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@601
    23
 * questions.
jaroslav@601
    24
 */
jaroslav@601
    25
jaroslav@601
    26
package java.lang.reflect;
jaroslav@601
    27
jaroslav@601
    28
/**
jaroslav@601
    29
 * {@code InvocationHandler} is the interface implemented by
jaroslav@601
    30
 * the <i>invocation handler</i> of a proxy instance.
jaroslav@601
    31
 *
jaroslav@601
    32
 * <p>Each proxy instance has an associated invocation handler.
jaroslav@601
    33
 * When a method is invoked on a proxy instance, the method
jaroslav@601
    34
 * invocation is encoded and dispatched to the {@code invoke}
jaroslav@601
    35
 * method of its invocation handler.
jaroslav@601
    36
 *
jaroslav@601
    37
 * @author      Peter Jones
jaroslav@601
    38
 * @see         Proxy
jaroslav@601
    39
 * @since       1.3
jaroslav@601
    40
 */
jaroslav@601
    41
public interface InvocationHandler {
jaroslav@601
    42
jaroslav@601
    43
    /**
jaroslav@601
    44
     * Processes a method invocation on a proxy instance and returns
jaroslav@601
    45
     * the result.  This method will be invoked on an invocation handler
jaroslav@601
    46
     * when a method is invoked on a proxy instance that it is
jaroslav@601
    47
     * associated with.
jaroslav@601
    48
     *
jaroslav@601
    49
     * @param   proxy the proxy instance that the method was invoked on
jaroslav@601
    50
     *
jaroslav@601
    51
     * @param   method the {@code Method} instance corresponding to
jaroslav@601
    52
     * the interface method invoked on the proxy instance.  The declaring
jaroslav@601
    53
     * class of the {@code Method} object will be the interface that
jaroslav@601
    54
     * the method was declared in, which may be a superinterface of the
jaroslav@601
    55
     * proxy interface that the proxy class inherits the method through.
jaroslav@601
    56
     *
jaroslav@601
    57
     * @param   args an array of objects containing the values of the
jaroslav@601
    58
     * arguments passed in the method invocation on the proxy instance,
jaroslav@601
    59
     * or {@code null} if interface method takes no arguments.
jaroslav@601
    60
     * Arguments of primitive types are wrapped in instances of the
jaroslav@601
    61
     * appropriate primitive wrapper class, such as
jaroslav@601
    62
     * {@code java.lang.Integer} or {@code java.lang.Boolean}.
jaroslav@601
    63
     *
jaroslav@601
    64
     * @return  the value to return from the method invocation on the
jaroslav@601
    65
     * proxy instance.  If the declared return type of the interface
jaroslav@601
    66
     * method is a primitive type, then the value returned by
jaroslav@601
    67
     * this method must be an instance of the corresponding primitive
jaroslav@601
    68
     * wrapper class; otherwise, it must be a type assignable to the
jaroslav@601
    69
     * declared return type.  If the value returned by this method is
jaroslav@601
    70
     * {@code null} and the interface method's return type is
jaroslav@601
    71
     * primitive, then a {@code NullPointerException} will be
jaroslav@601
    72
     * thrown by the method invocation on the proxy instance.  If the
jaroslav@601
    73
     * value returned by this method is otherwise not compatible with
jaroslav@601
    74
     * the interface method's declared return type as described above,
jaroslav@601
    75
     * a {@code ClassCastException} will be thrown by the method
jaroslav@601
    76
     * invocation on the proxy instance.
jaroslav@601
    77
     *
jaroslav@601
    78
     * @throws  Throwable the exception to throw from the method
jaroslav@601
    79
     * invocation on the proxy instance.  The exception's type must be
jaroslav@601
    80
     * assignable either to any of the exception types declared in the
jaroslav@601
    81
     * {@code throws} clause of the interface method or to the
jaroslav@601
    82
     * unchecked exception types {@code java.lang.RuntimeException}
jaroslav@601
    83
     * or {@code java.lang.Error}.  If a checked exception is
jaroslav@601
    84
     * thrown by this method that is not assignable to any of the
jaroslav@601
    85
     * exception types declared in the {@code throws} clause of
jaroslav@601
    86
     * the interface method, then an
jaroslav@601
    87
     * {@link UndeclaredThrowableException} containing the
jaroslav@601
    88
     * exception that was thrown by this method will be thrown by the
jaroslav@601
    89
     * method invocation on the proxy instance.
jaroslav@601
    90
     *
jaroslav@601
    91
     * @see     UndeclaredThrowableException
jaroslav@601
    92
     */
jaroslav@601
    93
    public Object invoke(Object proxy, Method method, Object[] args)
jaroslav@601
    94
        throws Throwable;
jaroslav@601
    95
}