public class Proxy extends Object implements Serializable
| Modifier and Type | Field and Description |
|---|---|
protected InvocationHandler |
h
the invocation handler for this proxy instance.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Proxy(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 Class<?> |
defineProxyClass(Object module,
String name,
byte[] b,
int off,
int len,
ClassLoader loader) |
static InvocationHandler |
getInvocationHandler(Object proxy)
Returns the invocation handler for the specified proxy instance.
|
static Class<?> |
getProxyClass(ClassLoader loader,
Class<?>... interfaces)
Returns the
java.lang.Class object for a proxy class
given a class loader and an array of interfaces. |
static boolean |
isProxyClass(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 Object |
newProxyInstance(ClassLoader loader,
Class<?>[] interfaces,
InvocationHandler h)
Returns an instance of a proxy class for the specified interfaces
that dispatches method invocations to the specified invocation
handler.
|
protected InvocationHandler h
protected Proxy(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 instanceNullPointerException - if the given invocation handler, h,
is null.public static Class<?> getProxyClass(ClassLoader loader, Class<?>... interfaces) throws 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 implementIllegalArgumentException - if any of the restrictions on the
parameters that may be passed to getProxyClass
are violatedSecurityException - 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.NullPointerException - if the interfaces array
argument or any of its elements are nullpublic static Object newProxyInstance(ClassLoader loader, Class<?>[] interfaces, InvocationHandler h) throws 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 toIllegalArgumentException - if any of the restrictions on the
parameters that may be passed to getProxyClass
are violatedSecurityException - 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.NullPointerException - if the interfaces array
argument or any of its elements are null, or
if the invocation handler, h, is
nullpublic static boolean isProxyClass(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 otherwiseNullPointerException - if cl is nullpublic static InvocationHandler getInvocationHandler(Object proxy) throws IllegalArgumentException
proxy - the proxy instance to return the invocation handler forIllegalArgumentException - if the argument is not a
proxy instanceSecurityException - 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 Class<?> defineProxyClass(Object module, String name, byte[] b, int off, int len, ClassLoader loader)
Copyright © 2024. All rights reserved.