@@ -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 <<sm-papyrus-statemachinecomponentresolver>>.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
@@ -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<String, String> {
|
||||
|
||||
@Override
|
||||
public void configure(StateMachineModelConfigurer<String, String> model) throws Exception {
|
||||
model
|
||||
.withModel()
|
||||
.factory(modelFactory());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StateMachineModelFactory<String, String> modelFactory() {
|
||||
UmlStateMachineModelFactory factory = new UmlStateMachineModelFactory(
|
||||
"classpath:org/springframework/statemachine/uml/docs/simple-machine.uml");
|
||||
factory.setStateMachineComponentResolver(stateMachineComponentResolver());
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StateMachineComponentResolver<String, String> stateMachineComponentResolver() {
|
||||
DefaultStateMachineComponentResolver<String, String> resolver = new DefaultStateMachineComponentResolver<>();
|
||||
resolver.registerAction("myAction", myAction());
|
||||
resolver.registerGuard("myGuard", myGuard());
|
||||
return resolver;
|
||||
}
|
||||
|
||||
public Action<String, String> myAction() {
|
||||
return new Action<String, String>() {
|
||||
|
||||
@Override
|
||||
public void execute(StateContext<String, String> context) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Guard<String, String> myGuard() {
|
||||
return new Guard<String, String>() {
|
||||
|
||||
@Override
|
||||
public boolean evaluate(StateContext<String, String> context) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
// end::snippetB[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user