All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.plugin.integration.application.AbstractPluginApplication Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.plugin.integration.application;

import org.pf4j.PluginStateListener;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;
import org.zodiac.plugin.extension.ExtensionFactory;
import org.zodiac.plugin.extension.PluginExtension;
import org.zodiac.plugin.integration.IntegrationConfiguration;
import org.zodiac.plugin.integration.listener.PluginListener;
import org.zodiac.plugin.integration.listener.PluginListenerFactory;
import org.zodiac.plugin.integration.listener.PluginStateListenerFactory;

import java.util.List;

public abstract class AbstractPluginApplication implements PluginApplication {

    protected final PluginListenerFactory listenerFactory = new PluginListenerFactory();
    protected final PluginStateListenerFactory pluginStateListenerFactory = new PluginStateListenerFactory();
    protected final ExtensionFactory extensionWebFactory;

    public AbstractPluginApplication(ExtensionFactory extensionWebFactory) {
        this.extensionWebFactory = extensionWebFactory;
    }

    @Override
    public PluginApplication addExtension(PluginExtension extension) {
        if (extension == null) {
            return this;
        }
        extension.setPluginApplication(this);
        extensionWebFactory.addPluginExtension(extension);
        return this;
    }

    @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);
        }
    }

    @Override
    public void addPf4jStateListener(PluginStateListener pluginListener) {
        pluginStateListenerFactory.addStateListener(pluginListener);
    }

    @Override
    public  void addPf4jStateListener(Class pluginListenerClass) {
        pluginStateListenerFactory.addStateListener(pluginListenerClass);
    }

    @Override
    public void addPf4jStateListener(List pluginListeners) {
        if (pluginListeners == null || pluginListeners.isEmpty()) {
            return;
        }
        for (PluginStateListener pluginListener : pluginListeners) {
            this.pluginStateListenerFactory.addStateListener(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