| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public class CompositeDataInvocationHandler extends Object implements InvocationHandler
An {@link InvocationHandler} that forwards getter methods to a {@link CompositeData}. If you have an interface that contains only getter methods (such as {@code String getName()} or {@code boolean isActive()}) then you can use this class in conjunction with the {@link Proxy} class to produce an implementation of the interface where each getter returns the value of the corresponding item in a {@code CompositeData}.
For example, suppose you have an interface like this:
and a {@code CompositeData} constructed like this:public interface NamedNumber { public int getNumber(); public String getName(); }
then you can construct an object implementing {@code NamedNumber} and backed by the object {@code cd} like this:CompositeData cd = new {@link CompositeDataSupport}( someCompositeType, new String[] {"number", "name"}, new Object[] {5, "five"} );
A call to {@code nn.getNumber()} will then return 5.InvocationHandler handler = new CompositeDataInvocationHandler(cd); NamedNumber nn = (NamedNumber) Proxy.newProxyInstance(NamedNumber.class.getClassLoader(), new Class[] {NamedNumber.class}, handler);
If the first letter of the property defined by a getter is a capital, then this handler will look first for an item in the {@code CompositeData} beginning with a capital, then, if that is not found, for an item beginning with the corresponding lowercase letter or code point. For a getter called {@code getNumber()}, the handler will first look for an item called {@code Number}, then for {@code number}. If the getter is called {@code getnumber()}, then the item must be called {@code number}.
If the method given to {@link #invoke invoke} is the method {@code boolean equals(Object)} inherited from {@code Object}, then it will return true if and only if the argument is a {@code Proxy} whose {@code InvocationHandler} is also a {@code CompositeDataInvocationHandler} and whose backing {@code CompositeData} is equal (not necessarily identical) to this object's. If the method given to {@code invoke} is the method {@code int hashCode()} inherited from {@code Object}, then it will return a value that is consistent with this definition of {@code equals}: if two objects are equal according to {@code equals}, then they will have the same {@code hashCode}.
Constructor Summary | |
---|---|
CompositeDataInvocationHandler(CompositeData compositeData) Construct a handler backed by the given . |
Method Summary | |
---|---|
CompositeData |
Return the that was supplied to the constructor. |
Object |
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CompositeDataInvocationHandler(CompositeData compositeData)
Construct a handler backed by the given {@code CompositeData}.
compositeData
- the {@code CompositeData} that will supply
information to getters.Method Detail |
---|
public CompositeData getCompositeData()
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
proxy
method
args
Throwable
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |