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

com.plugin.development.context.refresh.AbstractPluginSpringBeanRefresh Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package com.plugin.development.context.refresh;

import com.plugin.development.context.PluginSpringBeanListener;
import com.plugin.development.integration.PluginApplication;

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

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

    private final Class typeClass;

    private List beans;

    private final PluginApplication pluginApplication;


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

    @Override
    public void registryEvent(String pluginId) throws Exception {
        refresh();
    }

    @Override
    public void unRegistryEvent(String pluginId) throws Exception {
        refresh();
    }


    private void refresh(){
        List beans = pluginApplication
                .getPluginUser()
                .getPluginSpringDefineBeansOfType(typeClass);
        if(beans != null){
            this.beans = refresh(beans);
        } else {
            this.beans = beans;
        }
    }

    /**
     * 刷新beans的操作
     * @param beans beans
     * @return 刷新后的beans
     */
    protected abstract List refresh(List beans);

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy