package chat.server.call;
|
|
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 addOneMethod(String name) {
|
addOneMethod(name, name);
|
}
|
|
protected void addOneMethod(String methodName, String key) {
|
if (key == null || methodName == null) {
|
return;
|
}
|
|
methodName = methodName.toLowerCase();
|
Method method = allMethodMap.get(methodName);
|
|
if (method != null) {
|
key = key.toLowerCase();
|
|
method.setAccessible(true);
|
methodMap.put(key, method);
|
}
|
}
|
|
protected Method getOneMethod(String key) {
|
if (key == null) {
|
return null;
|
}
|
|
key = key.toLowerCase();
|
Method method = methodMap.get(key);
|
|
return method;
|
}
|
|
public Map<String, Method> getMethodMap() {
|
return methodMap;
|
}
|
|
}
|