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

org.zodiac.plugin.integration.refresh.AbstractSpringBeanRefresh Maven / Gradle / Ivy

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

import java.lang.reflect.ParameterizedType;
import java.util.List;

import org.zodiac.plugin.integration.application.PluginApplication;
import org.zodiac.plugin.integration.listener.PluginListener;

/**
 * 抽象的SpringBean刷新类监听类。
 * 继承该类在插件动态的注册卸载时refresh方法被触发,可以获取到当前环境所有T实现的所有beans(包括主程序中的beans)。
 *
 */
public abstract class AbstractSpringBeanRefresh implements PluginListener {

    private List beans;

    protected final Class typeClass;
    protected final PluginApplication pluginApplication;

    public AbstractSpringBeanRefresh(PluginApplication pluginApplication) {
        this.pluginApplication = pluginApplication;
        pluginApplication.addListener(this);
        this.typeClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    }

    @Override
    public void registry(String pluginId, boolean isInitialize) {
        this.beans = refresh();
        registryEvent(beans);
    }

    @Override
    public void unRegistry(String pluginId) {
        this.beans = refresh();
        unRegistryEvent(beans);
    }

    /**
     * 注册事件
     * 
     * @param beans
     *            当前所有实现的bean
     */
    protected void registryEvent(List beans) {

    }

    /**
     * 卸载事件
     * 
     * @param beans
     *            当前卸载后所有的beans
     */
    protected void unRegistryEvent(List beans) {

    }

    /**
     * 刷新bean
     * 
     * @return 返回刷新后的Bean集合
     */
    protected List refresh() {
        return pluginApplication.getPluginUser().getBeans(typeClass);
    }

    /**
     * 得到beans
     * 
     * @return beansMap
     */
    public List getBeans() {
        return beans;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy