接口 FieldInterceptor

所有超级接口:
Advice, Interceptor

public interface FieldInterceptor extends Interceptor
Intercepts field access on a target object.

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;
     }
 }
 
  • 方法概要

    修饰符和类型
    方法
    说明
    get(FieldAccess fieldRead)
    Do the stuff you want to do before and after the field is getted.
    set(FieldAccess fieldWrite)
    Do the stuff you want to do before and after the field is setted.
  • 方法详细资料

    • get

      Object get(FieldAccess fieldRead) throws Throwable
      Do the stuff you want to do before and after the field is getted.

      Polite implementations would certainly like to call Joinpoint.proceed().

      参数:
      fieldRead - the joinpoint that corresponds to the field read
      返回:
      the result of the field read Joinpoint.proceed(), might be intercepted by the interceptor.
      抛出:
      Throwable - if the interceptors or the target-object throws an exception.
    • set

      Object set(FieldAccess fieldWrite) throws Throwable
      Do the stuff you want to do before and after the field is setted.

      Polite implementations would certainly like to implement Joinpoint.proceed().

      参数:
      fieldWrite - the joinpoint that corresponds to the field write
      返回:
      the result of the field set Joinpoint.proceed(), might be intercepted by the interceptor.
      抛出:
      Throwable - if the interceptors or the target-object throws an exception.