Example usage for org.springframework.statemachine.support StateMachineUtils isNormalPseudoState

List of usage examples for org.springframework.statemachine.support StateMachineUtils isNormalPseudoState

Introduction

In this page you can find the example usage for org.springframework.statemachine.support StateMachineUtils isNormalPseudoState.

Prototype

public static <S, E> boolean isNormalPseudoState(State<S, E> state) 

Source Link

Document

Checks if state is a normal pseudo state, meaning it is a pseudostate and its kind is not initial or end.

Usage

From source file:org.springframework.statemachine.support.AbstractStateMachine.java

private void exitFromState(State<S, E> state, Message<E> message, Transition<S, E> transition,
        StateMachine<S, E> stateMachine, Collection<State<S, E>> sources, Collection<State<S, E>> targets) {
    if (state == null) {
        return;/*  www  . j  a  va  2 s.com*/
    }
    log.trace("Trying Exit state=[" + state + "]");
    StateContext<S, E> stateContext = buildStateContext(Stage.STATE_EXIT, message, transition, stateMachine);

    if (transition != null) {

        State<S, E> findDeep = findDeepParent(transition.getTarget());
        boolean isTargetSubOfOtherState = findDeep != null && findDeep != currentState;
        boolean isSubOfSource = StateMachineUtils.isSubstate(transition.getSource(), currentState);
        boolean isSubOfTarget = StateMachineUtils.isSubstate(transition.getTarget(), currentState);

        if (transition.getKind() == TransitionKind.LOCAL
                && StateMachineUtils.isSubstate(transition.getSource(), transition.getTarget())
                && transition.getSource() == currentState) {
            return;
        } else if (transition.getKind() == TransitionKind.LOCAL
                && StateMachineUtils.isSubstate(transition.getTarget(), transition.getSource())
                && transition.getTarget() == currentState) {
            return;
        }

        // TODO: this and entry below should be done via a separate
        // voter of some sort which would reveal transition path
        // we could make a choice on.
        if (currentState == transition.getSource() && currentState == transition.getTarget()) {
        } else if (!isSubOfSource && !isSubOfTarget && currentState == transition.getSource()) {
        } else if (!isSubOfSource && !isSubOfTarget && currentState == transition.getTarget()) {
        } else if (isTargetSubOfOtherState) {
        } else if (!isSubOfSource && !isSubOfTarget && findDeep == null) {
        } else if (!isSubOfSource && !isSubOfTarget && (transition.getSource() == currentState
                && StateMachineUtils.isSubstate(currentState, transition.getTarget()))) {
        } else if (StateMachineUtils.isNormalPseudoState(transition.getTarget())) {
            if (isPseudoStateSubstate(findDeep, targets)) {
                return;
            }
        } else if (findDeep != null && findDeep != state && findDeep.getStates().contains(state)) {
        } else if (!isSubOfSource && !isSubOfTarget) {
            return;
        }

    }

    log.debug("Exit state=[" + state + "]");
    state.exit(stateContext);

    notifyStateExited(buildStateContext(Stage.STATE_EXIT, message, null, getRelayStateMachine(), state, null));
}