All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.onetwo.common.interceptor.SimpleInterceptorManager Maven / Gradle / Ivy

package org.onetwo.common.interceptor;

import java.util.List;

import org.onetwo.common.spring.SpringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;

import com.google.common.collect.ImmutableList;

public class SimpleInterceptorManager implements InitializingBean {
	
	private List interceptors;
	@Autowired
	private ApplicationContext applicationContext;
	private Class interceptorClass;
	
	public SimpleInterceptorManager(Class interceptorClass) {
		super();
		this.interceptorClass = interceptorClass;
	}

	@Override
	public void afterPropertiesSet() {
		this.interceptors = SpringUtils.getBeans(applicationContext, interceptorClass);
		/*List interceptors = SpringUtils.getBeansWithAnnotation(applicationContext, annotationClass)
													.stream().map(bd -> (Interceptor)bd.getBean())
													.collect(Collectors.toList());*/
		
		AnnotationAwareOrderComparator.sort(interceptors);
		this.interceptors = ImmutableList.copyOf(interceptors);
		
	}

	public List getInterceptors() {
		return interceptors;
	}

	public void setInterceptors(List interceptors) {
		this.interceptors = interceptors;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy