SourceUtil.java 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.sckw.excel.translate;
  2. import com.sckw.core.exception.SourceInitializeException;
  3. import lombok.extern.slf4j.Slf4j;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. /**
  7. *
  8. * 数据源工具类
  9. *
  10. *
  11. * @author lfdc
  12. * @version v1
  13. * @create 2020-11-28 16:33:14
  14. * @copyright
  15. */
  16. @Slf4j
  17. //@Component
  18. //@Configuration
  19. public class SourceUtil {
  20. public static Map<com.sckw.excel.translate.enums.Source,
  21. com.sckw.excel.translate.context.Source> SOURCES_INSTANCE = new HashMap<>(2);
  22. public static void put(com.sckw.excel.translate.enums.Source source,
  23. com.sckw.excel.translate.context.Source instance) {
  24. SOURCES_INSTANCE.put(source, instance);
  25. }
  26. public static void remove(com.sckw.excel.translate.enums.Source source) {
  27. SOURCES_INSTANCE.remove(source);
  28. }
  29. public static void clear() {
  30. for (com.sckw.excel.translate.enums.Source source : SOURCES_INSTANCE.keySet()) {
  31. SOURCES_INSTANCE.get(source).clear();
  32. }
  33. }
  34. static Map<Integer, Object> get(com.sckw.excel.translate.enums.Source source) throws SourceInitializeException {
  35. try {
  36. return SOURCES_INSTANCE.get(source).get();
  37. } catch (Exception e) {
  38. log.error("failed to get data source, ex:{}", e.toString());
  39. throw e;
  40. }
  41. }
  42. }