package nckd.jimin.jyyy.bd.servicehelper;

import kd.bos.dataentity.TypesContainer;
import kd.bos.dataentity.resource.ResManager;

import java.util.HashMap;
import java.util.Map;

public class ServiceFactory {
    private static Map<String, String> serviceMap = new HashMap();

    public ServiceFactory() {

    }

    public static <T> T getService(Class<T> clazz) {
        return (T) getService(clazz.getSimpleName());
    }

    public static void putService(String serviceName, String serviceImpl) {
        serviceMap.put(serviceName, serviceImpl);
    }

    public static Object getService(String serviceName) {
        String className = (String)serviceMap.get(serviceName);
        if (className == null) {
            throw new RuntimeException(String.format(ResManager.loadKDString("%s对应的服务实现未找到", "ServiceFactory_0", "jkjt-tmc-servicehelper", new Object[0]), serviceName));
        } else {
            return TypesContainer.getOrRegisterSingletonInstance(className);
        }
    }

    static {
        serviceMap.put("SaveTravleLogService", "nckd.jimin.jyyy.bd.mservice.SaveTravleLogServiceImpl");
    }
}
