AOP syntax problem
March 8, 2005 Leave a comment
I have been trying to use AOP for a few months. One problem that I face is the syntax. I started with AspectWerkz. When they added support for JDK 5.0 I learnt to use that syntax. I am learning aspectj after they merged with it. Now AspectJ is introducing JDK 5 syntax. It is getting
more difficult with the introduction of generics support.
Though JDK 5 didn’t make it simpler, it seems that the syntax of different AOP frameworks is making the adoption harder. Sometimes it is difficult to keep track of what is in what version.
I have rewritten my AOP code using AspectJ 5 syntax after I
read this article
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class StatusReportAspect {
@Pointcut("execution(@com.blueprint.util.annotation.StatusShow * *..*(..))")
void statusMethods(){};
@Before("statusMethods()")
public void before( final JoinPoint jp ) {
try{
Class clazz = PaperSheet.class;
Method method = clazz.getMethod(
jp.getSignature().getName(),
Graphics2D.class);
if( method.isAnnotationPresent(
StatusShow.class )){
BluePrint.getStatus().setText(
method.getAnnotation( StatusShow.class ).
message() );
}
}catch( Throwable t ){
t.printStackTrace();
//This is benign. Just ignore.
}
}
}