dimanche 1 février 2015

How to "proxy" a method in Java

First off, I'm not sure how to best word my solution so if I seem to be babbling at times then please consider this.


There is an interface in a library I wish to modify without touching the physical code,



public interface ProxiedPlayer {
// .. other code
public void setPermission(String permission, boolean state);
}


I have written a third party library for handling permissions and having to hook into my API to edit permissions may be a step some developers do not want to take. So I ask that when setPermission is called is it possible to have it invoke my invoke the appropriate method in my library that will handle permission setting whilst ignoring the pre-programmed code or not?


I have looked into the Java Proxy class but it seems you need an instance of the object you're trying to proxy in the first place. Given that the method can be called any time I do not believe this to be my solution but will happily stand corrected.






Aucun commentaire:

Enregistrer un commentaire