AOP 101: Intro To Aspect Oriented Programming: Ernest Hill
AOP 101: Intro To Aspect Oriented Programming: Ernest Hill
Programming
Ernest Hill
[email protected]
String name;
...
int temp;
...
temp = temperature;
}
static {
try {
System.loadLibrary(“widgethandler”);
} catch ( UnsatisfiedLinkError ex ) {
... deal with the exception
}
}
...
Ernest Hill AOP 101 - 18
Object Initialization Join Point
● Defined when a dynamic initializer is executed
for a class
● After call to object's parent constructor
● Just before return of object's constructor
Public class Widget extends Thingee {
...
public Widget( boolean isPalpable ) {
super( );
this.isPalpable = isPalpable;
}
...
Ernest Hill AOP 101 - 19
Pointcut
● A set of join points defined to specify when the
advice should be executed
● Often descibed using regular expressions or
pattern match syntax
● Some frameworks support composition of
pointcuts
before() : tracePoints() {
_callDepth++;
print("Before", thisJoinPoint);
}
after() : tracePoints() {
print("After", thisJoinPoint);
_callDepth--;
}
aspect DetectSystemErrUsage {
declare error :
call ( * System.err.print*(..) :
“Please use Logger.log() instead”;
}
import org.codehaus.aspectwerkz.joinpoint.JoinPoint;