use of org.springframework.aop.aspectj.AspectJAroundAdvice in project uPortal by Jasig.
the class AspectJAroundAdviceFactory method createInstance.
@Override
protected AspectJAroundAdvice createInstance() throws Exception {
final Class<? extends Object> aspectType = this.aspect.getClass();
final Method method = ReflectionUtils.findMethod(aspectType, this.method, this.args);
final SingletonAspectInstanceFactory aif = new SingletonAspectInstanceFactory(this.aspect);
return new AspectJAroundAdvice(method, pointcut, aif);
}
use of org.springframework.aop.aspectj.AspectJAroundAdvice in project spring-framework by spring-projects.
the class ReflectiveAspectJAdvisorFactory method getAdvice.
@Override
public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName) {
Class<?> candidateAspectClass = aspectInstanceFactory.getAspectMetadata().getAspectClass();
validate(candidateAspectClass);
AspectJAnnotation<?> aspectJAnnotation = AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(candidateAdviceMethod);
if (aspectJAnnotation == null) {
return null;
}
// Check that it's an AspectJ-annotated class
if (!isAspect(candidateAspectClass)) {
throw new AopConfigException("Advice must be declared inside an aspect type: " + "Offending method '" + candidateAdviceMethod + "' in class [" + candidateAspectClass.getName() + "]");
}
if (logger.isDebugEnabled()) {
logger.debug("Found AspectJ method: " + candidateAdviceMethod);
}
AbstractAspectJAdvice springAdvice;
switch(aspectJAnnotation.getAnnotationType()) {
case AtBefore:
springAdvice = new AspectJMethodBeforeAdvice(candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
break;
case AtAfter:
springAdvice = new AspectJAfterAdvice(candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
break;
case AtAfterReturning:
springAdvice = new AspectJAfterReturningAdvice(candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
AfterReturning afterReturningAnnotation = (AfterReturning) aspectJAnnotation.getAnnotation();
if (StringUtils.hasText(afterReturningAnnotation.returning())) {
springAdvice.setReturningName(afterReturningAnnotation.returning());
}
break;
case AtAfterThrowing:
springAdvice = new AspectJAfterThrowingAdvice(candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
AfterThrowing afterThrowingAnnotation = (AfterThrowing) aspectJAnnotation.getAnnotation();
if (StringUtils.hasText(afterThrowingAnnotation.throwing())) {
springAdvice.setThrowingName(afterThrowingAnnotation.throwing());
}
break;
case AtAround:
springAdvice = new AspectJAroundAdvice(candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
break;
case AtPointcut:
if (logger.isDebugEnabled()) {
logger.debug("Processing pointcut '" + candidateAdviceMethod.getName() + "'");
}
return null;
default:
throw new UnsupportedOperationException("Unsupported advice type on method: " + candidateAdviceMethod);
}
// Now to configure the advice...
springAdvice.setAspectName(aspectName);
springAdvice.setDeclarationOrder(declarationOrder);
String[] argNames = this.parameterNameDiscoverer.getParameterNames(candidateAdviceMethod);
if (argNames != null) {
springAdvice.setArgumentNamesFromStringArray(argNames);
}
springAdvice.calculateArgumentBindings();
return springAdvice;
}
use of org.springframework.aop.aspectj.AspectJAroundAdvice in project uPortal by Jasig.
the class AspectJExpressionTest method testProgramaticPointcut.
@Test
public void testProgramaticPointcut() {
final RepositoryPointcutInterface targetPointcutInterface = new RepositoryPointcutInterfaceImpl();
final AspectJProxyFactory portletPreferencesProxyFactory = new AspectJProxyFactory(targetPointcutInterface);
final Method interceptorMethod = ReflectionUtils.findMethod(CountingMethodInterceptor.class, "countInvocation", ProceedingJoinPoint.class);
final AspectJAroundAdvice aspectJAroundAdvice = new AspectJAroundAdvice(interceptorMethod, repositoryPointcutInterfaceExecutionPointcut, new SingletonAspectInstanceFactory(this.countingMethodInterceptor));
portletPreferencesProxyFactory.addAdvice(aspectJAroundAdvice);
final RepositoryPointcutInterface proxiedPointcutInterface = (RepositoryPointcutInterface) portletPreferencesProxyFactory.getProxy();
assertEquals(0, countingMethodInterceptor.getCount());
proxiedPointcutInterface.methodOne("test");
assertEquals(1, countingMethodInterceptor.getCount());
proxiedPointcutInterface.methodOne("test");
assertEquals(2, countingMethodInterceptor.getCount());
}
Aggregations