diff --git a/docs/src/reference/asciidoc/sm.adoc b/docs/src/reference/asciidoc/sm.adoc index fcf74ca6..a946ce17 100644 --- a/docs/src/reference/asciidoc/sm.adoc +++ b/docs/src/reference/asciidoc/sm.adoc @@ -1841,7 +1841,8 @@ If `UmlStateMachineModelFactory` is created as a bean its guards. It's also possible to manually define a `StateMachineComponentResolver` which will then be used to find these components. Factory also have methods _registerAction_ and -_registerGuard_ which can be used to register these components. +_registerGuard_ which can be used to register these components. More +about this in <>. Uml model is relatively loose what comes for the implementation like _Spring StateMachine_ itself. There are choices what implementation @@ -1850,6 +1851,19 @@ functionalities for an implementation to decide. Below sections go through how _Spring StateMachine_ will implement uml model based on _Eclipse Papyrus plugin_. +[[sm-papyrus-statemachinecomponentresolver]] +==== StateMachineComponentResolver + +Below example shows how `UmlStateMachineModelFactory` is defined with +a `StateMachineComponentResolver` which registers a simple functions +`myAction` and `myGuard` respectively. As you notice these components +are not created as beans. + +[source,java,indent=0] +---- +include::samples/DocsUmlSampleTests1.java[tags=snippetB] +---- + === Creating Model Let's start by creating an empty state machine model. diff --git a/spring-statemachine-uml/src/test/java/org/springframework/statemachine/uml/docs/DocsUmlSampleTests1.java b/spring-statemachine-uml/src/test/java/org/springframework/statemachine/uml/docs/DocsUmlSampleTests1.java index fea7bcbe..00d63d07 100644 --- a/spring-statemachine-uml/src/test/java/org/springframework/statemachine/uml/docs/DocsUmlSampleTests1.java +++ b/spring-statemachine-uml/src/test/java/org/springframework/statemachine/uml/docs/DocsUmlSampleTests1.java @@ -17,10 +17,15 @@ package org.springframework.statemachine.uml.docs; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.statemachine.StateContext; +import org.springframework.statemachine.action.Action; import org.springframework.statemachine.config.EnableStateMachine; import org.springframework.statemachine.config.StateMachineConfigurerAdapter; import org.springframework.statemachine.config.builders.StateMachineModelConfigurer; +import org.springframework.statemachine.config.model.DefaultStateMachineComponentResolver; +import org.springframework.statemachine.config.model.StateMachineComponentResolver; import org.springframework.statemachine.config.model.StateMachineModelFactory; +import org.springframework.statemachine.guard.Guard; import org.springframework.statemachine.uml.UmlStateMachineModelFactory; public class DocsUmlSampleTests1 { @@ -43,4 +48,53 @@ public class DocsUmlSampleTests1 { } } // end::snippetA[] + +// tag::snippetB[] + @Configuration + @EnableStateMachine + public static class Config2 extends StateMachineConfigurerAdapter { + + @Override + public void configure(StateMachineModelConfigurer model) throws Exception { + model + .withModel() + .factory(modelFactory()); + } + + @Bean + public StateMachineModelFactory modelFactory() { + UmlStateMachineModelFactory factory = new UmlStateMachineModelFactory( + "classpath:org/springframework/statemachine/uml/docs/simple-machine.uml"); + factory.setStateMachineComponentResolver(stateMachineComponentResolver()); + return factory; + } + + @Bean + public StateMachineComponentResolver stateMachineComponentResolver() { + DefaultStateMachineComponentResolver resolver = new DefaultStateMachineComponentResolver<>(); + resolver.registerAction("myAction", myAction()); + resolver.registerGuard("myGuard", myGuard()); + return resolver; + } + + public Action myAction() { + return new Action() { + + @Override + public void execute(StateContext context) { + } + }; + } + + public Guard myGuard() { + return new Guard() { + + @Override + public boolean evaluate(StateContext context) { + return false; + } + }; + } + } +// end::snippetB[] }