hefeixia
2021-02-18 5b8c95c760840f09910730943b21391e47187315
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
package frame.object.dao;
 
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
 
public abstract class MethodPublisher {
 
    protected Map<String, Method> methodMap;
    protected Map<String, Method> allMethodMap;
    
    
    public MethodPublisher() {
        methodMap = new HashMap<String, Method>();
        allMethodMap = new HashMap<String, Method>();
 
        collectMethod();
        publishMethod();
    }
    
    public Method getMethod(String lower) {
        // TODO Auto-generated method stub
        return null;
    }
 
    protected void collectMethod() {
        Method[] methods = this.getClass().getDeclaredMethods();
 
        for (Method one : methods) {
            allMethodMap.put(one.getName().toLowerCase(), one);
        }
    }
 
    protected abstract void publishMethod();
 
    protected void addMethod(String name) {
        if (name == null) {
            return;
        }
 
        name = name.toLowerCase();
        Method method = allMethodMap.get(name);
 
        if (method != null) {
            method.setAccessible(true);
            methodMap.put(name, method);
        }
    }
 
    public Map<String, Method> getMethodMap() {
        return methodMap;
    }
    
}