package foundation.handler; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import foundation.util.Util; public abstract class MethodPublisher { protected Map methodMap; protected Map allMethodMap; public MethodPublisher() { methodMap = new HashMap(); allMethodMap = new HashMap(); collectMethod(); publishMethod(); } public Method getMethod(String name) { if (Util.isEmpty(name)) { return null; } name = name.toLowerCase(); return allMethodMap.get(name); } protected void collectMethod() { Method[] methods = this.getClass().getDeclaredMethods(); for (Method one : methods) { Class[] parameters = one.getParameterTypes(); if (!validateMethodParameter(parameters)) { continue; } 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); } } protected boolean validateMethodParameter(Class[] parameters) { return true; } public Map getMethodMap() { return methodMap; } }