001/*
002 * Copyright 2006-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.batch.core.job.flow.support.state;
018
019import java.util.Collection;
020import java.util.Collections;
021
022import org.springframework.batch.core.job.flow.Flow;
023import org.springframework.batch.core.job.flow.FlowExecutionStatus;
024import org.springframework.batch.core.job.flow.FlowExecutor;
025import org.springframework.batch.core.job.flow.FlowHolder;
026
027/**
028 * State that delegates to a Flow
029 *
030 * @author Dave Syer
031 * @since 2.0
032 */
033public class FlowState extends AbstractState implements FlowHolder {
034
035        private final Flow flow;
036
037        /**
038         * @param flow the {@link Flow} to delegate to.
039         * @param name the name of the state.
040         */
041        public FlowState(Flow flow, String name) {
042                super(name);
043                this.flow = flow;
044        }
045
046        /**
047         * @return the flows
048         */
049        @Override
050        public Collection<Flow> getFlows() {
051                return Collections.singleton(flow);
052        }
053
054        @Override
055        public FlowExecutionStatus handle(FlowExecutor executor) throws Exception {
056                return flow.start(executor).getStatus();
057        }
058
059        /* (non-Javadoc)
060         * @see org.springframework.batch.core.job.flow.State#isEndState()
061         */
062        @Override
063        public boolean isEndState() {
064                return false;
065        }
066
067}