src/main/java/de/uapcore/lightpit/ModuleManager.java

changeset 45
cc7f082c5ef3
parent 36
0f4f8f255c32
child 57
1262b5433644
equal deleted inserted replaced
44:835dd169642a 45:cc7f082c5ef3
34 import javax.servlet.Registration; 34 import javax.servlet.Registration;
35 import javax.servlet.ServletContext; 35 import javax.servlet.ServletContext;
36 import javax.servlet.ServletContextEvent; 36 import javax.servlet.ServletContextEvent;
37 import javax.servlet.ServletContextListener; 37 import javax.servlet.ServletContextListener;
38 import javax.servlet.annotation.WebListener; 38 import javax.servlet.annotation.WebListener;
39 import java.util.*; 39 import java.util.ArrayList;
40 import java.util.Collections;
41 import java.util.List;
42 import java.util.Optional;
40 43
41 /** 44 /**
42 * Scans registered servlets for LightPIT modules. 45 * Scans registered servlets for LightPIT modules.
43 */ 46 */
44 @WebListener 47 @WebListener
53 private ServletContext sc; 56 private ServletContext sc;
54 57
55 /** 58 /**
56 * Maps class names to module information. 59 * Maps class names to module information.
57 */ 60 */
58 private final Map<String, LightPITModule> registeredModules = new HashMap<>(); 61 private final List<LightPITModule> registeredModules = new ArrayList<>();
59 62
60 /** 63 /**
61 * Contains the menu entries for the loaded modules. 64 * Contains the menu entries for the loaded modules.
62 */ 65 */
63 private final List<MenuEntry> mainMenu = new ArrayList<>(); 66 private final List<MenuEntry> mainMenu = new ArrayList<>();
112 } 115 }
113 116
114 private void handleServletRegistration(String name, Registration reg) { 117 private void handleServletRegistration(String name, Registration reg) {
115 final Optional<LightPITModule> moduleInfo = getModuleInfo(reg); 118 final Optional<LightPITModule> moduleInfo = getModuleInfo(reg);
116 if (moduleInfo.isPresent()) { 119 if (moduleInfo.isPresent()) {
117 registeredModules.put(reg.getClassName(), moduleInfo.get()); 120 registeredModules.add(moduleInfo.get());
118 LOG.info("Module detected: {}", name); 121 LOG.info("Module detected: {}", name);
119 } else { 122 } else {
120 LOG.debug("Servlet {} is no module, skipping.", name); 123 LOG.debug("Servlet {} is no module, skipping.", name);
121 } 124 }
122 } 125 }
143 /** 146 /**
144 * Populates the main menu based on the registered modules. 147 * Populates the main menu based on the registered modules.
145 */ 148 */
146 private void createMainMenu() { 149 private void createMainMenu() {
147 mainMenu.clear(); 150 mainMenu.clear();
148 registeredModules.entrySet() 151 registeredModules
149 .stream() 152 .stream()
150 .filter(mod -> !mod.getValue().systemModule()) 153 .filter(mod -> !mod.systemModule())
151 .map(mod -> new MenuEntry( 154 .map(mod -> new MenuEntry(
152 mod.getKey(),
153 new ResourceKey( 155 new ResourceKey(
154 mod.getValue().bundleBaseName(), 156 mod.bundleBaseName(),
155 mod.getValue().menuKey()), 157 mod.menuKey()),
156 mod.getValue().modulePath(), 158 mod.modulePath(),
157 mod.getValue().defaultPriority())) 159 mod.defaultPriority()))
158 .sorted() 160 .sorted()
159 .forEachOrdered(mainMenu::add); 161 .forEachOrdered(mainMenu::add);
160 } 162 }
161 163
162 /** 164 /**

mercurial