Proxy


Proxy java.lang.reflect

Java 1.3 serializable

This class defines a simple but powerful API for dynamically generating a proxy class . A proxy class implements a specified list of interfaces and delegates invocations of the methods defined by those interfaces to a separate invocation handler object.

The static getProxyClass( ) method dynamically creates a new Class object that implements each of the interfaces specified in the supplied Class[ ] array. The newly created class is defined in the context of the specified ClassLoader . The Class returned by getProxyClass( ) is a subclass of Proxy . Every class that is dynamically generated by getProxyClass( ) has a single public constructor, which expects a single argument of type InvocationHandler . You can create an instance of the dynamic proxy class by using the Constructor class to invoke this constructor. Or, more simply, you can combine the call to getProxyClass( ) with the constructor call by calling the static newProxyInstance( ) method, which both defines and instantiates a proxy class.

Every instance of a dynamic proxy class has an associated InvocationHandler object. All method calls made on a proxy class are translated into calls to the invoke( ) method of this InvocationHandler object, which can handle the call in any way it sees fit. The static getInvocationHandler( ) method returns the InvocationHandler object for a given proxy object. The static isProxyClass( ) method returns true if a specified Class object is a dynamically generated proxy class.

Figure 10-100. java.lang.reflect.Proxy

 public class  Proxy  implements Serializable {  // Protected Constructors  protected  Proxy  (InvocationHandler  h  );  // Public Class Methods  public static InvocationHandler  getInvocationHandler  (Object  proxy  )  throws IllegalArgumentException;        public static Class<?>  getProxyClass  (ClassLoader  loader  , Class<?>  ...  interfaces  ) throws IllegalArgumentException;        public static boolean  isProxyClass  (Class<?>  cl  );        public static Object  newProxyInstance  (ClassLoader  loader  , Class<?>[ ]  interfaces  , InvocationHandler  h  ) throws IllegalArgumentException;  // Protected Instance Fields  protected InvocationHandler  h  ;   } 



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net