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

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

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

import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.zodiac.plugin.extension.ExtensionFactory;
import org.zodiac.plugin.integration.listener.PluginInitializerListener;
import org.zodiac.plugin.integration.pf4j.Pf4jFactory;

/**
 * 自动初始化的{@link PluginApplication}。基于 Spring InitializingBean 自动初始化插件。
 *
 */
public class AutoPluginApplication extends DefaultPluginApplication
    implements PluginApplication, InitializingBean, ApplicationContextAware {

    private ApplicationContext applicationContext;
    private PluginInitializerListener pluginInitializerListener;

    public AutoPluginApplication(ExtensionFactory extensionWebFactory) {
        super(extensionWebFactory);
    }

    public AutoPluginApplication(Pf4jFactory pf4jFactory, ExtensionFactory extensionWebFactory) {
        super(pf4jFactory, extensionWebFactory);
    }

    /**
     * 设置插件初始化监听器
     * 
     * @param pluginInitializerListener
     *            插件监听器
     */
    public void setPluginInitializerListener(PluginInitializerListener pluginInitializerListener) {
        this.pluginInitializerListener = pluginInitializerListener;
    }

    @Override
    public void initialize(ApplicationContext applicationContext, PluginInitializerListener listener) {
        // 此处不允许手动初始化!
        throw new RuntimeException("Cannot be initialized manually");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    /**
     * Spring boot bean属性被Set完后调用。会自动初始化插件
     * 
     * @throws Exception
     *             初始化异常
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        if (applicationContext == null) {
            throw new Exception("Auto initialize failed. ApplicationContext Not injected.");
        }
        super.initialize(applicationContext, pluginInitializerListener);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy