![JAR search and dependency download from the Maven repository](/logo.png)
net.ymate.platform.base.impl.DefaultModuleLoader Maven / Gradle / Ivy
/*
* Copyright 2007-2107 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.ymate.platform.base.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import net.ymate.platform.base.IModule;
import net.ymate.platform.base.IModuleLoader;
import net.ymate.platform.module.ConfigModule;
import net.ymate.platform.module.JdbcModule;
import net.ymate.platform.module.LogModule;
import net.ymate.platform.module.MongoDBModule;
import net.ymate.platform.module.WebMvcModule;
import org.apache.commons.lang.StringUtils;
/**
*
* DefaultModuleLoader
*
*
* 模块加载器接口默认实现类;
*
*
* @author 刘镇([email protected])
* @version 0.0.0
*
*
* 版本号 动作 修改人 修改时间
*
*
*
* 0.0.0
* 创建类
* 刘镇
* 2012-12-23下午6:08:03
*
*
*/
public class DefaultModuleLoader implements IModuleLoader {
protected static Map __DEFAULT_MODULE_LOADER_NAMES = new HashMap();
static {
// configuration|logger|jdbc|mongodb|webmvc
__DEFAULT_MODULE_LOADER_NAMES.put("configuration", ConfigModule.class.getName());
__DEFAULT_MODULE_LOADER_NAMES.put("logger", LogModule.class.getName());
__DEFAULT_MODULE_LOADER_NAMES.put("jdbc", JdbcModule.class.getName());
__DEFAULT_MODULE_LOADER_NAMES.put("mongodb", MongoDBModule.class.getName());
__DEFAULT_MODULE_LOADER_NAMES.put("webmvc", WebMvcModule.class.getName());
}
private List __loadedModules = new ArrayList();
/* (non-Javadoc)
* @see net.ymate.platform.module.base.IModuleLoader#initialize(java.util.Properties)
*/
public void initialize(Properties configs) throws Exception {
String[] _moduleList = StringUtils.split(configs.getProperty("ymp.module_list"), '|');
if (_moduleList != null && _moduleList.length > 0) {
for(String _moduleName : _moduleList) {
String _moduleClassName = configs.getProperty("ymp.modules." + _moduleName);
if (StringUtils.isBlank(_moduleClassName)) {
if (__DEFAULT_MODULE_LOADER_NAMES.containsKey(_moduleName)) {
_moduleClassName = __DEFAULT_MODULE_LOADER_NAMES.get(_moduleName);
}
}
if (StringUtils.isNotBlank(_moduleClassName)) {
IModule _module = (IModule) Class.forName(_moduleClassName).newInstance();
_module.initialize(__parseModuleCfg(_moduleName, configs));
__loadedModules.add(_module);
}
}
}
}
/* (non-Javadoc)
* @see net.ymate.platform.module.base.IModuleLoader#destroy()
*/
public void destroy() throws Exception {
for (IModule _module : __loadedModules) {
_module.destroy();
}
__loadedModules.clear();
}
/**
* @param moduleName 模块名称
* @param configs 配置参数集合
* @return 分析提取模块配置映射
*/
private Map __parseModuleCfg(String moduleName, Properties configs) {
Map _returnValue = new HashMap();
// 提取模块配置
for(Object _key : configs.keySet()) {
String _prefix = "ymp.configs." + moduleName + ".";
if (StringUtils.startsWith((String) _key, _prefix)) {
String _cfgKey = StringUtils.substring((String) _key, _prefix.length());
String _cfgValue = configs.getProperty((String) _key);
_returnValue.put(_cfgKey, _cfgValue);
}
}
return _returnValue;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy