bpmn_engine/activity/
factory.rs1use crate::activity::{Activity, ActivityError, ActivityFactory};
6use crate::elements::event::{
7 EndEventActivity, IntermediateCatchEventActivity, IntermediateThrowEventActivity,
8 StartEventActivity,
9};
10use crate::elements::gateway::{
11 ExclusiveGatewayActivity, InclusiveGatewayActivity, ParallelGatewayActivity,
12};
13use crate::elements::task::{
14 ManualTaskActivity, ScriptTaskActivity, ServiceTaskActivity, UserTaskActivity,
15};
16use crate::model::ProcessElement;
17use std::sync::Arc;
18
19#[derive(Debug)]
23pub struct DefaultActivityFactory;
24
25impl DefaultActivityFactory {
26 pub fn new() -> Self {
27 Self
28 }
29}
30
31impl Default for DefaultActivityFactory {
32 fn default() -> Self {
33 Self::new()
34 }
35}
36
37impl ActivityFactory for DefaultActivityFactory {
38 fn create_activity(&self, element: &ProcessElement) -> Result<Arc<dyn Activity>, ActivityError> {
39 match element {
40 ProcessElement::StartEvent(e) => {
41 Ok(Arc::new(StartEventActivity::new(e.clone())) as Arc<dyn Activity>)
42 }
43 ProcessElement::EndEvent(e) => {
44 Ok(Arc::new(EndEventActivity::new(e.clone())) as Arc<dyn Activity>)
45 }
46 ProcessElement::IntermediateCatchEvent(e) => Ok(Arc::new(IntermediateCatchEventActivity::new(
47 e.clone(),
48 )) as Arc<dyn Activity>),
49 ProcessElement::IntermediateThrowEvent(e) => Ok(Arc::new(IntermediateThrowEventActivity::new(
50 e.clone(),
51 )) as Arc<dyn Activity>),
52 ProcessElement::ServiceTask(e) => {
53 Ok(Arc::new(ServiceTaskActivity::new(e.clone())) as Arc<dyn Activity>)
54 }
55 ProcessElement::UserTask(e) => {
56 Ok(Arc::new(UserTaskActivity::new(e.clone())) as Arc<dyn Activity>)
57 }
58 ProcessElement::ScriptTask(e) => {
59 Ok(Arc::new(ScriptTaskActivity::new(e.clone())) as Arc<dyn Activity>)
60 }
61 ProcessElement::ManualTask(e) => {
62 Ok(Arc::new(ManualTaskActivity::new(e.clone())) as Arc<dyn Activity>)
63 }
64 ProcessElement::ExclusiveGateway(e) => {
65 Ok(Arc::new(ExclusiveGatewayActivity::new(e.clone())) as Arc<dyn Activity>)
66 }
67 ProcessElement::ParallelGateway(e) => {
68 Ok(Arc::new(ParallelGatewayActivity::new(e.clone())) as Arc<dyn Activity>)
69 }
70 ProcessElement::InclusiveGateway(e) => {
71 Ok(Arc::new(InclusiveGatewayActivity::new(e.clone())) as Arc<dyn Activity>)
72 }
73 }
74 }
75}
76