org.jlot.stats.client.MessageSourceStatsAspect Maven / Gradle / Ivy
package org.jlot.stats.client;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.SuppressAjWarnings;
import org.springframework.context.MessageSourceResolvable;
@Aspect
public class MessageSourceStatsAspect
{
private static StatsHarvester statsHarvester = new StatsHarvester();
private static boolean active = false;
@Pointcut("execution(public String org.springframework.context.MessageSource.getMessage(String, Object[], String, java.util.Locale))")
public void getMessageWithDefaultMessage ( )
{}
@Pointcut("execution(public String org.springframework.context.MessageSource.getMessage(String, Object[], java.util.Locale))")
public void getMessageWithoutDefaultMessage ( )
{}
@Pointcut("execution(public String org.springframework.context.MessageSource.getMessage(org.springframework.context.MessageSourceResolvable, java.util.Locale))")
public void getMessageWithMessageSourceResolvable ( )
{}
@Before("getMessageWithDefaultMessage()")
@SuppressAjWarnings()
public void harvestWithDefaultMessage ( JoinPoint joinPoint )
{
if (active)
{
String code = (String) joinPoint.getArgs()[0];
statsHarvester.collect(code);
}
}
@Before("getMessageWithoutDefaultMessage()")
@SuppressAjWarnings()
public void harvestWithoutDefaultMessage ( JoinPoint joinPoint )
{
if (active)
{
String code = (String) joinPoint.getArgs()[0];
statsHarvester.collect(code);
}
}
@Before("getMessageWithMessageSourceResolvable()")
@SuppressAjWarnings()
public void harvestWithMessageSourceResolvable ( JoinPoint joinPoint )
{
if (active)
{
MessageSourceResolvable resolvable = (MessageSourceResolvable) joinPoint.getArgs()[0];
statsHarvester.collect(resolvable.getCodes());
}
}
public static void setActive ( boolean active )
{
MessageSourceStatsAspect.active = active;
}
public static StatsHarvester getStatsHarvester ( )
{
return statsHarvester;
}
}