Annotations - Declare Warnings
Declaring warnings To declare a warning, you annotate a field with @DeclareWarning. This field must be within an @Aspect or @InterceptorDef annotated class. The type of the field does not actually matter, though Pointcut has been used in this example. DeclareAspect is not actually bound to anything and does no interceptions, its sole purpose in this example is as a vessel for the @DeclareWarning annotations. import org.jboss.aop.DeclareWarning; @Aspect public class DeclareAspect { @DeclareWarning (expr="class($instanceof{VehicleDAO}) AND !has(public void *->save())", msg="All VehicleDAO subclasses must override the save() method.") public static Pointcut warning1; @DeclareWarning (expr="call(Driver->new(..)) AND within(*DAO)", msg="DAO classes should not access the Driver class") public static Pointcut warning2; @DeclareWarning (expr="call(* Driver->*(..)) AND withincode(* *DAO->save())", msg="DAO classes should not access the Driver class") public static Pointcut warning3; } The first @DeclareWarning annotated field specifies that VehicleDAO and its subclasses must implement a void noargs save() method. This condition is broken in our example by the fact that MotorbikeDAO does not do so. The second @DeclareWarning annotated field specifies that none of the DAO classes can call the Driver constructor. This condition is broken in our example by the fact that CarDAO.save() tries to create a new Driver class. The third @DeclareWarning annotated field specifies that no method on any of the the DAO classes can call the Driver methods. This condition is broken in our example by the fact that CarDAO.save() tries to call a method on the Driver class