package cn.axzo.workflow.core.service.support.spring;

import cn.axzo.workflow.core.service.support.forecast.FlowableConditionEvaluator;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * 自定义的 Aware 模式的接口处理类
 *
 * @author wangli
 * @since 2023/10/11 10:23
 */
@Component
public class FlowableConditionEvaluatorAwareProcessor implements BeanPostProcessor {

    private final FlowableConditionEvaluator conditionEvaluator;

    public FlowableConditionEvaluatorAwareProcessor(FlowableConditionEvaluator conditionEvaluator) {this.conditionEvaluator = conditionEvaluator;}

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof FlowableConditionEvaluatorAware) {
            ((FlowableConditionEvaluatorAware) bean).setConditionEvaluator(conditionEvaluator);
        }
        return bean;
    }
}
