public interface FieldInterceptor extends Interceptor
The user should implement the set(FieldAccess) and
get(FieldAccess) methods to modify the original
behavior. E.g. the following class implements a tracing interceptor
(traces the accesses to the intercepted field(s)):
class TracingInterceptor implements FieldInterceptor {
Object set(FieldAccess fa) throws Throwable {
System.out.println("field "+fa.getField()+" is set with value "+
fa.getValueToSet());
Object ret=fa.proceed();
System.out.println("field "+fa.getField()+" was set to value "+ret);
return ret;
}
Object get(FieldAccess fa) throws Throwable {
System.out.println("field "+fa.getField()+" is about to be read");
Object ret=fa.proceed();
System.out.println("field "+fa.getField()+" was read; value is "+ret);
return ret;
}
}
| Modifier and Type | Method and Description |
|---|---|
Object |
get(FieldAccess fieldRead)
Do the stuff you want to do before and after the
field is getted.
|
Object |
set(FieldAccess fieldWrite)
Do the stuff you want to do before and after the
field is setted.
|
Object get(FieldAccess fieldRead) throws Throwable
Polite implementations would certainly like to call
Joinpoint.proceed().
fieldRead - the joinpoint that corresponds to the field
readJoinpoint.proceed(), might be intercepted by the
interceptor.Throwable - if the interceptors or the
target-object throws an exception.Object set(FieldAccess fieldWrite) throws Throwable
Polite implementations would certainly like to implement
Joinpoint.proceed().
fieldWrite - the joinpoint that corresponds to the field
writeJoinpoint.proceed(), might be intercepted by the
interceptor.Throwable - if the interceptors or the
target-object throws an exception.Copyright © 2009–2014 Oracle Corporation. All rights reserved.