1 16 17 package org.springframework.aop.aspectj; 18 19 import org.aopalliance.aop.Advice; 20 21 import org.springframework.aop.ClassFilter; 22 import org.springframework.aop.IntroductionAdvisor; 23 import org.springframework.aop.support.ClassFilters; 24 import org.springframework.aop.support.DelegatePerTargetObjectIntroductionInterceptor; 25 26 33 public class DeclareParentsAdvisor implements IntroductionAdvisor { 34 35 private final Class introducedInterface; 36 37 private final ClassFilter typePatternClassFilter; 38 39 private final Advice advice; 40 41 42 48 public DeclareParentsAdvisor(Class interfaceType, String typePattern, Class defaultImpl) { 49 this.introducedInterface = interfaceType; 50 ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern); 51 52 ClassFilter exclusion = new ClassFilter() { 54 public boolean matches(Class clazz) { 55 return !(introducedInterface.isAssignableFrom(clazz)); 56 } 57 }; 58 59 this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion); 60 this.advice = new DelegatePerTargetObjectIntroductionInterceptor(defaultImpl, interfaceType); 61 } 62 63 64 public ClassFilter getClassFilter() { 65 return this.typePatternClassFilter; 66 } 67 68 public void validateInterfaces() throws IllegalArgumentException { 69 } 71 72 public boolean isPerInstance() { 73 return true; 74 } 75 76 public Advice getAdvice() { 77 return advice; 78 } 79 80 public Class [] getInterfaces() { 81 return new Class [] {this.introducedInterface}; 82 } 83 84 } 85 | Popular Tags |