package org.springblade.flow.engine.custom.xml.impl;


import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.converter.UserTaskXMLConverter;
import org.flowable.bpmn.model.BaseElement;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.ExtensionAttribute;
import org.flowable.bpmn.model.UserTask;

import javax.xml.stream.XMLStreamReader;
import java.util.List;
import java.util.Map;

/**
 * @Author:LoveMyOrange
 * @Description: 如果只是取出扩展属性 输出 那么下面代码写法没有问题, 如果 调用完super 还想添加扩展属性,那么表面是正确的,实际上是完全错误
 * 原因: SAX解析机制
 *
 * 此类不用添加任何代码 因为 userTask元素本身就支持扩展属性
 * @Date:Created in 2021/12/17 14:21
 */
@Slf4j
public class CustomUserTaskXMLConverter extends UserTaskXMLConverter {
    @Override
    protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
        BaseElement baseElement = super.convertXMLToElement(xtr, model);
        UserTask userTask=null;
        if (baseElement!=null) {
            userTask=(UserTask) baseElement;
        }
        Map<String, List<ExtensionAttribute>> attributes = userTask.getAttributes();
        log.info("当前节点 {}扩展属性{}", userTask.getName(),attributes);
        return userTask;
    }


}
