An attempt to create dynamic delegation classes.
This project aim to create new proxy classes which they will be used for delegation.
For example, you can delegate an java.lang.String
to trace any invocations.
To use this library, you will need to install :
- Byte-Buddy (version 1.12.1 or later)
- Objenesis (version 3.2 or later)
You will need to create a new class which extends Delegator<T>
(fr.drogonistudio.delegateme.Delegator
), the type <T>
is your
object's type to delegate. Then, you will implement the following method:
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
This method will be invoked everytime a public method is invoked in your proxied object. In this method, you can use :
protected final Object delegate(Object proxy, Method method, Object[] args) throws Throwable
to perform delegation.
Once you complete your Delegator
, you can warp your object to delegate with DelegatorFactorty.warp(Class<T>, Delegator<T>)
. The returned
object will be a clone a delegated object (every fields values are copied during generation process) but with the difference which any public
methods will invoke your Delegator
's invoke
method.
You can find examples into example
directory.