Ref doc updates
This commit is contained in:
@@ -15,21 +15,34 @@
|
||||
*/
|
||||
package org.springframework.statemachine.docs;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.statemachine.AbstractStateMachineTests;
|
||||
import org.springframework.statemachine.StateContext;
|
||||
import org.springframework.statemachine.StateMachine;
|
||||
import org.springframework.statemachine.action.Action;
|
||||
import org.springframework.statemachine.annotation.AnnoStates;
|
||||
import org.springframework.statemachine.annotation.OnTransition;
|
||||
import org.springframework.statemachine.annotation.WithStateMachine;
|
||||
import org.springframework.statemachine.config.EnableStateMachine;
|
||||
import org.springframework.statemachine.config.EnableStateMachineFactory;
|
||||
import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter;
|
||||
import org.springframework.statemachine.config.StateMachineFactory;
|
||||
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
|
||||
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
|
||||
import org.springframework.statemachine.event.StateMachineEvent;
|
||||
import org.springframework.statemachine.guard.Guard;
|
||||
import org.springframework.statemachine.listener.StateMachineListenerAdapter;
|
||||
import org.springframework.statemachine.state.State;
|
||||
import org.springframework.statemachine.transition.Transition;
|
||||
|
||||
/**
|
||||
* Tests for state machine configuration.
|
||||
@@ -185,7 +198,7 @@ public class DocsConfigurationSampleTests extends AbstractStateMachineTests {
|
||||
|
||||
|
||||
// tag::snippetG[]
|
||||
static class StateMachineEventListener implements ApplicationListener<StateMachineEvent> {
|
||||
static class StateMachineApplicationEventListener implements ApplicationListener<StateMachineEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(StateMachineEvent event) {
|
||||
@@ -193,4 +206,78 @@ public class DocsConfigurationSampleTests extends AbstractStateMachineTests {
|
||||
}
|
||||
// end::snippetG[]
|
||||
|
||||
// tag::snippetH[]
|
||||
static class StateMachineEventListener extends StateMachineListenerAdapter<States, Events> {
|
||||
|
||||
@Override
|
||||
public void stateChanged(State<States, Events> from, State<States, Events> to) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateEntered(State<States, Events> state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateExited(State<States, Events> state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transition(Transition<States, Events> transition) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transitionStarted(Transition<States, Events> transition) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transitionEnded(Transition<States, Events> transition) {
|
||||
}
|
||||
}
|
||||
// end::snippetH[]
|
||||
|
||||
// tag::snippetI[]
|
||||
@WithStateMachine
|
||||
static class Bean1 {
|
||||
|
||||
@OnTransition(source = "S1", target = "S2")
|
||||
public void fromS1ToS2() {
|
||||
}
|
||||
}
|
||||
// end::snippetI[]
|
||||
|
||||
// tag::snippetJ[]
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@OnTransition
|
||||
static @interface StatesOnTransition {
|
||||
|
||||
States[] source() default {};
|
||||
|
||||
States[] target() default {};
|
||||
}
|
||||
// end::snippetJ[]
|
||||
|
||||
// tag::snippetK[]
|
||||
@WithStateMachine
|
||||
static class Bean2 {
|
||||
|
||||
@StatesOnTransition(source = States.S1, target = States.S2)
|
||||
public void fromS1ToS2() {
|
||||
}
|
||||
}
|
||||
// end::snippetK[]
|
||||
|
||||
// tag::snippetL[]
|
||||
static class Bean3 {
|
||||
|
||||
@Autowired
|
||||
StateMachineFactory<States, Events> factory;
|
||||
|
||||
void method() {
|
||||
StateMachine<States,Events> stateMachine = factory.getStateMachine();
|
||||
stateMachine.start();
|
||||
}
|
||||
}
|
||||
// end::snippetL[]
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.statemachine.docs;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.statemachine.annotation.OnTransition;
|
||||
import org.springframework.statemachine.annotation.WithStateMachine;
|
||||
import org.springframework.statemachine.config.EnableStateMachine;
|
||||
import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter;
|
||||
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
|
||||
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
|
||||
|
||||
public class IntroSample {
|
||||
|
||||
// tag::snippetA[]
|
||||
static enum States {
|
||||
STATE1, STATE2
|
||||
}
|
||||
|
||||
static enum Events {
|
||||
EVENT1, EVENT2
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableStateMachine
|
||||
static class Config1 extends EnumStateMachineConfigurerAdapter<States, Events> {
|
||||
|
||||
@Override
|
||||
public void configure(StateMachineStateConfigurer<States, Events> states)
|
||||
throws Exception {
|
||||
states
|
||||
.withStates()
|
||||
.initial(States.STATE1)
|
||||
.states(EnumSet.allOf(States.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(StateMachineTransitionConfigurer<States, Events> transitions)
|
||||
throws Exception {
|
||||
transitions
|
||||
.withExternal()
|
||||
.source(States.STATE1).target(States.STATE2)
|
||||
.event(Events.EVENT1)
|
||||
.and()
|
||||
.withExternal()
|
||||
.source(States.STATE2).target(States.STATE1)
|
||||
.event(Events.EVENT2);
|
||||
}
|
||||
}
|
||||
|
||||
@WithStateMachine
|
||||
static class MyBean {
|
||||
|
||||
@OnTransition(target = "STATE1")
|
||||
void toState1() {
|
||||
}
|
||||
|
||||
@OnTransition(target = "STATE2")
|
||||
void toState2() {
|
||||
}
|
||||
}
|
||||
// end::snippetA[]
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user