Example usage for org.springframework.aop.support DefaultPointcutAdvisor DefaultPointcutAdvisor

List of usage examples for org.springframework.aop.support DefaultPointcutAdvisor DefaultPointcutAdvisor

Introduction

In this page you can find the example usage for org.springframework.aop.support DefaultPointcutAdvisor DefaultPointcutAdvisor.

Prototype

public DefaultPointcutAdvisor(Pointcut pointcut, Advice advice) 

Source Link

Document

Create a DefaultPointcutAdvisor, specifying Pointcut and Advice.

Usage

From source file:com.github.wnameless.tagwall.aop.TagwallAspectConfig.java

@Bean
public Advisor crudRepositoryDeleteIterableAdvisor() {
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(/*from  w  w  w  .ja  va2s. co m*/
            "execution(public void org.springframework.data.repository.CrudRepository+.delete(Iterable))");

    return new DefaultPointcutAdvisor(pointcut, new MethodInterceptor() {

        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
            invocation.proceed();

            List<Serializable> thingIds = newArrayList();
            Class<?> thingType = null;
            Iterable<?> entities = (Iterable<?>) invocation.getArguments()[0];
            for (Object entity : entities) {
                if (entity != null) {
                    thingType = entity.getClass();
                    thingIds.add(getId(entity));
                }
            }
            removeTags(thingType.getName(), thingIds);

            return null;
        }

    });
}

From source file:br.com.teste.spring.security.config.AppConfig.java

@Bean
public Advisor traceAdvisor() {
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(POINTCUT_EXECUTION_REPOSITORY);
    return new DefaultPointcutAdvisor(pointcut, interceptor());
}

From source file:org.lexevs.dao.database.service.error.ErrorCallbackDatabaseServiceFactory.java

/**
 * Gets the error callback database service.
 * //from w w  w. java2  s .  c o  m
 * @param databaseService the database service
 * @param callback the callback
 * 
 * @return the error callback database service
 */
@SuppressWarnings("unchecked")
public <T> T getErrorCallbackDatabaseService(T databaseService, ErrorCallbackListener callback) {
    ErrorHandlingService serviceAnnotation = AnnotationUtils.findAnnotation(databaseService.getClass(),
            ErrorHandlingService.class);

    if (serviceAnnotation == null) {
        throw new RuntimeException(
                "Class: " + databaseService.getClass().getName() + " is not an Error Handling Service.");
    }

    ProxyFactory pf = new ProxyFactory(databaseService);

    pf.setProxyTargetClass(true);
    ErrorCallbackInterceptor interceptor = new ErrorCallbackInterceptor(callback);

    if (serviceAnnotation.matchAllMethods()) {
        pf.addAdvice(interceptor);
    } else {
        AnnotationMatchingPointcut pointcut = new AnnotationMatchingPointcut(null,
                DatabaseErrorIdentifier.class);
        Advisor advisor = new DefaultPointcutAdvisor(pointcut, interceptor);
        pf.addAdvisor(advisor);

        Class<?>[] annotationClasses = serviceAnnotation.matchAnnotatedMethods();

        if (!ArrayUtils.isEmpty(annotationClasses)) {
            for (Class clazz : annotationClasses) {
                AnnotationMatchingPointcut methodAnnotationPointcuts = new AnnotationMatchingPointcut(
                        ErrorHandlingService.class, clazz);
                pf.addAdvisor(new DefaultPointcutAdvisor(methodAnnotationPointcuts, interceptor));
            }
        }
    }

    Object obj = pf.getProxy();
    return (T) obj;
}