The Proxy design pattern (GoF ) allows you to provide "a surrogate or placeholder for another object to control access to it". Proxies can be used in many ways. Some of which are:
Commons Proxy supports dynamic proxy generation using proxy factories, object providers, invokers, and interceptors.
Proxy factories encapsulate all necessary proxying logic away from your code. Switching proxying techniques/technologies is as simple as using a different proxy factory implementation class. Currently, Commons Proxy provides proxy factory implementations using JDK proxies, CGLIB , and Javassist . Proxy factories allow you to create three different types of proxy objects:
Object providers provide the objects which will be the "target" of a proxy. There are two types of object providers:
A core object provider provides a core implementation object. Commons Proxy supports many different implementations including:
|Constant||Always returns a specific object|
|Bean||Merely instantiates an object of a specified class each time|
|Cloning||Reflectively calls the public clone() method on a Cloneable object|
|Hessian||Returns a Hessian -based service object|
|Burlap||Returns a Burlap -based service object|
|JAX-RPC||Returns a JAX-RPC -based service object|
|Session Bean||Returns a reference to a Session EJB (stateless session beans only)|
An invoker handles all method invocations using a single method. Commons Proxy provides a few invoker implementations:
|Null||Always returns a null (useful for the "Null Object" pattern)|
|Apache XML-RPC||Uses Apache XML-RPC to fulfill the method invocation|
|Duck Typing||Supports "duck typing" by adapting a class to an interface it does not implement.|
|Invocation Handler Adapter||Adapts the JDK InvocationHandler interface to the Commons ProxyInvoker interface.|
Commons Proxy allows you to "intercept" a method invocation using Interceptors . Interceptors provide rudimentary aspect-oriented programming support, allowing you to alter the results/effects of a method invocation without actually changing the implementation of the method itself. Commons Proxy provides a few interceptor implementations including:
|Executor||Uses an Executor to execute the method in possibly another thread (only void methods are supported).|
|Logging||Logs all method invocations using the Apache Commons Logging API|
|Filtered||Optionally intercepts a method invocation based on a method filter|
|Method Interceptor Adapter||Adapts the AOP Alliance MethodInterceptor interface to the Commons ProxyInterceptor interface.|
The latest version is v1.0. -
For previous releases, see the Apache Archive
Note: The 1.x releases are compatible with JDK1.4+.
The commons mailing lists act as the main support forum. The user list is suitable for most library usage queries. The dev list is intended for the development discussion. Please remember that the lists are shared between all commons components, so prefix your email subject with [proxy].
Issues may be reported via ASF JIRA . Please read the instructions carefully to submit a useful bug report or enhancement request.