/** * Adds a declare parents pointcut - spr5307 * @author Andy Clement * @since 3.0 */ @Aspect class MakeAnnotatedTypeModifiable extends AbstractMakeModifiable { @DeclareParents(value = "(@org.springframework.aop.aspectj.annotation.Measured *)", defaultImpl = DefaultLockable.class) public static Lockable mixin; }
/** * Build a {@link org.springframework.aop.aspectj.DeclareParentsAdvisor} * for the given introduction field. * <p>Resulting Advisors will need to be evaluated for targets. * @param introductionField the field to introspect * @return the Advisor instance, or {@code null} if not an Advisor */ @Nullable private Advisor getDeclareParentsAdvisor(Field introductionField) { DeclareParents declareParents = introductionField.getAnnotation(DeclareParents.class); if (declareParents == null) { // Not an introduction field return null; } if (DeclareParents.class == declareParents.defaultImpl()) { throw new IllegalStateException("'defaultImpl' attribute must be set on DeclareParents"); } return new DeclareParentsAdvisor( introductionField.getType(), declareParents.value(), declareParents.defaultImpl()); }
private void addAnnotationStyleDeclareParents(List<DeclareParents> toList) { for (Field f : clazz.getDeclaredFields()) { if (f.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) { if (!f.getType().isInterface()) continue; org.aspectj.lang.annotation.DeclareParents ann = f.getAnnotation(org.aspectj.lang.annotation.DeclareParents.class); String parentType = f.getType().getName(); DeclareParentsImpl decp = new DeclareParentsImpl( ann.value(), parentType, false, this ); toList.add(decp); } } }
private void addAnnotationStyleITDMethods(List<InterTypeMethodDeclaration> toList, boolean publicOnly) { if (isAspect()) { for (Field f : clazz.getDeclaredFields()) { if (!f.getType().isInterface()) continue; if (f.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) { Class<org.aspectj.lang.annotation.DeclareParents> decPAnnClass = org.aspectj.lang.annotation.DeclareParents.class; org.aspectj.lang.annotation.DeclareParents decPAnn = f.getAnnotation(decPAnnClass); if (decPAnn.defaultImpl() == decPAnnClass) continue; // doesn't contribute members... for (Method itdM : f.getType().getDeclaredMethods()) { if (!Modifier.isPublic(itdM.getModifiers()) && publicOnly) continue; InterTypeMethodDeclaration itdm = new InterTypeMethodDeclarationImpl( this, AjTypeSystem.getAjType(f.getType()), itdM, Modifier.PUBLIC ); toList.add(itdm); } } } } }
/** * Adds a declare parents pointcut. * @author Rod Johnson * @since 2.0 */ @Aspect class MakeITestBeanModifiable extends AbstractMakeModifiable { @DeclareParents(value = "org.springframework.tests.sample.beans.ITestBean+", defaultImpl=ModifiableImpl.class) public static MutableModifiable mixin; }
/** * Build a {@link org.springframework.aop.aspectj.DeclareParentsAdvisor} * for the given introduction field. * <p>Resulting Advisors will need to be evaluated for targets. * @param introductionField the field to introspect * @return the Advisor instance, or {@code null} if not an Advisor */ @Nullable private Advisor getDeclareParentsAdvisor(Field introductionField) { DeclareParents declareParents = introductionField.getAnnotation(DeclareParents.class); if (declareParents == null) { // Not an introduction field return null; } if (DeclareParents.class == declareParents.defaultImpl()) { throw new IllegalStateException("'defaultImpl' attribute must be set on DeclareParents"); } return new DeclareParentsAdvisor( introductionField.getType(), declareParents.value(), declareParents.defaultImpl()); }
/** * Demonstrates introductions, AspectJ annotation style. */ @Aspect class MakeLockable { @DeclareParents(value = "org.springframework..*", defaultImpl = DefaultLockable.class) public static Lockable mixin; @Before(value="execution(void set*(*)) && this(mixin)", argNames="mixin") public void checkNotLocked( Lockable mixin) { // Can also obtain the mixin (this) this way //Lockable mixin = (Lockable) jp.getThis(); if (mixin.locked()) { throw new IllegalStateException(); } } }
/** * Build a {@link org.springframework.aop.aspectj.DeclareParentsAdvisor} * for the given introduction field. * <p>Resulting Advisors will need to be evaluated for targets. * @param introductionField the field to introspect * @return the Advisor instance, or {@code null} if not an Advisor */ private Advisor getDeclareParentsAdvisor(Field introductionField) { DeclareParents declareParents = introductionField.getAnnotation(DeclareParents.class); if (declareParents == null) { // Not an introduction field return null; } if (DeclareParents.class == declareParents.defaultImpl()) { throw new IllegalStateException("'defaultImpl' attribute must be set on DeclareParents"); } return new DeclareParentsAdvisor( introductionField.getType(), declareParents.value(), declareParents.defaultImpl()); }
@Aspect public class EnableSellerAspect { @DeclareParents(value = "com.brianway.learning.spring.aop.aspectj.NaiveWaiter", defaultImpl = SmartSeller.class) public static Seller seller; }
/** * Created by brian on 16/8/18. */ @Aspect public class EnableSellerAspect { @DeclareParents(value = "com.brianway.learning.spring.aop.aspectj.NaiveWaiter", defaultImpl = SmartSeller.class) public Seller seller; }
@Aspect public class ContestantIntroducer { @DeclareParents( //<co id="co_declareParents"/> value = "com.vonzhou.springinaction.springidol.Performer+", defaultImpl = GraciousContestant.class) public static Contestant contestant; }
@Component @Aspect public class UghAspect { @DeclareParents(value="org.cevahir.spring.*ServisiImpl", defaultImpl=DefaultUghImpl.class) public static Ugh ugh; @Before("org.cevahir.spring.CalAspect.orkestraCal() && " + "this(mixin)") public void before(Ugh mixin) { if (mixin instanceof OrkestraServisi) mixin.ugh(); } }