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:
createLayoutItem
is 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,
configurePartBuilder
is 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,
addShapes
is called to create the shapes for all flow nodes created during the first step.IFlattenedAlignmentItemMap
provides several convenience methods to create shapes. - Next,
addFlows
is called to create theflows
and interconnections between the BPMN elements created during the first step.IFlattenedAlignmentItemMap
provides several convenience methods to create flows and interconnections, most notablyflattened.flow()...build()
. - Next,
addAssociations
is called to create theAssociation
andedges
between the BPMN elements created during the first step.IFlattenedAlignmentItemMap
provides several convenience methods to create associations, most notablyflattened.association()...build()
. - Finally,
finishBpmnModel
is called to finish the BPMN model.
IWorkflowNodeBpmnModeler
that creates 2tasks
connected 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 class
AStatefulWorkflowBpmnModeler.ANodeStatefulModeler<Model>
static class
AStatefulWorkflowBpmnModeler.AProcessStatefulModeler
static class
AStatefulWorkflowBpmnModeler.ATaskStatefulModeler
static class
AStatefulWorkflowBpmnModeler.ATriggerStatefulModeler<Model>
-
Field Summary
Fields Modifier and Type Field Description protected PartBuilder
builder
Convenience field with thepart builder
from theIModelWorkflowItemParams
.protected IWorkflowBpmnModelContext
ctx
Convenience field with theIWorkflowBpmnModelContext
as provided by the workflow engine.protected Element
element
The workflow element to be modeled.protected de.xima.bpmn_model.api.model.BpmnElementFactory
factory
Convenience field with theelement factory
as provided by the workflow engine via theIWorkflowBpmnModelContext
.protected IWorkflowBpmnLayouter
layouter
Convenience field with thelayouter
as provided by the workflow engine via theIWorkflowBpmnModelContext
.protected Params
params
Convenience field with theIModelWorkflowItemParams
as provided by the workflow engine.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AStatefulWorkflowBpmnModeler(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 void
addAssociations(IFlattenedAlignmentItemMap<?> flattened)
After the finalIFlattenedAlignmentItemMap
was created, adds allassociations
between BPMN elements, such as the association between aTextAnnotation
and the element it annotates.protected abstract void
addFlows(IFlattenedAlignmentItemMap<?> flattened)
After the finalIFlattenedAlignmentItemMap
was created, connects allflow nodes
with each other.protected abstract void
addShapes(IFlattenedAlignmentItemMap<?> flattened)
After the finalIFlattenedAlignmentItemMap
was created, addsBPMN shapes
for allflow nodes
created by the part; and configures those shapes appropriately (position, dimensions, colors).protected abstract void
configurePartBuilder(IFlattenedAlignmentItemMap<?> flattened)
Adds basic settings to thepart builder
for 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 void
finishBpmnModel(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 builder
from 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 theIWorkflowBpmnModelContext
as 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 factory
as 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 thelayouter
as 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 theIModelWorkflowItemParams
as 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 finalIFlattenedAlignmentItemMap
was created, adds allassociations
between BPMN elements, such as the association between aTextAnnotation
and the element it annotates.- Parameters:
flattened
- The finalIFlattenedAlignmentItemMap
created for the part.
-
addFlows
protected abstract void addFlows(IFlattenedAlignmentItemMap<?> flattened)
After the finalIFlattenedAlignmentItemMap
was created, connects allflow nodes
with each other.Adds
sequence flows
andedges
between flow nodes created by part; and also addsinterconnections
between flow nodes and child parts.- Parameters:
flattened
- The finalIFlattenedAlignmentItemMap
created for the part.
-
addShapes
protected abstract void addShapes(IFlattenedAlignmentItemMap<?> flattened)
After the finalIFlattenedAlignmentItemMap
was created, addsBPMN shapes
for allflow nodes
created by the part; and configures those shapes appropriately (position, dimensions, colors).- Parameters:
flattened
- The finalIFlattenedAlignmentItemMap
created for the part.
-
configurePartBuilder
protected abstract void configurePartBuilder(IFlattenedAlignmentItemMap<?> flattened)
Adds basic settings to thepart builder
for 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 finalIFlattenedAlignmentItemMap
created 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 finalIFlattenedAlignmentItemMap
created 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 ofAStatefulWorkflowBpmnModeler
for 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.
-
-