Search in sources :

Example 6 with IntroductionAdvisor

use of org.springframework.aop.IntroductionAdvisor in project spring-framework by spring-projects.

the class AopUtils method findAdvisorsThatCanApply.

/**
	 * Determine the sublist of the {@code candidateAdvisors} list
	 * that is applicable to the given class.
	 * @param candidateAdvisors the Advisors to evaluate
	 * @param clazz the target class
	 * @return sublist of Advisors that can apply to an object of the given class
	 * (may be the incoming List as-is)
	 */
public static List<Advisor> findAdvisorsThatCanApply(List<Advisor> candidateAdvisors, Class<?> clazz) {
    if (candidateAdvisors.isEmpty()) {
        return candidateAdvisors;
    }
    List<Advisor> eligibleAdvisors = new LinkedList<>();
    for (Advisor candidate : candidateAdvisors) {
        if (candidate instanceof IntroductionAdvisor && canApply(candidate, clazz)) {
            eligibleAdvisors.add(candidate);
        }
    }
    boolean hasIntroductions = !eligibleAdvisors.isEmpty();
    for (Advisor candidate : candidateAdvisors) {
        if (candidate instanceof IntroductionAdvisor) {
            // already processed
            continue;
        }
        if (canApply(candidate, clazz, hasIntroductions)) {
            eligibleAdvisors.add(candidate);
        }
    }
    return eligibleAdvisors;
}
Also used : IntroductionAdvisor(org.springframework.aop.IntroductionAdvisor) PointcutAdvisor(org.springframework.aop.PointcutAdvisor) IntroductionAdvisor(org.springframework.aop.IntroductionAdvisor) Advisor(org.springframework.aop.Advisor) LinkedList(java.util.LinkedList)

Aggregations

IntroductionAdvisor (org.springframework.aop.IntroductionAdvisor)6 Advisor (org.springframework.aop.Advisor)5 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)3 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)3 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)2 PointcutAdvisor (org.springframework.aop.PointcutAdvisor)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 IntroductionInterceptor (org.springframework.aop.IntroductionInterceptor)1 MethodMatcher (org.springframework.aop.MethodMatcher)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 AdvisorAdapterRegistry (org.springframework.aop.framework.adapter.AdvisorAdapterRegistry)1 GlobalAdvisorAdapterRegistry (org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry)1 TimeStamped (org.springframework.tests.TimeStamped)1 INestedTestBean (org.springframework.tests.sample.beans.INestedTestBean)1 ITestBean (org.springframework.tests.sample.beans.ITestBean)1 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)1 TestBean (org.springframework.tests.sample.beans.TestBean)1