//檢查當前advisor的pointcut是否可以匹配當前方法??
MethodMatcher?mm?=pointcutAdvisor.getPointcut().getMethodMatcher(); ?
if?(MethodMatchers.matches(mm,method,?targetClass,?hasIntroductions))?{??
if(mm.isRuntime())?{??
//?Creating?a?newobject?instance?in?the?getInterceptors()?method??
//?isn't?a?problemas?we?normally?cache?created?chains.??
for?(intj?=?0;?j?
interceptorList.add(new?InterceptorAndDynamicMethodMatcher(interceptors[j],mm));??
}??
}?else?{??
interceptorList.addAll(Arrays.asList(interceptors));??
}??
}??
}??
}?else?if?(advisor?instanceof?IntroductionAdvisor){??
IntroductionAdvisor?ia?=(IntroductionAdvisor)?advisor;??
if(config.isPreFiltered()?||?ia.getClassFilter().matches(targetClass))?{??
Interceptor[]?interceptors=?registry.getInterceptors(advisor);??
interceptorList.addAll(Arrays.asList(interceptors));??
}??
}?else?{??
Interceptor[]?interceptors?=registry.getInterceptors(advisor);??
interceptorList.addAll(Arrays.asList(interceptors));??
}??
}??
return?interceptorList;??
} ?
這個方法執(zhí)行完成后,Advised中配置能夠應用到連接點或者目標類的Advisor全部被轉(zhuǎn)化成了MethodInterceptor.
接下來我們再看下得到的攔截器鏈是怎么起作用的。
if?(chain.isEmpty())?{??
retVal?=?AopUtils.invokeJoinpointUsingReflection(target,method,?args);??
}?else?{??
//創(chuàng)建MethodInvocation??
invocation?=?newReflectiveMethodInvocation(proxy,?target,?method,?args,?targetClass,?chain);??
retVal?=?invocation.proceed();??
} ?
評論
查看更多