package cn.cslg.pas.common.utils.handler;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

public class DataProcessHandler {
    public interface IProcessData {
        Object processData(Object data, Object code);
    }

    public DataProcessHandler() {
    }

    public static Object getData(String typeName, String jarOrClassPath) {

        if (jarOrClassPath != null) {
            try {
                //用路径创建Url
                URL url = new URL("file:" + jarOrClassPath);
                //通过Url加载外部的jar包
                URLClassLoader urlClassLoader = new URLClassLoader(new URL[]{url});
                Class<?> clazz = urlClassLoader.loadClass(typeName);
                return clazz.newInstance();
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | MalformedURLException e) {
                e.printStackTrace();
            }
        } else {
            try {
                return Class.forName(typeName).newInstance();
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println("启动成功");
    }

}




