8080import org .flowable .bpmn .model .BpmnModel ;
8181import org .flowable .bpmn .model .DateDataObject ;
8282import org .flowable .bpmn .model .DoubleDataObject ;
83+ import org .flowable .bpmn .model .Event ;
84+ import org .flowable .bpmn .model .EventRegistryEventDefinition ;
8385import org .flowable .bpmn .model .EventSubProcess ;
86+ import org .flowable .bpmn .model .ExtensionElement ;
8487import org .flowable .bpmn .model .FlowElement ;
8588import org .flowable .bpmn .model .FlowNode ;
8689import org .flowable .bpmn .model .IntegerDataObject ;
90+ import org .flowable .bpmn .model .IntermediateCatchEvent ;
8791import org .flowable .bpmn .model .JsonDataObject ;
8892import org .flowable .bpmn .model .LongDataObject ;
8993import org .flowable .bpmn .model .Pool ;
9094import org .flowable .bpmn .model .Process ;
9195import org .flowable .bpmn .model .SequenceFlow ;
96+ import org .flowable .bpmn .model .StartEvent ;
9297import org .flowable .bpmn .model .StringDataObject ;
9398import org .flowable .bpmn .model .SubProcess ;
9499import org .flowable .bpmn .model .TextAnnotation ;
@@ -479,6 +484,7 @@ public BpmnModel convertToBpmnModel(XMLStreamReader xtr) {
479484
480485 protected void processFlowElements (Collection <FlowElement > flowElementList , BaseElement parentScope ) {
481486 for (FlowElement flowElement : flowElementList ) {
487+
482488 if (flowElement instanceof SequenceFlow sequenceFlow ) {
483489 FlowNode sourceNode = getFlowNodeFromScope (sequenceFlow .getSourceRef (), parentScope );
484490 if (sourceNode != null ) {
@@ -498,14 +504,40 @@ protected void processFlowElements(Collection<FlowElement> flowElementList, Base
498504 boundaryEvent .setAttachedToRef (attachedActivity );
499505 attachedActivity .getBoundaryEvents ().add (boundaryEvent );
500506 }
507+ promoteEventTypeExtensionToEventRegistryEventDefinition (boundaryEvent );
501508
502509 } else if (flowElement instanceof SubProcess subProcess ) {
503510 Collection <FlowElement > childFlowElements = subProcess .getFlowElements ();
504511 processFlowElements (childFlowElements , subProcess );
512+ } else if (flowElement instanceof Event event ) {
513+ promoteEventTypeExtensionToEventRegistryEventDefinition (event );
514+
505515 }
506516 }
507517 }
508518
519+ /**
520+ * Adds a typed {@link EventRegistryEventDefinition} on event hosts that carry a legacy
521+ * {@code <flowable:eventType>X</flowable:eventType>} extension element. The extension element is left
522+ * in place so external code that reads it via {@code event.getExtensionElements()} continues to work;
523+ * the typed definition gives the engine and validators a class to dispatch on. Programmatic models that
524+ * already attach the typed definition (or carry no extension element) are skipped.
525+ */
526+ protected void promoteEventTypeExtensionToEventRegistryEventDefinition (Event event ) {
527+ if (event .getEventDefinitions ().stream ().anyMatch (EventRegistryEventDefinition .class ::isInstance )) {
528+ return ;
529+ }
530+ List <ExtensionElement > eventTypeElements = event .getExtensionElements ().get (BpmnXMLConstants .ELEMENT_EVENT_TYPE );
531+ if (eventTypeElements == null || eventTypeElements .isEmpty ()) {
532+ return ;
533+ }
534+ String value = eventTypeElements .get (0 ).getElementText ();
535+ if (StringUtils .isEmpty (value )) {
536+ return ;
537+ }
538+ event .addEventDefinition (new EventRegistryEventDefinition (value ));
539+ }
540+
509541 protected FlowNode getFlowNodeFromScope (String elementId , BaseElement scope ) {
510542 FlowNode flowNode = null ;
511543 if (StringUtils .isNotEmpty (elementId )) {
0 commit comments