1 | /* |
2 | * Copyright 2006-2007 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 org.springframework.batch.core.Step; |
20 | import org.springframework.batch.core.job.flow.FlowExecutionStatus; |
21 | import org.springframework.batch.core.job.flow.FlowExecutor; |
22 | import org.springframework.batch.core.job.flow.State; |
23 | import org.springframework.batch.core.step.StepHolder; |
24 | |
25 | /** |
26 | * {@link State} implementation that delegates to a {@link FlowExecutor} to |
27 | * execute the specified {@link Step}. |
28 | * |
29 | * @author Dave Syer |
30 | * @since 2.0 |
31 | */ |
32 | public class StepState extends AbstractState implements StepHolder { |
33 | |
34 | private final Step step; |
35 | |
36 | /** |
37 | * @param step the step that will be executed |
38 | */ |
39 | public StepState(Step step) { |
40 | super(step.getName()); |
41 | this.step = step; |
42 | } |
43 | |
44 | /** |
45 | * @param name for the step that will be executed |
46 | * @param step the step that will be executed |
47 | */ |
48 | public StepState(String name, Step step) { |
49 | super(name); |
50 | this.step = step; |
51 | } |
52 | |
53 | @Override |
54 | public FlowExecutionStatus handle(FlowExecutor executor) throws Exception { |
55 | /* |
56 | * On starting a new step, possibly upgrade the last execution to make |
57 | * sure it is abandoned on restart if it failed. |
58 | */ |
59 | executor.abandonStepExecution(); |
60 | return new FlowExecutionStatus(executor.executeStep(step)); |
61 | } |
62 | |
63 | /** |
64 | * @return the step |
65 | */ |
66 | public Step getStep() { |
67 | return step; |
68 | } |
69 | |
70 | /* (non-Javadoc) |
71 | * @see org.springframework.batch.core.job.flow.State#isEndState() |
72 | */ |
73 | public boolean isEndState() { |
74 | return false; |
75 | } |
76 | |
77 | } |