public class Proxy
extends java.lang.Object
implements java.io.Serializable
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.reflect.InvocationHandler |
h
the invocation handler for this proxy instance.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Proxy(java.lang.reflect.InvocationHandler h)
Constructs a new
Proxy instance from a subclass
(typically, a dynamic proxy class) with the specified value
for its invocation handler. |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Class<?> |
defineProxyClass(java.lang.Object module,
java.lang.String name,
byte[] b,
int off,
int len,
java.lang.ClassLoader loader) |
static java.lang.reflect.InvocationHandler |
getInvocationHandler(java.lang.Object proxy)
Returns the invocation handler for the specified proxy instance.
|
static java.lang.Class<?> |
getProxyClass(java.lang.ClassLoader loader,
java.lang.Class<?>... interfaces)
Returns the
java.lang.Class object for a proxy class
given a class loader and an array of interfaces. |
static boolean |
isProxyClass(java.lang.Class<?> cl)
Returns true if and only if the specified class was dynamically
generated to be a proxy class using the
getProxyClass
method or the newProxyInstance method. |
static java.lang.Object |
newProxyInstance(java.lang.ClassLoader loader,
java.lang.Class<?>[] interfaces,
java.lang.reflect.InvocationHandler h)
Returns an instance of a proxy class for the specified interfaces
that dispatches method invocations to the specified invocation
handler.
|
protected java.lang.reflect.InvocationHandler h
protected Proxy(java.lang.reflect.InvocationHandler h)
Proxy instance from a subclass
(typically, a dynamic proxy class) with the specified value
for its invocation handler.h - the invocation handler for this proxy instancejava.lang.NullPointerException - if the given invocation handler, h,
is null.public static java.lang.Class<?> getProxyClass(java.lang.ClassLoader loader,
java.lang.Class<?>... interfaces)
throws java.lang.IllegalArgumentException
java.lang.Class object for a proxy class
given a class loader and an array of interfaces. The proxy class
will be defined by the specified class loader and will implement
all of the supplied interfaces. If any of the given interfaces
is non-public, the proxy class will be non-public. If a proxy class
for the same permutation of interfaces has already been defined by the
class loader, then the existing proxy class will be returned; otherwise,
a proxy class for those interfaces will be generated dynamically
and defined by the class loader.
There are several restrictions on the parameters that may be
passed to Proxy.getProxyClass:
Class objects in the
interfaces array must represent interfaces, not
classes or primitive types.
interfaces array may
refer to identical Class objects.
cl and every interface i, the following
expression must be true:
Class.forName(i.getName(), false, cl) == i
interfaces array must not
exceed 65535.
If any of these restrictions are violated,
Proxy.getProxyClass will throw an
IllegalArgumentException. If the interfaces
array argument or any of its elements are null, a
NullPointerException will be thrown.
Note that the order of the specified proxy interfaces is significant: two requests for a proxy class with the same combination of interfaces but in a different order will result in two distinct proxy classes.
loader - the class loader to define the proxy classinterfaces - the list of interfaces for the proxy class
to implementjava.lang.IllegalArgumentException - if any of the restrictions on the
parameters that may be passed to getProxyClass
are violatedjava.lang.SecurityException - if a security manager, s, is present
and any of the following conditions is met:
loader is null and
the caller's class loader is not null and the
invocation of s.checkPermission with
RuntimePermission("getClassLoader") permission
denies access.intf,
the caller's class loader is not the same as or an
ancestor of the class loader for intf and
invocation of s.checkPackageAccess() denies access to intf.java.lang.NullPointerException - if the interfaces array
argument or any of its elements are nullpublic static java.lang.Object newProxyInstance(java.lang.ClassLoader loader,
java.lang.Class<?>[] interfaces,
java.lang.reflect.InvocationHandler h)
throws java.lang.IllegalArgumentException
Proxy.newProxyInstance throws
IllegalArgumentException for the same reasons that
Proxy.getProxyClass does.
loader - the class loader to define the proxy classinterfaces - the list of interfaces for the proxy class
to implementh - the invocation handler to dispatch method invocations tojava.lang.IllegalArgumentException - if any of the restrictions on the
parameters that may be passed to getProxyClass
are violatedjava.lang.SecurityException - if a security manager, s, is present
and any of the following conditions is met:
loader is null and
the caller's class loader is not null and the
invocation of s.checkPermission with
RuntimePermission("getClassLoader") permission
denies access;intf,
the caller's class loader is not the same as or an
ancestor of the class loader for intf and
invocation of s.checkPackageAccess() denies access to intf;s.checkPermission with
ReflectPermission("newProxyInPackage.{package name}")
permission denies access.java.lang.NullPointerException - if the interfaces array
argument or any of its elements are null, or
if the invocation handler, h, is
nullpublic static boolean isProxyClass(java.lang.Class<?> cl)
getProxyClass
method or the newProxyInstance method.
The reliability of this method is important for the ability
to use it to make security decisions, so its implementation should
not just test if the class in question extends Proxy.
cl - the class to testtrue if the class is a proxy class and
false otherwisejava.lang.NullPointerException - if cl is nullpublic static java.lang.reflect.InvocationHandler getInvocationHandler(java.lang.Object proxy)
throws java.lang.IllegalArgumentException
proxy - the proxy instance to return the invocation handler forjava.lang.IllegalArgumentException - if the argument is not a
proxy instancejava.lang.SecurityException - if a security manager, s, is present
and the caller's class loader is not the same as or an
ancestor of the class loader for the invocation handler
and invocation of s.checkPackageAccess() denies access to the invocation
handler's class.public static java.lang.Class<?> defineProxyClass(java.lang.Object module,
java.lang.String name,
byte[] b,
int off,
int len,
java.lang.ClassLoader loader)
Copyright © 2022. All rights reserved.