Пример #1
0
 /** 查找Module(由Module初始化的子Module不再查找范围内)。 */
 protected Module[] findModules() {
   ArrayList<String> moduleTyleList = new ArrayList<String>();
   Environment env = this.getEnvironment();
   boolean loadModule = env.getSettings().getBoolean("hasor.modules.loadModule", true);
   if (loadModule) {
     List<XmlNode> allModules = env.getSettings().merageXmlNode("hasor.modules", "module");
     for (XmlNode module : allModules) {
       String moduleTypeString = module.getText();
       if (StringUtils.isBlank(moduleTypeString)) {
         continue;
       }
       if (!moduleTyleList.contains(moduleTypeString)) {
         moduleTyleList.add(moduleTypeString);
       }
     }
   }
   //
   ArrayList<Module> moduleList = new ArrayList<Module>();
   for (String modStr : moduleTyleList) {
     try {
       ClassLoader loader = Thread.currentThread().getContextClassLoader();
       Class<?> moduleType = ClassUtils.getClass(loader, modStr);
       moduleList.add((Module) moduleType.newInstance());
     } catch (Throwable e) {
       logger.warn(
           "load module Type {} is failure. -> {}:{}", modStr, e.getClass(), e.getMessage());
       if (this.getEnvironment().isDebug()) logger.error(e.getMessage(), e);
     }
   }
   return moduleList.toArray(new Module[moduleList.size()]);
 }
Пример #2
0
 /*从构造方法中注入 AppContext 接口对象*/
 @Inject
 public MenuServices(AppContext appContext) {
   this.menuList = new ArrayList<MenuBean>();
   /*获取操纵配置文件的接口*/
   Settings setting = appContext.getSettings();
   /*取得‘/demoProject/menus’ Xml节点*/
   XmlNode xmlNode = setting.getXmlNode("demoProject.menus");
   /*使用 DOM 方式解析 Xml节点*/
   List<XmlNode> menus = xmlNode.getChildren("menu");
   for (XmlNode node : menus) {
     MenuBean menuBean = new MenuBean();
     menuBean.setCode(node.getAttribute("code"));
     menuBean.setName(node.getAttribute("name"));
     menuBean.setUrl(node.getAttribute("url"));
     menuList.add(menuBean);
   }
 };