com.github.codingdebugallday.integration.application.AbstractPluginApplication Maven / Gradle / Ivy
The newest version!
package com.github.codingdebugallday.integration.application;
import java.util.List;
import com.github.codingdebugallday.extension.AbstractExtension;
import com.github.codingdebugallday.extension.ExtensionFactory;
import com.github.codingdebugallday.integration.IntegrationConfiguration;
import com.github.codingdebugallday.integration.listener.PluginListener;
import com.github.codingdebugallday.integration.listener.PluginListenerFactory;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;
/**
*
* 公用的的插件应用
*
*
* @author isaac 2020/6/16 14:14
* @since 1.0
*/
public abstract class AbstractPluginApplication implements PluginApplication {
protected final PluginListenerFactory listenerFactory = new PluginListenerFactory();
@Override
public void addExtension(AbstractExtension extension) {
if (extension == null) {
return;
}
extension.setPluginApplication(this);
ExtensionFactory.addExtension(extension);
}
@Override
public void addListener(PluginListener pluginListener) {
this.listenerFactory.addPluginListener(pluginListener);
}
@Override
public void addListener(Class pluginListenerClass) {
listenerFactory.addPluginListener(pluginListenerClass);
}
@Override
public void addListener(List pluginListeners) {
if (pluginListeners == null || pluginListeners.isEmpty()) {
return;
}
for (PluginListener pluginListener : pluginListeners) {
this.listenerFactory.addPluginListener(pluginListener);
}
}
/**
* 子类可通过Application 获取插件定义的配置
*
* @param applicationContext applicationContext
* @return IntegrationConfiguration
*/
protected IntegrationConfiguration getConfiguration(ApplicationContext applicationContext) {
IntegrationConfiguration configuration = null;
try {
configuration = applicationContext.getBean(IntegrationConfiguration.class);
} catch (Exception e) {
// no show exception
}
if (configuration == null) {
throw new BeanCreationException("Not Found IntegrationConfiguration, Please define " +
"IntegrationConfiguration to Spring Bean.");
}
return configuration;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy