See: Description
| Interface | Description |
|---|---|
| InvokerReference |
Interface to access the
Invoker of the proxy. |
| Class | Description |
|---|---|
| CglibProxyFactory |
A
ProxyFactory based on CGLIB. |
| StandardProxyFactory |
A
ProxyFactory based on a JDK. |
Different implementations of the ProxyFactory interface.
Currently are two implementations supported. One based on the JDK's reflection API and the other one on the CGLIB library.
The usage of a special ProxyFactory is simple and easy:
ProxyFactory factory = new StandardProxyFactory();
List<String> proxy = factory.createProxy(new SimpleInvoker(new ArrayList<String>()), List.class);
proxy.add("Hello World");
System.out.println("Size of list: " + proxy.size());
System.out.println("First element of list: " + proxy.get(0));
The example creates a proxy that implements the List interface. The proxy is backed up by a instance of an
ArrayList. The proxy ensures in this example,
that the instance cannot just be casted to access the specific methods
of the ArrayList like ArrayList.ensureCapacity(int).
Compare with the JDK's reflection API, there is not a real difference.
Copyright © 2005–2018 Codehaus. All rights reserved.