Is there a way to make this code work?
LogonControl.java
@Audit(AuditType.LOGON)
public void login(String username, String password) {
// do login
}
AuditHandler.java
public void audit(AuditType auditType) {
// persist audit
}
Endgame being, that each time login() is called, audit() is also called, with the appropriate audittype.
I imagine AOP is probably the solution to this, but I would like it to be as simple as possible (the AspectJ tutorials I’ve looked at normally have very convoluted annotations).
Note: I don’t want to have to predefine the methods that will call audit, I’m writing this for an extensible framework, and others may need to use it.
Using reflection is easy just annotate a method with @Audit, just like test runners in JUnit:
@Audit is defined as:
where Handler is:
and now the real code:
@Test:
output: