我是靠谱客的博主 哭泣发卡,最近开发中收集的这篇文章主要介绍Flowable源码注释(四十八)流程解析处理器,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Flowable源码地址:https://github.com/flowable/flowable-engine

Flowable-6.7.2 源码注释地址:https://github.com/solojin/flowable-6.7.2-annotated

包路径:org.flowable.engine.impl.bpmn.parser.handler

ProcessParseHandler 流程解析处理器

package org.flowable.engine.impl.bpmn.parser.handler;
import java.util.List;
import org.flowable.bpmn.model.BaseElement;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.EventListener;
import org.flowable.bpmn.model.ImplementationType;
import org.flowable.bpmn.model.Process;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.impl.event.FlowableEventSupport;
import org.flowable.engine.impl.bpmn.parser.BpmnParse;
import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 流程解析处理器
*
* @author Joram Barrez
*/
public class ProcessParseHandler extends AbstractBpmnParseHandler<Process> {
private static final Logger LOGGER = LoggerFactory.getLogger(ProcessParseHandler.class);
public static final String PROPERTYNAME_DOCUMENTATION = "documentation";
@Override
public Class<? extends BaseElement> getHandledType() {
return Process.class;
}
@Override
protected void executeParse(BpmnParse bpmnParse, Process process) {
if (!process.isExecutable()) {
// 忽略id为“{}”的不可执行进程。设置属性isExecutable=“true”以部署此流程。
LOGGER.info("Ignoring non-executable process with id='{}'. Set the attribute isExecutable="true" to deploy this process.", process.getId());
} else {
bpmnParse.getProcessDefinitions().add(transformProcess(bpmnParse, process));
}
}
protected ProcessDefinitionEntity transformProcess(BpmnParse bpmnParse, Process process) {
ProcessDefinitionEntity currentProcessDefinition = CommandContextUtil.getProcessDefinitionEntityManager().create();
bpmnParse.setCurrentProcessDefinition(currentProcessDefinition);
/*
* 映射对象模型-bpmn xml:
*
流程定义id -> 由activiti引擎生成
*
流程定义主键 -> bpmn id (必要的)
*
流程定义名称 -> bpmn 名称 (可选)
*/
currentProcessDefinition.setKey(process.getId());
currentProcessDefinition.setName(process.getName());
currentProcessDefinition.setCategory(bpmnParse.getBpmnModel().getTargetNamespace());
currentProcessDefinition.setDescription(process.getDocumentation());
currentProcessDefinition.setDeploymentId(bpmnParse.getDeployment().getId());
if (bpmnParse.getDeployment().getEngineVersion() != null) {
currentProcessDefinition.setEngineVersion(bpmnParse.getDeployment().getEngineVersion());
}
createEventListeners(bpmnParse, process.getEventListeners());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Parsing process {}", currentProcessDefinition.getKey());
}
bpmnParse.processFlowElements(process.getFlowElements());
processArtifacts(bpmnParse, process.getArtifacts());
return currentProcessDefinition;
}
protected void createEventListeners(BpmnParse bpmnParse, List<EventListener> eventListeners) {
if (eventListeners != null && !eventListeners.isEmpty()) {
for (EventListener eventListener : eventListeners) {
// 提取特定事件类型(如果有)
FlowableEngineEventType[] types = FlowableEngineEventType.getTypesFromString(eventListener.getEvents());
if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(eventListener.getImplementationType())) {
getEventSupport(bpmnParse.getBpmnModel()).addEventListener(bpmnParse.getListenerFactory().createClassDelegateEventListener(eventListener), types);
} else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(eventListener.getImplementationType())) {
getEventSupport(bpmnParse.getBpmnModel()).addEventListener(bpmnParse.getListenerFactory().createDelegateExpressionEventListener(eventListener), types);
} else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_SIGNAL_EVENT.equals(eventListener.getImplementationType())
|| ImplementationType.IMPLEMENTATION_TYPE_THROW_GLOBAL_SIGNAL_EVENT.equals(eventListener.getImplementationType())
|| ImplementationType.IMPLEMENTATION_TYPE_THROW_MESSAGE_EVENT.equals(eventListener.getImplementationType())
|| ImplementationType.IMPLEMENTATION_TYPE_THROW_ERROR_EVENT.equals(eventListener.getImplementationType())) {
getEventSupport(bpmnParse.getBpmnModel()).addEventListener(bpmnParse.getListenerFactory().createEventThrowingEventListener(eventListener), types);
} else {
// 事件监听器不支持的实现类型:{}元素{}
LOGGER.warn("Unsupported implementation type for EventListener: {} for element {}", eventListener.getImplementationType(), bpmnParse.getCurrentFlowElement().getId());
}
}
}
}
protected FlowableEventSupport getEventSupport(BpmnModel bpmnModel) {
return (FlowableEventSupport) bpmnModel.getEventSupport();
}
}

最后

以上就是哭泣发卡为你收集整理的Flowable源码注释(四十八)流程解析处理器的全部内容,希望文章能够帮你解决Flowable源码注释(四十八)流程解析处理器所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部