package com.sckw.excel.translate; import com.sckw.core.exception.SourceInitializeException; import lombok.extern.slf4j.Slf4j; import java.util.HashMap; import java.util.Map; /** * * 数据源工具类 * * * @author lfdc * @version v1 * @create 2020-11-28 16:33:14 * @copyright */ @Slf4j //@Component //@Configuration public class SourceUtil { public static Map SOURCES_INSTANCE = new HashMap<>(2); public static void put(com.sckw.excel.translate.enums.Source source, com.sckw.excel.translate.context.Source instance) { SOURCES_INSTANCE.put(source, instance); } public static void remove(com.sckw.excel.translate.enums.Source source) { SOURCES_INSTANCE.remove(source); } public static void clear() { for (com.sckw.excel.translate.enums.Source source : SOURCES_INSTANCE.keySet()) { SOURCES_INSTANCE.get(source).clear(); } } static Map get(com.sckw.excel.translate.enums.Source source) throws SourceInitializeException { try { return SOURCES_INSTANCE.get(source).get(); } catch (Exception e) { log.error("failed to get data source, ex:{}", e.toString()); throw e; } } }