I am learning AspectJ by refactoring some existing code. The curret plan is to handle logging via Aspects and then move on to timers. At present I am still working on the logging side of things.
So far this has been fairly simple and I have the following code:
Expand|Select|Wrap|Line Numbers
- public aspect MyLogger extends BaseAspect {
- declare precedence : *, MyLogger ;
- declare warning : (get(* System.out)||get(* System.err)) && withinScope() : "Don't use System.out.";
- MyLogger() {
- }
- pointcut sercoManagerLogging(): target(org.esf.adapters.serco.SercoManager) && withinScope();
- pointcut translatorLogging(): target(org.esf.adapters.serco.SercoBBTranslator) && withinScope();
- pointcut translateLogging(): execution(public void translate*(..)) && translatorLogging();
- pointcut addRoleLogging(): execution(public String addInst*(..)) && translatorLogging();
- pointcut callRoleLogging(): execution(public void *AddInst*(..)) && translatorLogging();
- before(): sercoManagerLogging() {
- pkgLogger.info("SercoLOGGING before method="
- + thisJoinPointStaticPart.getSignature());
- }
- before(): translateLogging(){
- pkgLogger.info("TranslateLOGGING before method="
- + thisJoinPointStaticPart.getSignature());
- }
- after(): translateLogging(){
- pkgLogger.info("TranslateLOGGING after method="
- + thisJoinPointStaticPart.getSignature());
- }
- String around(): addRoleLogging(){
- String information = proceed();
- pkgLogger.info("addRoleLOGGING around method="
- + thisJoinPointStaticPart.getSignature() + " " + information);
- return information;
- }
- before(): callRoleLogging(){
- pkgLogger.info("callRoleLogging before method="
- + thisJoinPointStaticPart.getSignature());
- }
- }
Within the actual method I have a number of variables that handle process counts. Is it possible to access these values from within the aspect code so that I don't have to have the otherwose unnecessary return?
Hopefully the question is a bit clearer now. I have tried reading up on this and found no way ofachieving what I want, then again I have also struggled to put this into a suitable search string for Google.
Any help here is greatly appreciated.
Cheers
nathj