Spring Statemachine:如何获得选择状态的转换?

Spring Statemachine: how to get transitions of choice states?

我这样配置状态机:

    StateMachineTransitionConfigurer transitions = builder.configureTransitions();
    transitions.withChoice().source(CHOICE). //
    first(A, aGuard). //
    then(B, bGuard). //
    last(C);

然后,在另一个地方,我想从这个配置中获得选择转换。而我可以通过以下方式轻松获得选择状态:

    for (final State smState : stateMachine.getStates()) {
        if (smState.getPseudoState() != null && smState.getPseudoState().getKind() == PseudoStateKind.CHOICE) {
// smState is a choice state
        }
    }

我不知道如何从这些选择状态(上面的 "first"、"then" 和 "last" 中获取转换列表)。

似乎无法访问此信息。我说得对吗?

状态机有:

Collection<Transition<S,E>> getTransitions()

并且从 Transition 你需要检查源或目标

State<S,E> getSource();
State<S,E> getTarget()

我们最终通过自省ChoicePseudoState的"choices" 属性解决了这个问题,因为某些原因没有访问器:

    final Field choicesField = ChoicePseudoState.class.getDeclaredField("choices");
    choicesField.setAccessible(true);

    for (final State<SessionStateType, SessionEvent> smState : stateMachine.getStates()) {
        if (smState.getPseudoState() != null && smState.getPseudoState().getKind() == PseudoStateKind.CHOICE) {
            final ChoicePseudoState<SessionStateType, SessionEvent> choice = ((ChoicePseudoState<SessionStateType, SessionEvent>) smState
                .getPseudoState());
            final List<ChoiceStateData<SessionStateType, SessionEvent>> choices = (List<ChoiceStateData<SessionStateType, SessionEvent>>) choicesField
                .get(choice);

...