org.zodiac.plugin.extension.AbstractExtensionFactory Maven / Gradle / Ivy
package org.zodiac.plugin.extension;
import java.util.Collections;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zodiac.sdk.toolkit.util.collection.CollUtil;
import org.zodiac.sdk.toolkit.util.lang.StrUtil;
public abstract class AbstractExtensionFactory implements ExtensionFactory {
protected final Logger logger = LoggerFactory.getLogger(getClass());
/**
* 扩展工厂。key 扩展的key. 值为扩展的实现
*/
private final static Map PLUGIN_EXTENSION_MAP = CollUtil.concurrentMap();
public AbstractExtensionFactory() {
}
@Override
public Map getPluginExtensions() {
return Collections.unmodifiableMap(PLUGIN_EXTENSION_MAP);
}
@Override
public AbstractExtensionFactory addPluginExtension(PluginExtension pluginExtension) {
if (pluginExtension == null) {
logger.warn("add failure, PluginExtension is null");
return this;
}
String key = pluginExtension.key();
if (StrUtil.isEmpty(key)) {
logger.error("add failure, key is empty");
}
PLUGIN_EXTENSION_MAP.put(key, pluginExtension);
return this;
}
}