package test.stateful.logging; public class Stateful { private boolean isEnabled=true; public boolean isEnabled() { return isEnabled; } public void isEnabled(boolean enabled) { isEnabled=enabled; } hook StatefulLogging { private String logText = "Executing: "; StatefulLogging(startmethod(..args),method(..args),stopmethod(..args)) { start>p1; p1:execution(startmethod)>p3||p2; p2:execution(method)>p3||p2; p3:execution(stopmethod)>p1; } public void setLogText(String text) { logText= text; } isApplicable() { return global.isEnabled(); } before() { System.out.println(logText+thisJoinPoint.getName()+" IN "+thisJoinPoint.getClassName()); } after throwing p3(java.io.IOException ex) { ; } } hook StatefulLoggingComplement { private String logText = "UNEXPECTED Complement: "; StatefulLoggingComplement(startmethod(..args),method(..args),stopmethod(..args),allmethods(..args)) { complement[execution(allmethods)]: start>p1; p1:execution(startmethod)>p3||p2; p2:execution(method)>p3||p2; p3:execution(stopmethod)>p1; } public void setLogText(String text) { logText= text; } isApplicable() { return global.isEnabled(); } before complement() { System.out.println(logText+thisJoinPoint.getName()+" IN "+thisJoinPoint.getClassName()); } } hook StatefulLoggingStrict { private String logText = "UNEXPECTED Strict: "; StatefulLoggingStrict(startmethod(..args),triggermethod(..args),allmethods(..args)) { strict[execution(allmethods)]: start>p1; p1:execution(startmethod)>p2; p2:execution(triggermethod)>p1; } public void setLogText(String text) { logText= text; } isApplicable() { return global.isEnabled(); } before p2() { System.out.println(logText+thisJoinPoint.getName()+" IN "+thisJoinPoint.getClassName()); } } hook StatefulLoggingStrictAll { private String logText = "Strict ALL SHOULD NOT OCCUR!!!!: "; StatefulLoggingStrictAll(startmethod(..args),triggermethod(..args)) { strict: start>p1; p1:execution(startmethod)>p2; p2:execution(triggermethod)>p1; } public void setLogText(String text) { logText= text; } isApplicable() { return global.isEnabled(); } before p2() { System.out.println(logText+thisJoinPoint.getName()+" IN "+thisJoinPoint.getClassName()); } } hook StatefulLoggingComplementAll { private String logText = "Strict ALL SHOULD NOT OCCUR!!!!: "; StatefulLoggingComplementAll(startmethod(..args),triggermethod(..args)) { complement: start>p1; p1:execution(startmethod)>p2; p2:execution(triggermethod)>p1; } public void setLogText(String text) { logText= text; } isApplicable() { return global.isEnabled(); } before p2() { System.out.println(logText+thisJoinPoint.getName()+" IN "+thisJoinPoint.getClassName()); } } hook StatefulLoggingComplementStrict { private String logText = "UNEXPECTED Strict: "; StatefulLoggingComplementStrict(startmethod(..args),triggermethod(..args),allmethods(..args)) { strict complement[execution(allmethods)]: start>p1; p1:execution(startmethod)>p2; p2:execution(triggermethod)>p1; } public void setLogText(String text) { logText= text; } isApplicable() { return global.isEnabled(); } before p2() { System.out.println(logText+thisJoinPoint.getName()+" IN "+thisJoinPoint.getClassName()); } } hook StatefulLoggingComplementStrictAll { private String logText = "Strict ALL SHOULD NOT OCCUR!!!!: "; StatefulLoggingComplementStrictAll(startmethod(..args),triggermethod(..args)) { complement strict: start>p1; p1:execution(startmethod)>p2; p2:execution(triggermethod)>p1; } public void setLogText(String text) { logText= text; } isApplicable() { return global.isEnabled(); } before p2() { System.out.println(logText+thisJoinPoint.getName()+" IN "+thisJoinPoint.getClassName()); } } }