shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.walker.tcp;
 
import com.walker.tcp.handler.AbstractStringHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
 
import java.util.Map;
import java.util.TreeMap;
 
/**
 * 集中存放系统定义的所有<code>Request</code>对象。</p>
 * @author 时克英
 * @date 2018-11-27
 *
 */
public class RequestPostProcessor implements BeanPostProcessor {
 
    private final transient Logger logger = LoggerFactory.getLogger(getClass());
 
    private static final Map<String, String> reference = new TreeMap<String, String>();
 
//    private static List<ProtocolResolver> cacheList =null;
 
//    private final InnerComparator comparator = new InnerComparator();
 
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName)
            throws BeansException {
        if(ServerHandler.class.isAssignableFrom(bean.getClass())){
            AbstractStringHandler pr = (AbstractStringHandler)bean;
            reference.putAll(pr.getMapper());
            logger.info("找到了一个ServerHandler:" + pr.getClass().getName());
        }
 
        return bean;
    }
 
    /**
     * 根据数据协议编号,查找要处理该业务的action实例。</p>
     *
     * @param protocolNum
     * @return
     */
    public static final String getAction(String protocolNum){
        if(reference.size() == 0){
            throw new IllegalArgumentException("未配置任何request对象");
        }
 
        String action = reference.get(protocolNum);
        if(action == null){
            throw new IllegalArgumentException("未找到定义的request实现类,protocolNum = " + protocolNum);
        }
        return action;
    }
 
    /**
     * 返回所有requestNum和action类名称对应关系
     * @return
     */
    public static final Map<String, String> getActionList(){
        return reference;
    }
}