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