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

com.github.quartzwebui.manager.bean.QuartzBeanManagerFacade Maven / Gradle / Ivy

The newest version!
/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.github.quartzwebui.manager.bean;

import com.github.quartzwebui.exception.NoSuchBeanDefinitionException;
import com.github.quartzwebui.utils.ReflectionUtils;
import com.github.quartzwebui.utils.SortListUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author quxiucheng [[email protected]]
 */
public class QuartzBeanManagerFacade {

    private final static QuartzBeanManagerFacade instance = new QuartzBeanManagerFacade();

    private List quartzBeanManagers = new ArrayList();

    private QuartzBeanManager defaultQuartzBeanManager = new ConstructorQuartzBeanManager();

    /**
     * 是否使用默认QuartzBeanManager
     */
    private boolean useDefaultQuartzBeanManager = true;

    private QuartzBeanManagerFacade() {
    }

    /**
     * 获取 是否使用默认QuartzBeanManager
     * @return useDefaultQuartzBeanManager 是否使用默认QuartzBeanManager
     */
    public boolean isUseDefaultQuartzBeanManager() {
        return this.useDefaultQuartzBeanManager;
    }

    /**
     * 设置 是否使用默认QuartzBeanManager
     * @param useDefaultQuartzBeanManager 是否使用默认QuartzBeanManager
     */
    public void setUseDefaultQuartzBeanManager(boolean useDefaultQuartzBeanManager) {
        this.useDefaultQuartzBeanManager = useDefaultQuartzBeanManager;
    }

    public static QuartzBeanManagerFacade getInstance() {
        return instance;
    }


    public Object getBean(String name) {
        for (QuartzBeanManager quartzBeanManager : quartzBeanManagers) {
            try {
                Object bean = quartzBeanManager.getBean(name);
                if (bean != null) {
                    return bean;
                }
            } catch (Exception e) {
                ReflectionUtils.handleReflectionException(e);
            }

        }
        if (useDefaultQuartzBeanManager) {
            try {
                Object bean = defaultQuartzBeanManager.getBean(name);
                if (bean != null) {
                    return bean;
                }
            } catch (Exception e) {
                ReflectionUtils.handleReflectionException(e);
            }
        }

        throw new NoSuchBeanDefinitionException("No bean named '" + name + "' is defined");
    }

    public Object getBean(String name, Object[] args) {
        for (QuartzBeanManager quartzBeanManager : quartzBeanManagers) {
            try {
                Object bean = quartzBeanManager.getBean(name, args);
                if (bean != null) {
                    return bean;
                }
            } catch (Exception e) {
                ReflectionUtils.handleReflectionException(e);
            }

        }
        if (useDefaultQuartzBeanManager) {
            try {
                Object bean = defaultQuartzBeanManager.getBean(name, args);
                if (bean != null) {
                    return bean;
                }
            } catch (Exception e) {
                ReflectionUtils.handleReflectionException(e);
            }
        }

        throw new NoSuchBeanDefinitionException("No bean named '" + name + "' is defined");
    }

    public List getQuartzBeanManagers() {
        return quartzBeanManagers;
    }

    public void setQuartzBeanManagers(List quartzBeanManagers) {
        this.quartzBeanManagers = quartzBeanManagers;
        SortListUtil.sort(this.quartzBeanManagers, "priority", SortListUtil.DESC);
    }

    public QuartzBeanManager getDefaultQuartzBeanManager() {
        return defaultQuartzBeanManager;
    }

    public void setDefaultQuartzBeanManager(QuartzBeanManager defaultQuartzBeanManager) {
        this.defaultQuartzBeanManager = defaultQuartzBeanManager;
    }

    public List getQuartzBeanManagerAll() {
        ArrayList all = new ArrayList();
        all.addAll(quartzBeanManagers);
        all.add(defaultQuartzBeanManager);
        return all;
    }

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy