package com.ag.secp.platform.microkernel;

import com.ag.secp.platform.spring.BeanMange;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by yangxh on 2019/5/22.
 */
public class ReflectServerMethod {
    private static Log log = LogFactory.getLog(ReflectServerMethod.class);

    public static void isReflect(String className, String methodName, HttpServletRequest request, HttpServletResponse response) throws Exception {
        //有可能在扩展工程中
        BeanMange beanMange = new BeanMange();
        beanMange.bean = className.substring(className.lastIndexOf(".")+1, className.length());
        beanMange.method = methodName;
        beanMange.request = request;
        beanMange.response = response;
        beanMange.execute();
    }

    /**
     * 判断className是否在主工程, 是返回true
     * @param name
     * @return
     */
    public static boolean isPresent(String name) {
        try {
            Thread.currentThread().getContextClassLoader().loadClass(name);
            return true;
        } catch (ClassNotFoundException e) {
            return false;
        }
    }


}
