package cn.com.qmth.stmms.biz.api.auth.service.validator;

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

import org.springframework.stereotype.Service;

import cn.com.qmth.stmms.biz.api.auth.interfaces.AuthValidator;

@Service("authValidateService")
public class AuthValidateService {

    private Map<String, AuthValidator> map = new HashMap<String, AuthValidator>();

    public List<AuthValidator> getValidators(String[] names) {
        List<AuthValidator> list = new LinkedList<AuthValidator>();
        list.add(getValidator("default"));

        if (names != null && names.length > 0) {
            for (String name : names) {
                AuthValidator v = getValidator(name);
                if (v != null) {
                    list.add(v);
                }
            }
        }
        return list;
    }

    public AuthValidator getValidator(String name) {
        return map.get(name);
    }

    protected void addValidator(AuthValidator validator) {
        if (validator != null) {
            map.put(validator.getName(), validator);
        }
    }
}
