diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/builders/StateMachineStates.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/builders/StateMachineStates.java index fcad7cd3..5f064143 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/builders/StateMachineStates.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/builders/StateMachineStates.java @@ -77,12 +77,12 @@ public class StateMachineStates { public static class StateData { private S state; private Collection deferred; - private Collection> entryActions; - private Collection> exitActions; + private Collection> entryActions; + private Collection> exitActions; public StateData(S state, Collection deferred) { this(state, deferred, null, null); } - public StateData(S state, Collection deferred, Collection> entryActions, Collection> exitActions) { + public StateData(S state, Collection deferred, Collection> entryActions, Collection> exitActions) { this.state = state; this.deferred = deferred; this.entryActions = entryActions; @@ -97,10 +97,10 @@ public class StateMachineStates { public Collection getDeferred() { return deferred; } - public Collection> getEntryActions() { + public Collection> getEntryActions() { return entryActions; } - public Collection> getExitActions() { + public Collection> getExitActions() { return exitActions; } @Override diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/DefaultStateConfigurer.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/DefaultStateConfigurer.java index be97816a..66ea5906 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/DefaultStateConfigurer.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/DefaultStateConfigurer.java @@ -68,7 +68,8 @@ public class DefaultStateConfigurer } @Override - public StateConfigurer state(S state, Collection> entryActions, Collection> exitActions) { + public StateConfigurer state(S state, Collection> entryActions, + Collection> exitActions) { states.add(new StateData(state, null, entryActions, exitActions)); return this; } diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/DefaultSubStateConfigurer.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/DefaultSubStateConfigurer.java index 14c8257c..f2eabfb7 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/DefaultSubStateConfigurer.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/DefaultSubStateConfigurer.java @@ -34,8 +34,8 @@ public class DefaultSubStateConfigurer private final Object parent; private S initial; - private Collection> entryActions; - private Collection> exitActions; + private Collection> entryActions; + private Collection> exitActions; private final Collection> states = new ArrayList>(); @@ -62,13 +62,13 @@ public class DefaultSubStateConfigurer } @Override - public SubStateConfigurer entry(Collection> entryActions) { + public SubStateConfigurer entry(Collection> entryActions) { this.entryActions = entryActions; return this; } @Override - public SubStateConfigurer exit(Collection> exitActions) { + public SubStateConfigurer exit(Collection> exitActions) { this.exitActions = exitActions; return this; } diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/StateConfigurer.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/StateConfigurer.java index 2786c350..9f6ff285 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/StateConfigurer.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/StateConfigurer.java @@ -29,7 +29,8 @@ public interface StateConfigurer extends StateConfigurer state(S state); - StateConfigurer state(S state, Collection> entryActions, Collection> exitActions); + StateConfigurer state(S state, Collection> entryActions, + Collection> exitActions); StateConfigurer state(S state, E... deferred); diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/SubStateConfigurer.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/SubStateConfigurer.java index 60538e7b..e4fd3d1b 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/SubStateConfigurer.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/config/configurers/SubStateConfigurer.java @@ -26,8 +26,8 @@ public interface SubStateConfigurer extends SubStateConfigurer initial(S initial); - SubStateConfigurer entry(Collection> entryActions); + SubStateConfigurer entry(Collection> entryActions); - SubStateConfigurer exit(Collection> exitActions); + SubStateConfigurer exit(Collection> exitActions); } diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/AbstractSimpleState.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/AbstractSimpleState.java index e1460572..4b9421cd 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/AbstractSimpleState.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/AbstractSimpleState.java @@ -52,7 +52,7 @@ public abstract class AbstractSimpleState extends AbstractState { * @param entryActions the entry actions * @param exitActions the exit actions */ - public AbstractSimpleState(S id, Collection deferred, Collection> entryActions, Collection> exitActions) { + public AbstractSimpleState(S id, Collection deferred, Collection> entryActions, Collection> exitActions) { this(id, deferred, entryActions, exitActions, null); } @@ -86,7 +86,7 @@ public abstract class AbstractSimpleState extends AbstractState { * @param pseudoState the pseudo state * @param regions the regions */ - public AbstractSimpleState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, + public AbstractSimpleState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, PseudoState pseudoState, Collection> regions) { super(id, deferred, entryActions, exitActions, pseudoState, regions); this.ids = new ArrayList(); @@ -103,7 +103,7 @@ public abstract class AbstractSimpleState extends AbstractState { * @param pseudoState the pseudo state * @param submachine the submachine */ - public AbstractSimpleState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, + public AbstractSimpleState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, PseudoState pseudoState, StateMachine submachine) { super(id, deferred, entryActions, exitActions, pseudoState, submachine); this.ids = new ArrayList(); @@ -119,7 +119,7 @@ public abstract class AbstractSimpleState extends AbstractState { * @param exitActions the exit actions * @param pseudoState the pseudo state */ - public AbstractSimpleState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, + public AbstractSimpleState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, PseudoState pseudoState) { super(id, deferred, entryActions, exitActions, pseudoState); this.ids = new ArrayList(); diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/AbstractState.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/AbstractState.java index 30164e1a..17cf98c3 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/AbstractState.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/AbstractState.java @@ -37,8 +37,8 @@ public abstract class AbstractState implements State { private final S id; private final PseudoState pseudoState; private final Collection deferred; - private final Collection> entryActions; - private final Collection> exitActions; + private final Collection> entryActions; + private final Collection> exitActions; private final Collection> regions = new ArrayList>(); private final StateMachine submachine; @@ -70,7 +70,7 @@ public abstract class AbstractState implements State { * @param entryActions the entry actions * @param exitActions the exit actions */ - public AbstractState(S id, Collection deferred, Collection> entryActions, Collection> exitActions) { + public AbstractState(S id, Collection deferred, Collection> entryActions, Collection> exitActions) { this(id, deferred, entryActions, exitActions, null); } @@ -83,7 +83,7 @@ public abstract class AbstractState implements State { * @param exitActions the exit actions * @param pseudoState the pseudo state */ - public AbstractState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, + public AbstractState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, PseudoState pseudoState) { this(id, deferred, entryActions, exitActions, pseudoState, null, null); } @@ -98,7 +98,7 @@ public abstract class AbstractState implements State { * @param pseudoState the pseudo state * @param submachine the submachine */ - public AbstractState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, + public AbstractState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, PseudoState pseudoState, StateMachine submachine) { this(id, deferred, entryActions, exitActions, pseudoState, null, submachine); } @@ -113,7 +113,7 @@ public abstract class AbstractState implements State { * @param pseudoState the pseudo state * @param regions the regions */ - public AbstractState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, + public AbstractState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, PseudoState pseudoState, Collection> regions) { this(id, deferred, entryActions, exitActions, pseudoState, regions, null); } @@ -129,7 +129,7 @@ public abstract class AbstractState implements State { * @param regions the regions * @param submachine the submachine */ - private AbstractState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, + private AbstractState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, PseudoState pseudoState, Collection> regions, StateMachine submachine) { this.id = id; this.deferred = deferred; @@ -174,12 +174,12 @@ public abstract class AbstractState implements State { } @Override - public Collection> getEntryActions() { + public Collection> getEntryActions() { return entryActions; } @Override - public Collection> getExitActions() { + public Collection> getExitActions() { return exitActions; } diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/EnumState.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/EnumState.java index 9c5adea0..283b4539 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/EnumState.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/EnumState.java @@ -24,7 +24,7 @@ import org.springframework.statemachine.region.Region; /** * A {@link State} implementation where state and event is enum based. - * + * * @author Janne Valkealahti * * @param the type of state @@ -69,7 +69,7 @@ public class EnumState, E extends Enum> extends AbstractSim * @param entryActions the entry actions * @param exitActions the exit actions */ - public EnumState(S id, Collection deferred, Collection> entryActions, Collection> exitActions) { + public EnumState(S id, Collection deferred, Collection> entryActions, Collection> exitActions) { super(id, deferred, entryActions, exitActions); } @@ -82,7 +82,7 @@ public class EnumState, E extends Enum> extends AbstractSim * @param exitActions the exit actions * @param pseudoState the pseudo state */ - public EnumState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, + public EnumState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, PseudoState pseudoState) { super(id, deferred, entryActions, exitActions, pseudoState); } @@ -97,7 +97,7 @@ public class EnumState, E extends Enum> extends AbstractSim * @param pseudoState the pseudo state * @param regions the regions */ - public EnumState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, + public EnumState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, PseudoState pseudoState, Collection> regions) { super(id, deferred, entryActions, exitActions, pseudoState, regions); } @@ -112,31 +112,31 @@ public class EnumState, E extends Enum> extends AbstractSim * @param pseudoState the pseudo state * @param submachine the submachine */ - public EnumState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, + public EnumState(S id, Collection deferred, Collection> entryActions, Collection> exitActions, PseudoState pseudoState, StateMachine submachine) { super(id, deferred, entryActions, exitActions, pseudoState, submachine); } @Override public void exit(E event, StateContext context) { - Collection> actions = getExitActions(); + Collection> actions = getExitActions(); if (actions != null) { for (Action action : actions) { action.execute(context); - } + } } } - + @Override public void entry(E event, StateContext context) { - Collection> actions = getEntryActions(); + Collection> actions = getEntryActions(); if (actions != null) { for (Action action : actions) { action.execute(context); - } + } } } - + @Override public String toString() { return "EnumState [getIds()=" + getIds() + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/RegionState.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/RegionState.java index f1e13e8c..dfbe56fb 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/RegionState.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/RegionState.java @@ -108,7 +108,7 @@ public class RegionState extends AbstractState { region.getState().exit(event, context); region.stop(); } - Collection> actions = getExitActions(); + Collection> actions = getExitActions(); if (actions != null) { for (Action action : actions) { action.execute(context); @@ -118,7 +118,7 @@ public class RegionState extends AbstractState { @Override public void entry(E event, StateContext context) { - Collection> actions = getEntryActions(); + Collection> actions = getEntryActions(); if (actions != null) { for (Action action : actions) { action.execute(context); diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/State.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/State.java index 1903ac1e..6b03fa1d 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/State.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/State.java @@ -90,14 +90,14 @@ public interface State { * * @return the state entry actions */ - Collection> getEntryActions(); + Collection> getEntryActions(); /** * Gets {@link Action}s executed exiting from this state. * * @return the state exit actions */ - Collection> getExitActions(); + Collection> getExitActions(); /** * Checks if state is a simple state. A simple state does not have any diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/StateMachineState.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/StateMachineState.java index 19148516..a9416d50 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/StateMachineState.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/state/StateMachineState.java @@ -84,7 +84,7 @@ public class StateMachineState extends AbstractState { * @param exitActions the exit actions * @param pseudoState the pseudo state */ - public StateMachineState(S id, StateMachine submachine, Collection deferred, Collection> entryActions, Collection> exitActions, + public StateMachineState(S id, StateMachine submachine, Collection deferred, Collection> entryActions, Collection> exitActions, PseudoState pseudoState) { super(id, deferred, entryActions, exitActions, pseudoState, submachine); this.ids = new ArrayList(); @@ -100,7 +100,7 @@ public class StateMachineState extends AbstractState { * @param entryActions the entry actions * @param exitActions the exit actions */ - public StateMachineState(S id, StateMachine submachine, Collection deferred, Collection> entryActions, Collection> exitActions) { + public StateMachineState(S id, StateMachine submachine, Collection deferred, Collection> entryActions, Collection> exitActions) { super(id, deferred, entryActions, exitActions, null, submachine); this.ids = new ArrayList(); this.ids.add(id); @@ -121,7 +121,7 @@ public class StateMachineState extends AbstractState { public void exit(E event, StateContext context) { getSubmachine().getState().exit(event, context); getSubmachine().stop(); - Collection> actions = getExitActions(); + Collection> actions = getExitActions(); if (actions != null && !isLocal(context)) { for (Action action : actions) { action.execute(context); @@ -131,7 +131,7 @@ public class StateMachineState extends AbstractState { @Override public void entry(E event, StateContext context) { - Collection> actions = getEntryActions(); + Collection> actions = getEntryActions(); if (actions != null && !isLocal(context)) { for (Action action : actions) { action.execute(context); diff --git a/spring-statemachine-core/src/test/java/org/springframework/statemachine/SubStateMachineTests.java b/spring-statemachine-core/src/test/java/org/springframework/statemachine/SubStateMachineTests.java index 4a2bbf58..421ce476 100644 --- a/spring-statemachine-core/src/test/java/org/springframework/statemachine/SubStateMachineTests.java +++ b/spring-statemachine-core/src/test/java/org/springframework/statemachine/SubStateMachineTests.java @@ -436,91 +436,4 @@ public class SubStateMachineTests extends AbstractStateMachineTests { } -// @Configuration -// @EnableStateMachine(name = "submachine11Config") -// public static class Config1 extends EnumStateMachineConfigurerAdapter { -// -// @Override -// public void configure(StateMachineStateConfigurer states) throws Exception { -// states -// .withStates() -// .initial(TestStates.S111) -// .state(TestStates.S111, Arrays.asList(testEntryAction()), Arrays.asList(testExitAction())); -// } -// -// @Bean(name = "entryActionS111") -// public Action testEntryAction() { -// return new TestEntryAction(); -// } -// -// @Bean(name = "exitActionS111") -// public Action testExitAction() { -// return new TestExitAction(); -// } -// -// } - -// @Configuration -// @EnableStateMachine(name = "submachine1Config") -// public static class Config2 extends EnumStateMachineConfigurerAdapter { -// -// @Autowired -// @Qualifier("submachine11Config") -// public StateMachine submachine; -// -// @Override -// public void configure(StateMachineStateConfigurer states) throws Exception { -// states -// .withSubmachine() -// .submachine(submachine); -// } -// -// @Bean(name = "entryActionS11") -// public Action testEntryAction() { -// return new TestEntryAction(); -// } -// -// @Bean(name = "exitActionS11") -// public Action testExitAction() { -// return new TestExitAction(); -// } -// -// } - -// @Configuration -// @EnableStateMachine(name = "submachineConfig") -// public static class Config3 extends EnumStateMachineConfigurerAdapter { -// -// @Autowired -// @Qualifier("submachine1Config") -// public StateMachine submachine; -// -// @Override -// public void configure(StateMachineStateConfigurer states) throws Exception { -// states -// .withSubmachine() -// .submachine(submachine); -// } -// -// @Override -// public void configure(StateMachineTransitionConfigurer transitions) throws Exception { -// transitions -// .withExternal() -// .source(TestStates.S111) -// .target(TestStates.S1) -// .event(TestEvents.E1); -// } -// -// @Bean(name = "entryActionS1") -// public TestEntryAction testEntryAction() { -// return new TestEntryAction(); -// } -// -// @Bean(name = "exitActionS1") -// public TestExitAction testExitAction() { -// return new TestExitAction(); -// } -// -// } - } diff --git a/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ConfigurationTests.java b/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ConfigurationTests.java index cfda6f87..24ebb5d3 100644 --- a/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ConfigurationTests.java +++ b/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ConfigurationTests.java @@ -19,6 +19,9 @@ import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.EnumSet; import org.junit.Test; @@ -31,6 +34,7 @@ import org.springframework.statemachine.AbstractStateMachineTests; import org.springframework.statemachine.EnumStateMachine; import org.springframework.statemachine.StateMachineSystemConstants; import org.springframework.statemachine.TestUtils; +import org.springframework.statemachine.action.Action; import org.springframework.statemachine.config.builders.StateMachineStateConfigurer; import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer; @@ -195,5 +199,53 @@ public class ConfigurationTests extends AbstractStateMachineTests { } + @Configuration + @EnableStateMachine + public static class Config5 extends EnumStateMachineConfigurerAdapter { + + @SuppressWarnings("unchecked") + @Override + public void configure(StateMachineStateConfigurer states) throws Exception { + TestEntryAction action1 = action1(); + Collection actions1 = new ArrayList(); + actions1.add(action1); + Collection> actions3 = new ArrayList>(); + actions3.add(action3()); + states + .withSubStates(TestStates.S11, null) + .entry(actions1) + .exit(Arrays.asList(action2())) + .and() + .withStates(TestStates.S11) + .initial(TestStates.S111) + .state(TestStates.S111, actions3, Arrays.asList(action4())); + } + + @Override + public void configure(StateMachineTransitionConfigurer transitions) throws Exception { + transitions + .withExternal() + .source(TestStates.S111) + .target(TestStates.S1) + .event(TestEvents.E1); + } + + public TestEntryAction action1() { + return new TestEntryAction(); + } + + public Action action2() { + return new TestExitAction(); + } + + public Action action3() { + return new TestEntryAction(); + } + + public TestExitAction action4() { + return new TestExitAction(); + } + + } }