View Javadoc

1   /*
2    * Copyright 2006-2013 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.batch.core.job.flow.support.state;
18  
19  import java.util.Collection;
20  import java.util.Collections;
21  
22  import org.springframework.batch.core.job.flow.Flow;
23  import org.springframework.batch.core.job.flow.FlowExecutionStatus;
24  import org.springframework.batch.core.job.flow.FlowExecutor;
25  import org.springframework.batch.core.job.flow.FlowHolder;
26  
27  /**
28   * State that delegates to a Flow
29   *
30   * @author Dave Syer
31   * @since 2.0
32   */
33  public class FlowState extends AbstractState implements FlowHolder {
34  
35  	private final Flow flow;
36  
37  	/**
38  	 * @param name
39  	 */
40  	public FlowState(Flow flow, String name) {
41  		super(name);
42  		this.flow = flow;
43  	}
44  
45  	/**
46  	 * @return the flows
47  	 */
48  	@Override
49  	public Collection<Flow> getFlows() {
50  		return Collections.singleton(flow);
51  	}
52  
53  	@Override
54  	public FlowExecutionStatus handle(FlowExecutor executor) throws Exception {
55  		return flow.start(executor).getStatus();
56  	}
57  
58  	/* (non-Javadoc)
59  	 * @see org.springframework.batch.core.job.flow.State#isEndState()
60  	 */
61  	@Override
62  	public boolean isEndState() {
63  		return false;
64  	}
65  
66  }