|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -20,6 +20,7 @@ import org.aopalliance.aop.Advice; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aop.ClassFilter; |
|
|
|
import org.springframework.aop.ClassFilter; |
|
|
|
import org.springframework.aop.IntroductionAdvisor; |
|
|
|
import org.springframework.aop.IntroductionAdvisor; |
|
|
|
|
|
|
|
import org.springframework.aop.IntroductionInterceptor; |
|
|
|
import org.springframework.aop.support.ClassFilters; |
|
|
|
import org.springframework.aop.support.ClassFilters; |
|
|
|
import org.springframework.aop.support.DelegatePerTargetObjectIntroductionInterceptor; |
|
|
|
import org.springframework.aop.support.DelegatePerTargetObjectIntroductionInterceptor; |
|
|
|
import org.springframework.aop.support.DelegatingIntroductionInterceptor; |
|
|
|
import org.springframework.aop.support.DelegatingIntroductionInterceptor; |
|
|
|
@ -34,12 +35,12 @@ import org.springframework.aop.support.DelegatingIntroductionInterceptor; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class DeclareParentsAdvisor implements IntroductionAdvisor { |
|
|
|
public class DeclareParentsAdvisor implements IntroductionAdvisor { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Advice advice; |
|
|
|
|
|
|
|
|
|
|
|
private final Class<?> introducedInterface; |
|
|
|
private final Class<?> introducedInterface; |
|
|
|
|
|
|
|
|
|
|
|
private final ClassFilter typePatternClassFilter; |
|
|
|
private final ClassFilter typePatternClassFilter; |
|
|
|
|
|
|
|
|
|
|
|
private final Advice advice; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new advisor for this DeclareParents field. |
|
|
|
* Create a new advisor for this DeclareParents field. |
|
|
|
@ -48,8 +49,8 @@ public class DeclareParentsAdvisor implements IntroductionAdvisor { |
|
|
|
* @param defaultImpl the default implementation class
|
|
|
|
* @param defaultImpl the default implementation class
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> defaultImpl) { |
|
|
|
public DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> defaultImpl) { |
|
|
|
this(interfaceType, typePattern, defaultImpl, |
|
|
|
this(interfaceType, typePattern, |
|
|
|
new DelegatePerTargetObjectIntroductionInterceptor(defaultImpl, interfaceType)); |
|
|
|
new DelegatePerTargetObjectIntroductionInterceptor(defaultImpl, interfaceType)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -59,8 +60,7 @@ public class DeclareParentsAdvisor implements IntroductionAdvisor { |
|
|
|
* @param delegateRef the delegate implementation object |
|
|
|
* @param delegateRef the delegate implementation object |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Object delegateRef) { |
|
|
|
public DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Object delegateRef) { |
|
|
|
this(interfaceType, typePattern, delegateRef.getClass(), |
|
|
|
this(interfaceType, typePattern, new DelegatingIntroductionInterceptor(delegateRef)); |
|
|
|
new DelegatingIntroductionInterceptor(delegateRef)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -68,18 +68,16 @@ public class DeclareParentsAdvisor implements IntroductionAdvisor { |
|
|
|
* (cannot use method such as init() to share common code, due the use of final fields) |
|
|
|
* (cannot use method such as init() to share common code, due the use of final fields) |
|
|
|
* @param interfaceType static field defining the introduction |
|
|
|
* @param interfaceType static field defining the introduction |
|
|
|
* @param typePattern type pattern the introduction is restricted to |
|
|
|
* @param typePattern type pattern the introduction is restricted to |
|
|
|
* @param implementationClass implementation class
|
|
|
|
* @param interceptor the delegation advice as {@link IntroductionInterceptor} |
|
|
|
* @param advice delegation advice |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> implementationClass, Advice advice) { |
|
|
|
private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, IntroductionInterceptor interceptor) { |
|
|
|
|
|
|
|
this.advice = interceptor; |
|
|
|
this.introducedInterface = interfaceType; |
|
|
|
this.introducedInterface = interfaceType; |
|
|
|
ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Excludes methods implemented.
|
|
|
|
// Excludes methods implemented.
|
|
|
|
ClassFilter exclusion = clazz -> !(introducedInterface.isAssignableFrom(clazz)); |
|
|
|
ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern); |
|
|
|
|
|
|
|
ClassFilter exclusion = (clazz -> !introducedInterface.isAssignableFrom(clazz)); |
|
|
|
this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion); |
|
|
|
this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion); |
|
|
|
this.advice = advice; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|