Example usage for org.springframework.batch.core.job.flow.support StateTransition getState

List of usage examples for org.springframework.batch.core.job.flow.support StateTransition getState

Introduction

In this page you can find the example usage for org.springframework.batch.core.job.flow.support StateTransition getState.

Prototype

public State getState() 

Source Link

Document

Public getter for the State.

Usage

From source file:org.springframework.batch.core.job.flow.support.SimpleFlow.java

/**
 * Analyse the transitions provided and generate all the information needed
 * to execute the flow.//from www.ja  v a 2  s  .c  o m
 */
private void initializeTransitions() {
    startState = null;
    transitionMap.clear();
    stateMap.clear();
    boolean hasEndStep = false;

    if (stateTransitions.isEmpty()) {
        throw new IllegalArgumentException(
                "No start state was found. You must specify at least one step in a job.");
    }

    for (StateTransition stateTransition : stateTransitions) {
        State state = stateTransition.getState();
        String stateName = state.getName();
        stateMap.put(stateName, state);
    }

    for (StateTransition stateTransition : stateTransitions) {

        State state = stateTransition.getState();

        if (!stateTransition.isEnd()) {

            String next = stateTransition.getNext();

            if (!stateMap.containsKey(next)) {
                throw new IllegalArgumentException("Missing state for [" + stateTransition + "]");
            }

        } else {
            hasEndStep = true;
        }

        String name = state.getName();

        Set<StateTransition> set = transitionMap.get(name);
        if (set == null) {
            // If no comparator is provided, we will maintain the order of insertion
            if (stateTransitionComparator == null) {
                set = new LinkedHashSet<StateTransition>();
            } else {
                set = new TreeSet<StateTransition>(stateTransitionComparator);
            }

            transitionMap.put(name, set);
        }
        set.add(stateTransition);

    }

    if (!hasEndStep) {
        throw new IllegalArgumentException(
                "No end state was found.  You must specify at least one transition with no next state.");
    }

    startState = stateTransitions.get(0).getState();

}