forked from TIBCOSoftware/flogo-contrib
/
model.go
72 lines (54 loc) · 1.86 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package model
// FlowModel defines the execution Model for a Flow. It contains the
// execution behaviors for Flows and Tasks.
type FlowModel struct {
name string
flowBehavior FlowBehavior
defaultTaskBehavior TaskBehavior
taskBehaviors map[string]TaskBehavior
}
// New creates a new FlowModel from the specified Behaviors
func New(name string) *FlowModel {
var flowModel FlowModel
flowModel.name = name
flowModel.taskBehaviors = make(map[string]TaskBehavior)
return &flowModel
}
// Name returns the name of the FlowModel
func (fm *FlowModel) Name() string {
return fm.name
}
// RegisterFlowBehavior registers the specified FlowBehavior with the Model
func (fm *FlowModel) RegisterFlowBehavior(flowBehavior FlowBehavior) {
fm.flowBehavior = flowBehavior
}
// GetFlowBehavior returns FlowBehavior of the FlowModel
func (fm *FlowModel) GetFlowBehavior() FlowBehavior {
return fm.flowBehavior
}
// RegisterDefaultTaskBehavior registers the default TaskBehavior for the Model
func (fm *FlowModel) GetDefaultTaskBehavior() TaskBehavior {
return fm.defaultTaskBehavior
}
func (fm *FlowModel) RegisterDefaultTaskBehavior(id string, taskBehavior TaskBehavior) {
fm.RegisterTaskBehavior(id, taskBehavior)
fm.defaultTaskBehavior = taskBehavior
}
// RegisterTaskBehavior registers the specified TaskBehavior with the Model
func (fm *FlowModel) RegisterTaskBehavior(id string, taskBehavior TaskBehavior) {
fm.taskBehaviors[id] = taskBehavior
}
func (fm *FlowModel) IsValidTaskType(taskType string) bool {
if taskType == "" && fm.defaultTaskBehavior != nil {
return true
}
_, exists := fm.taskBehaviors[taskType]
return exists
}
// GetTaskBehavior returns TaskBehavior with the specified ID in he FlowModel
func (fm *FlowModel) GetTaskBehavior(id string) TaskBehavior {
if id == "" {
return fm.defaultTaskBehavior
}
return fm.taskBehaviors[id]
}