net.ymate.platform.plugin.Plugins 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.plugin;
import net.ymate.platform.base.YMP;
import net.ymate.platform.commons.i18n.I18N;
import net.ymate.platform.plugin.impl.DefaultPluginConfig;
/**
*
* Plugins
*
*
* 插件管理器类;
*
*
* @author 刘镇([email protected])
* @version 0.0.0
*
*
* 版本号 动作 修改人 修改时间
*
*
*
* 0.0.0
* 创建类
* 刘镇
* 2012-11-30下午6:28:20
*
*
*/
public class Plugins {
/**
* 使用默认配置创建插件工厂
*
* @return
* @throws PluginException
*/
public static IPluginFactory createPluginFactory() throws PluginException {
return createPluginFactory(new DefaultPluginConfig(true, true));
}
/**
* 创建插件工厂
*
* @param config 插件初始化配置
* @return
* @throws PluginException
*/
public static IPluginFactory createPluginFactory(IPluginConfig config) throws PluginException {
if (config == null) {
throw new PluginException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.plugin.create_plugin_factory_param_exception"));
}
IPluginFactory _factory = config.getPluginFactoryClassImpl();
_factory.initialize(config);
if (config.isAllowAutomatic()) {
// 将所有设置为自动运行的插件启动起来...
for (PluginMeta _meta : _factory.getPluginMetas()) {
if (_meta.isAutomatic()) {
_factory.getPlugin(_meta.getId());
}
}
}
return _factory;
}
}