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

org.shoulder.code.ValidateCodeProcessorHolder Maven / Gradle / Ivy

The newest version!
package org.shoulder.code;

import org.shoulder.code.processor.ValidateCodeProcessor;
import org.shoulder.code.exception.NoSuchValidateCodeProcessorException;
import org.shoulder.code.exception.ValidateCodeAuthenticationException;
import org.springframework.beans.factory.InitializingBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 提供处理器
 * @author lym
 */
public class ValidateCodeProcessorHolder implements InitializingBean {

	/** 所有的验证码处理器 */
	private List allProcessors;

	private Map processorMap;

	public ValidateCodeProcessorHolder(List allProcessors) {
		this.allProcessors = allProcessors;
	}

	/**
	 * 获取验证码处理器
	 * @throws ValidateCodeAuthenticationException 没有对应的验证码处理器
	 */
	public ValidateCodeProcessor getProcessor(String type) throws NoSuchValidateCodeProcessorException {
		ValidateCodeProcessor processor = processorMap.get(type);
		if (processor == null) {
			// "ValidateCodeProcessor(type) not exist."
			throw new NoSuchValidateCodeProcessorException("not support such validateCode(" + type + ")");
		}
		return processor;
	}


	@Override
	public void afterPropertiesSet() {
		processorMap = new HashMap<>(allProcessors.size());
		for (ValidateCodeProcessor processor : allProcessors){
			processorMap.put(processor.getType(), processor);
		}
	}

	public List getAllProcessors() {
		return allProcessors;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy