public SyntheticInstantiationAdvisor(final MetadataAwareAspectInstanceFactory aif) { super(aif.getAspectMetadata().getPerClausePointcut(), (MethodBeforeAdvice) (method, args, target) -> aif.getAspectInstance()); } }
/** * Create a new BeanFactoryAspectJAdvisorsBuilder for the given BeanFactory. * @param beanFactory the ListableBeanFactory to scan */ public BeanFactoryAspectJAdvisorsBuilder(ListableBeanFactory beanFactory) { this(beanFactory, new ReflectiveAspectJAdvisorFactory(beanFactory)); }
@Override public boolean isBeforeAdvice() { if (this.isBeforeAdvice == null) { determineAdviceType(); } return this.isBeforeAdvice; }
@Test public void testWithSimpleAspect() throws Exception { TestBean bean = new TestBean(); bean.setAge(2); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(bean); proxyFactory.addAspect(MultiplyReturnValue.class); ITestBean proxy = proxyFactory.getProxy(); assertEquals("Multiplication did not occur", bean.getAge() * 2, proxy.getAge()); }
@Test(expected = IllegalStateException.class) public void testAnnotationArgumentNameBinding() { TransactionalBean tb = new TransactionalBean(); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb); proxyFactory.addAspect(PointcutWithAnnotationArgument.class); ITransactionalBean proxiedTestBean = proxyFactory.getProxy(); proxiedTestBean.doInTransaction(); }
@Test // SPR-13328 @SuppressWarnings("unchecked") public void testUnproxiedVarargsWithEnumArray() throws Exception { AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean()); proxyFactory.addAspect(LoggingAspectOnSetter.class); ITestBean proxy = proxyFactory.getProxy(); assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)); }
@Override @Nullable public Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrderInAspect, String aspectName) { validate(aspectInstanceFactory.getAspectMetadata().getAspectClass()); AspectJExpressionPointcut expressionPointcut = getPointcut( candidateAdviceMethod, aspectInstanceFactory.getAspectMetadata().getAspectClass()); if (expressionPointcut == null) { return null; } return new InstantiationModelAwarePointcutAdvisorImpl(expressionPointcut, candidateAdviceMethod, this, aspectInstanceFactory, declarationOrderInAspect, aspectName); }
@Test(expected = IllegalArgumentException.class) public void testWithInstanceWithNonAspect() throws Exception { AspectJProxyFactory pf = new AspectJProxyFactory(); pf.addAspect(new TestBean()); }
@Test(expected = IllegalArgumentException.class) public void testDeclarePrecedenceNotSupported() { TestBean target = new TestBean(); MetadataAwareAspectInstanceFactory aspectInstanceFactory = new SingletonMetadataAwareAspectInstanceFactory( new DeclarePrecedenceShouldSucceed(), "someBean"); createProxy(target, getFixture().getAdvisors(aspectInstanceFactory), ITestBean.class); }
/** * Return whether the aspect needs to be lazily instantiated. */ public boolean isLazilyInstantiated() { return (isPerThisOrPerTarget() || isPerTypeWithin()); }
/** * Create a new SimpleMetadataAwareAspectInstanceFactory for the given aspect class. * @param aspectClass the aspect class * @param aspectName the aspect name */ public SimpleMetadataAwareAspectInstanceFactory(Class<?> aspectClass, String aspectName) { super(aspectClass); this.metadata = new AspectMetadata(aspectClass, aspectName); }
/** * We consider something to be an AspectJ aspect suitable for use by the Spring AOP system * if it has the @Aspect annotation, and was not compiled by ajc. The reason for this latter test * is that aspects written in the code-style (AspectJ language) also have the annotation present * when compiled by ajc with the -1.5 flag, yet they cannot be consumed by Spring AOP. */ @Override public boolean isAspect(Class<?> clazz) { return (hasAspectAnnotation(clazz) && !compiledByAjc(clazz)); }
/** * Create a new {@code AspectJProxyFactory}. * No target, only interfaces. Must add interceptors. */ public AspectJProxyFactory(Class<?>... interfaces) { setInterfaces(interfaces); }
private Advice instantiateAdvice(AspectJExpressionPointcut pointcut) { Advice advice = this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pointcut, this.aspectInstanceFactory, this.declarationOrder, this.aspectName); return (advice != null ? advice : EMPTY_ADVICE); }
/** * Lazily instantiate advice if necessary. */ @Override public synchronized Advice getAdvice() { if (this.instantiatedAdvice == null) { this.instantiatedAdvice = instantiateAdvice(this.declaredPointcut); } return this.instantiatedAdvice; }
/** * Return the AspectJ AspectMetadata for this advisor. */ public AspectMetadata getAspectMetadata() { return this.aspectInstanceFactory.getAspectMetadata(); }
@Override protected boolean isEligibleBean(String beanName) { return AnnotationAwareAspectJAutoProxyCreator.this.isEligibleAspectBean(beanName); } }
@Override @Transactional public void doInTransaction() { } }
@Override public Object getAspectInstance() { ++this.count; return new PerTypeWithinAspect(); }
@Override public boolean isAfterAdvice() { if (this.isAfterAdvice == null) { determineAdviceType(); } return this.isAfterAdvice; }