/** * Search the given candidate Advisors to find all Advisors that * can apply to the specified bean. * @param candidateAdvisors the candidate Advisors * @param beanClass the target's bean class * @param beanName the target's bean name * @return the List of applicable Advisors * @see ProxyCreationContext#getCurrentProxiedBeanName() */ protected List<Advisor> findAdvisorsThatCanApply( List<Advisor> candidateAdvisors, Class<?> beanClass, String beanName) { ProxyCreationContext.setCurrentProxiedBeanName(beanName); try { return AopUtils.findAdvisorsThatCanApply(candidateAdvisors, beanClass); } finally { ProxyCreationContext.setCurrentProxiedBeanName(null); } }
/** * Add all {@link Advisor Advisors} from the supplied {@link MetadataAwareAspectInstanceFactory} * to the current chain. Exposes any special purpose {@link Advisor Advisors} if needed. * @see AspectJProxyUtils#makeAdvisorChainAspectJCapableIfNecessary(List) */ private void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory) { List<Advisor> advisors = this.aspectFactory.getAdvisors(instanceFactory); Class<?> targetClass = getTargetClass(); Assert.state(targetClass != null, "Unresolvable target class"); advisors = AopUtils.findAdvisorsThatCanApply(advisors, targetClass); AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(advisors); AnnotationAwareOrderComparator.sort(advisors); addAdvisors(advisors); }
@Test public void testIntroductionAdvisorExcludedFromTargetImplementingInterface() { assertTrue(AopUtils.findAdvisorsThatCanApply( getFixture().getAdvisors( new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")), CannotBeUnlocked.class).isEmpty()); assertEquals(2, AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors( new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size()); }
@Test public void testIntroductionOnTargetExcludedByTypePattern() { LinkedList<Object> target = new LinkedList<>(); List<?> proxy = (List<?>) createProxy(target, AopUtils.findAdvisorsThatCanApply( getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")), List.class ), List.class); assertFalse("Type pattern must have excluded mixin", proxy instanceof Lockable); }
@Test public void testIntroductionOnTargetImplementingInterface() { CannotBeUnlocked target = new CannotBeUnlocked(); Lockable proxy = (Lockable) createProxy(target, // Ensure that we exclude AopUtils.findAdvisorsThatCanApply( getFixture().getAdvisors( new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")), CannotBeUnlocked.class ), CannotBeUnlocked.class); assertThat(proxy, instanceOf(Lockable.class)); Lockable lockable = proxy; assertTrue("Already locked", lockable.locked()); lockable.lock(); assertTrue("Real target ignores locking", lockable.locked()); try { lockable.unlock(); fail(); } catch (UnsupportedOperationException ex) { // Ok } }
/** * Find all eligible advices for auto-proxying this class. * @return the empty list, not null, if there are no pointcuts or interceptors * @see #findCandidateAdvisors */ protected List findEligibleAdvisors(Class clazz) { return AopUtils.findAdvisorsThatCanApply(findCandidateAdvisors(), clazz); }
/** * Search the given candidate Advisors to find all Advisors that * can apply to the specified bean. * @param candidateAdvisors the candidate Advisors * @param beanClass the target's bean class * @param beanName the target's bean name * @return the List of applicable Advisors * @see ProxyCreationContext#getCurrentProxiedBeanName() */ protected List<Advisor> findAdvisorsThatCanApply( List<Advisor> candidateAdvisors, Class<?> beanClass, String beanName) { ProxyCreationContext.setCurrentProxiedBeanName(beanName); try { return AopUtils.findAdvisorsThatCanApply(candidateAdvisors, beanClass); } finally { ProxyCreationContext.setCurrentProxiedBeanName(null); } }
/** * Search the given candidate Advisors to find all Advisors that * can apply to the specified bean. * @param candidateAdvisors the candidate Advisors * @param beanClass the target's bean class * @param beanName the target's bean name * @return the List of applicable Advisors * @see ProxyCreationContext#getCurrentProxiedBeanName() */ protected List<Advisor> findAdvisorsThatCanApply( List<Advisor> candidateAdvisors, Class<?> beanClass, String beanName) { ProxyCreationContext.setCurrentProxiedBeanName(beanName); try { return AopUtils.findAdvisorsThatCanApply(candidateAdvisors, beanClass); } finally { ProxyCreationContext.setCurrentProxiedBeanName(null); } }
/** * Add all {@link Advisor Advisors} from the supplied {@link MetadataAwareAspectInstanceFactory} * to the current chain. Exposes any special purpose {@link Advisor Advisors} if needed. * @see AspectJProxyUtils#makeAdvisorChainAspectJCapableIfNecessary(List) */ private void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory) { List<Advisor> advisors = this.aspectFactory.getAdvisors(instanceFactory); Class<?> targetClass = getTargetClass(); Assert.state(targetClass != null, "Unresolvable target class"); advisors = AopUtils.findAdvisorsThatCanApply(advisors, targetClass); AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(advisors); AnnotationAwareOrderComparator.sort(advisors); addAdvisors(advisors); }
/** * Add all {@link Advisor Advisors} from the supplied {@link MetadataAwareAspectInstanceFactory} * to the current chain. Exposes any special purpose {@link Advisor Advisors} if needed. * @see AspectJProxyUtils#makeAdvisorChainAspectJCapableIfNecessary(List) */ private void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory) { List<Advisor> advisors = this.aspectFactory.getAdvisors(instanceFactory); advisors = AopUtils.findAdvisorsThatCanApply(advisors, getTargetClass()); AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(advisors); AnnotationAwareOrderComparator.sort(advisors); addAdvisors(advisors); }