List of usage examples for org.springframework.aop PointcutAdvisor getPointcut
Pointcut getPointcut();
From source file:org.springframework.aop.support.AopUtils.java
/** * Can the given advisor apply at all on the given class? * This is an important test as it can be used to optimize * out a advisor for a class./*from w w w . j a va2s.com*/ * @param advisor the advisor to check * @param targetClass class we're testing * @return whether the pointcut can apply on any method */ public static boolean canApply(Advisor advisor, Class targetClass) { if (advisor instanceof IntroductionAdvisor) { return ((IntroductionAdvisor) advisor).getClassFilter().matches(targetClass); } else if (advisor instanceof PointcutAdvisor) { PointcutAdvisor pca = (PointcutAdvisor) advisor; return canApply(pca.getPointcut(), targetClass); } else { // It doesn't have a pointcut so we assume it applies return true; } }
From source file:org.springframework.integration.monitor.IntegrationMBeanExporter.java
private Object applyAdvice(Object bean, PointcutAdvisor advisor, ClassLoader beanClassLoader) { Class<?> targetClass = AopUtils.getTargetClass(bean); if (AopUtils.canApply(advisor.getPointcut(), targetClass)) { if (bean instanceof Advised) { ((Advised) bean).addAdvisor(advisor); return bean; } else {//from w ww . j a va 2 s . c o m ProxyFactory proxyFactory = new ProxyFactory(bean); proxyFactory.addAdvisor(advisor); /** * N.B. it's not a good idea to use proxyFactory.setProxyTargetClass(true) here because it forces all * the integration components to be cglib proxyable (i.e. have a default constructor etc.), which they * are not in general (usually for good reason). */ return proxyFactory.getProxy(beanClassLoader); } } return bean; }