From 29b7757b7e89bb6363d41f7cf01727dd1fec1e52 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 23 Oct 2024 11:26:16 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=B7=A5=E5=8E=82?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=AD=E9=80=9A=E8=BF=87=E5=85=A8=E7=B1=BB?= =?UTF-8?q?=E5=90=8D=E8=8E=B7=E5=8F=96=E7=BB=84=E4=BB=B6=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87=E7=B1=BB?= =?UTF-8?q?=E5=90=8D=E8=8E=B7=E5=8F=96=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1273774249312256]工厂模式中通过全类名获取组件时,扩展支持通过类名获取组件 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1273774249312256 --- .../core/NotifyPolicyHandlerFactory.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/neatlogic/framework/notify/core/NotifyPolicyHandlerFactory.java b/src/main/java/neatlogic/framework/notify/core/NotifyPolicyHandlerFactory.java index 509ed0b45..431fcbdfa 100644 --- a/src/main/java/neatlogic/framework/notify/core/NotifyPolicyHandlerFactory.java +++ b/src/main/java/neatlogic/framework/notify/core/NotifyPolicyHandlerFactory.java @@ -53,11 +53,24 @@ public class NotifyPolicyHandlerFactory extends ModuleInitializedListenerBase { private static final Map handler2ModuleIdMap = new HashMap<>(); public static INotifyPolicyHandler getHandler(String handler) { - return notifyPolicyHandlerMap.get(handler); + INotifyPolicyHandler notifyPolicyHandler = notifyPolicyHandlerMap.get(handler); + if (notifyPolicyHandler == null) { + int index = handler.lastIndexOf("."); + notifyPolicyHandler = notifyPolicyHandlerMap.get(handler.substring(index + 1)); + } + return notifyPolicyHandler; } public static List getHandlerList() { - return new ArrayList<>(notifyPolicyHandlerMap.values()); + List resultList = new ArrayList<>(); + for (Map.Entry entry : notifyPolicyHandlerMap.entrySet()) { + INotifyPolicyHandler notifyPolicyHandler = entry.getValue(); + if (resultList.contains(notifyPolicyHandler)) { + continue; + } + resultList.add(notifyPolicyHandler); + } + return resultList; } public static String getModuleIdByHandler(String handler) { @@ -164,9 +177,12 @@ public class NotifyPolicyHandlerFactory extends ModuleInitializedListenerBase { if (StringUtils.isBlank(moduleGroup)) { moduleGroup = moduleVo.getGroup(); } - notifyPolicyHandlerMap.put(notifyPolicyHandler.getClassName(), notifyPolicyHandler); - handler2ModuleGroupIdMap.put(notifyPolicyHandler.getClassName(), moduleGroup); - handler2ModuleIdMap.put(notifyPolicyHandler.getClassName(), moduleVo.getId()); + String className = notifyPolicyHandler.getClassName(); + int index = className.lastIndexOf("."); + notifyPolicyHandlerMap.put(className.substring(index + 1), notifyPolicyHandler); + notifyPolicyHandlerMap.put(className, notifyPolicyHandler); + handler2ModuleGroupIdMap.put(className, moduleGroup); + handler2ModuleIdMap.put(className, moduleVo.getId()); // notifyPolicyHandlerList.add(new NotifyPolicyHandlerVo(notifyPolicyHandler.getClassName(), notifyPolicyHandler.getName(), notifyPolicyHandler.getAuthName(), moduleVo.getId(), moduleVo.getGroup(), notifyPolicyHandler.isAllowMultiPolicy())); // INotifyPolicyHandlerGroup notifyPolicyHandlerGroup = notifyPolicyHandler.getGroup(); -- Gitee