Package de.xima.fc.workflow.bpmn
Class AStatefulWorkflowBpmnModeler<Element,PartBuilder extends IStructuredBpmnModelPartBuilder<?>,Params extends IModelWorkflowItemParams<Element,PartBuilder>>
- java.lang.Object
-
- de.xima.fc.workflow.bpmn.AStatefulWorkflowBpmnModeler<Element,PartBuilder,Params>
-
- Type Parameters:
Element- The type of the workflow element to be modeled, such as a process, task, trigger, or node.PartBuilder- The type of the part builder to be used for the workflow element.Params- The type of the parameters passed to the modeler.
- Direct Known Subclasses:
AStatefulWorkflowBpmnModeler.ANodeStatefulModeler,AStatefulWorkflowBpmnModeler.AProcessStatefulModeler,AStatefulWorkflowBpmnModeler.ATaskStatefulModeler,AStatefulWorkflowBpmnModeler.ATriggerStatefulModeler
public abstract class AStatefulWorkflowBpmnModeler<Element,PartBuilder extends IStructuredBpmnModelPartBuilder<?>,Params extends IModelWorkflowItemParams<Element,PartBuilder>> extends Object
Helper class for modeling a workflow element as astructured BPMN part. For more complex elements, it may prove useful to keep state as instance fields around, to avoid having to pass many parameters around methods. This class provides a base for such modelers and contains various protected fields that can be used by subclasses.It also enforces a certain structure for the modelling process by defining template methods that are called in a specific order:
createLayoutItemis called first to create the layout item for the workflow element. It may contain nested items. Here you should create all BPMN elements such as tasks, events, gateways, etc., and align them with the various methods from thelayouter.- The layout items then gets flattened to a
IFlattenedAlignmentItemMap, and passed on to the next steps. - Next,
configurePartBuilderis called to configure the part builder with basic data, such as the bounding box, in and out ports, and the position of the child parts. - Next,
addShapesis called to create the shapes for all flow nodes created during the first step.IFlattenedAlignmentItemMapprovides several convenience methods to create shapes. - Next,
addFlowsis called to create theflowsand interconnections between the BPMN elements created during the first step.IFlattenedAlignmentItemMapprovides several convenience methods to create flows and interconnections, most notablyflattened.flow()...build(). - Next,
addAssociationsis called to create theAssociationandedgesbetween the BPMN elements created during the first step.IFlattenedAlignmentItemMapprovides several convenience methods to create associations, most notablyflattened.association()...build(). - Finally,
finishBpmnModelis called to finish the BPMN model.
IWorkflowNodeBpmnModelerthat creates 2tasksconnected with aSequenceFlow; and each task has atext annotation. We could implement it like this:public enum MyModeler implements IWorkflowNodeBpmnModeler<MyProps> { INSTANCE; @Override public void modelNode(IModelWorkflowNodeParams<MyProps> params, IWorkflowBpmnModelContext context) { modelWorkflowElementWithState(StatefulModeler::new, params, context); } private final static class StatefulModeler extends ANodeStatefulModeler<MyProps> { // implement the abstract template methods here... private IAnnotatedNamedBpmnElementLayout<Task> task1; private IAnnotatedNamedBpmnElementLayout<Task> task2; @Override protected IWorkflowBpmnAlignmentItem<?, ?> createLayoutItem() { var taskElement1 = factory.serviceTask().name("My Task 1"); var taskElement2 = factory.serviceTask().name("My Task 2"); task1 = layouter.layoutEvent().annotation("Task details 1").build(taskElement1); task2 = layouter.layoutEvent().annotation("Task details 2").build(taskElement2); return layouter.alignAtAxis() .portsOfFirstAndLastItem() .flowDirection() .flowDirectionSpacing(2) .build(task1.item().value(), task2.item().value()); } @Override protected void configurePartBuilder(IFlattenedAlignmentItemMap<?> flattened) { builder.boundingBox(flattened.boundingBox()); builder.inPort(flattened.inPort()); builder.outPort(flattened.outPort()); builder.addRaisableError(ctx.bpmnElements().generalError()); } @Override protected void addShapes(IFlattenedAlignmentItemMap<?> flattened) { flattened.createTaskShape(task1); flattened.createTaskShape(task2); } @Override protected void addFlows(IFlattenedAlignmentItemMap<?> flattened) { flattened.flow().fromOutPort(task1).toInPort(task2).build(); } @Override protected void addAssociations(IFlattenedAlignmentItemMap<?> flattened) { flattened.association().closestDiagonalConnectionToAnnotation(task1).build(); flattened.association().closestDiagonalConnectionToAnnotation(task2).build(); } } }- Since:
- 8.4.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAStatefulWorkflowBpmnModeler.ANodeStatefulModeler<Model>static classAStatefulWorkflowBpmnModeler.AProcessStatefulModelerstatic classAStatefulWorkflowBpmnModeler.ATaskStatefulModelerstatic classAStatefulWorkflowBpmnModeler.ATriggerStatefulModeler<Model>
-
Field Summary
Fields Modifier and Type Field Description protected PartBuilderbuilderConvenience field with thepart builderfrom theIModelWorkflowItemParams.protected IWorkflowBpmnModelContextctxConvenience field with theIWorkflowBpmnModelContextas provided by the workflow engine.protected ElementelementThe workflow element to be modeled.protected de.xima.bpmn_model.api.model.BpmnElementFactoryfactoryConvenience field with theelement factoryas provided by the workflow engine via theIWorkflowBpmnModelContext.protected IWorkflowBpmnLayouterlayouterConvenience field with thelayouteras provided by the workflow engine via theIWorkflowBpmnModelContext.protected ParamsparamsConvenience field with theIModelWorkflowItemParamsas provided by the workflow engine.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAStatefulWorkflowBpmnModeler(Params params, IWorkflowBpmnModelContext context)Creates a new stateful modeler with the data as provided by the workflow engine.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidaddAssociations(IFlattenedAlignmentItemMap<?> flattened)After the finalIFlattenedAlignmentItemMapwas created, adds allassociationsbetween BPMN elements, such as the association between aTextAnnotationand the element it annotates.protected abstract voidaddFlows(IFlattenedAlignmentItemMap<?> flattened)After the finalIFlattenedAlignmentItemMapwas created, connects allflow nodeswith each other.protected abstract voidaddShapes(IFlattenedAlignmentItemMap<?> flattened)After the finalIFlattenedAlignmentItemMapwas created, addsBPMN shapesfor allflow nodescreated by the part; and configures those shapes appropriately (position, dimensions, colors).protected abstract voidconfigurePartBuilder(IFlattenedAlignmentItemMap<?> flattened)Adds basic settings to thepart builderfor the part, such as the dimensions of the bounding box, the in and out ports, the position of the child parts, and the events that can be raised by the part.protected abstract IWorkflowBpmnAlignmentItem<?,?>createLayoutItem()Creates the alignment item with nested children for the workflow element.protected voidfinishBpmnModel(IFlattenedAlignmentItemMap<String> flattened)Called at the end after all other modeling methods have been called.static <Element,PartBuilder extends IStructuredBpmnModelPartBuilder<?>,Params extends IModelWorkflowItemParams<Element,PartBuilder>,Modeler extends AStatefulWorkflowBpmnModeler<Element,PartBuilder,Params>>
voidmodelWorkflowElementWithState(BiFunction<Params,IWorkflowBpmnModelContext,Modeler> modelerFactory, Params params, IWorkflowBpmnModelContext context)Models a workflow element as astructured BPMN part, using the given modeler.
-
-
-
Field Detail
-
builder
protected final PartBuilder extends IStructuredBpmnModelPartBuilder<?> builder
Convenience field with thepart builderfrom theIModelWorkflowItemParams. The part builder should be used to create the structured BPMN part for the element to be modeled.
-
ctx
protected final IWorkflowBpmnModelContext ctx
Convenience field with theIWorkflowBpmnModelContextas provided by the workflow engine. This context contains various services and factories for modeling a workflow element within a BPMN diagram.
-
element
protected final Element element
The workflow element to be modeled.
-
factory
protected final de.xima.bpmn_model.api.model.BpmnElementFactory factory
Convenience field with theelement factoryas provided by the workflow engine via theIWorkflowBpmnModelContext. This factory should be used to create the required BPMN elements for the workflow element to be modeled.
-
layouter
protected final IWorkflowBpmnLayouter layouter
Convenience field with thelayouteras provided by the workflow engine via theIWorkflowBpmnModelContext. This layouter can be used to compute the layout of the BPMN elements for the workflow element to be modeled.
-
params
protected final Params extends IModelWorkflowItemParams<Element,PartBuilder> params
Convenience field with theIModelWorkflowItemParamsas provided by the workflow engine.
-
-
Constructor Detail
-
AStatefulWorkflowBpmnModeler
protected AStatefulWorkflowBpmnModeler(Params params, IWorkflowBpmnModelContext context)
Creates a new stateful modeler with the data as provided by the workflow engine.- Parameters:
params- The parameters as provided by the workflow engine.context- The model context as provided by the workflow engine.
-
-
Method Detail
-
addAssociations
protected abstract void addAssociations(IFlattenedAlignmentItemMap<?> flattened)
After the finalIFlattenedAlignmentItemMapwas created, adds allassociationsbetween BPMN elements, such as the association between aTextAnnotationand the element it annotates.- Parameters:
flattened- The finalIFlattenedAlignmentItemMapcreated for the part.
-
addFlows
protected abstract void addFlows(IFlattenedAlignmentItemMap<?> flattened)
After the finalIFlattenedAlignmentItemMapwas created, connects allflow nodeswith each other.Adds
sequence flowsandedgesbetween flow nodes created by part; and also addsinterconnectionsbetween flow nodes and child parts.- Parameters:
flattened- The finalIFlattenedAlignmentItemMapcreated for the part.
-
addShapes
protected abstract void addShapes(IFlattenedAlignmentItemMap<?> flattened)
After the finalIFlattenedAlignmentItemMapwas created, addsBPMN shapesfor allflow nodescreated by the part; and configures those shapes appropriately (position, dimensions, colors).- Parameters:
flattened- The finalIFlattenedAlignmentItemMapcreated for the part.
-
configurePartBuilder
protected abstract void configurePartBuilder(IFlattenedAlignmentItemMap<?> flattened)
Adds basic settings to thepart builderfor the part, such as the dimensions of the bounding box, the in and out ports, the position of the child parts, and the events that can be raised by the part.- Parameters:
flattened- The finalIFlattenedAlignmentItemMapcreated for the part.
-
createLayoutItem
protected abstract IWorkflowBpmnAlignmentItem<?,?> createLayoutItem()
Creates the alignment item with nested children for the workflow element.- Returns:
- The layout item that was created for the workflow element. May contain nested items.
-
finishBpmnModel
protected void finishBpmnModel(IFlattenedAlignmentItemMap<String> flattened)
Called at the end after all other modeling methods have been called. This method can be used for finishing the BPMN model by executing any remaining tasks.- Parameters:
flattened- The finalIFlattenedAlignmentItemMapcreated for the part.
-
modelWorkflowElementWithState
public static <Element,PartBuilder extends IStructuredBpmnModelPartBuilder<?>,Params extends IModelWorkflowItemParams<Element,PartBuilder>,Modeler extends AStatefulWorkflowBpmnModeler<Element,PartBuilder,Params>> void modelWorkflowElementWithState(BiFunction<Params,IWorkflowBpmnModelContext,Modeler> modelerFactory, Params params, IWorkflowBpmnModelContext context)
Models a workflow element as astructured BPMN part, using the given modeler. See the class-level documentation ofAStatefulWorkflowBpmnModelerfor more details on the modeling process.- Parameters:
modelerFactory- The factory that creates the modeler for the workflow element.params- The parameters as provided by the workflow engine.context- The model context as provided by the workflow engine.
-
-