Skip to content

DrogoniEntity/Delegate-Me

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Delegate-Me

An attempt to create dynamic delegation classes.

What is it ?

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.

How to use it ?

Prerequisite :

To use this library, you will need to install :

Writing a delegation class

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.

Generating delegated object

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.

About

An attempt to create dynamic delegation classes.

Topics

Resources

License

Stars

Watchers

Forks

Languages