View Javadoc

1   /*
2    * Copyright 2006-2011 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  package org.springframework.batch.core.step.builder;
17  
18  import org.springframework.batch.core.Step;
19  import org.springframework.batch.core.job.flow.Flow;
20  import org.springframework.batch.core.job.flow.FlowStep;
21  
22  /**
23   * A step builder for {@link FlowStep} instances. A flow step delegates processing to a nested flow composed of other
24   * steps.
25   * 
26   * @author Dave Syer
27   * 
28   * @since 2.2
29   */
30  public class FlowStepBuilder extends StepBuilderHelper<FlowStepBuilder> {
31  
32  	private Flow flow;
33  
34  	/**
35  	 * Create a new builder initialized with any properties in the parent. The parent is copied, so it can be re-used.
36  	 * 
37  	 * @param parent a parent helper containing common step properties
38  	 */
39  	public FlowStepBuilder(StepBuilderHelper<?> parent) {
40  		super(parent);
41  	}
42  
43  	/**
44  	 * Provide a flow to execute during the step.
45  	 * 
46  	 * @param flow the flow to execute
47  	 * @return this for fluent chaining
48  	 */
49  	public FlowStepBuilder flow(Flow flow) {
50  		this.flow = flow;
51  		return this;
52  	}
53  
54  	/**
55  	 * Build a step that executes the flow provided, normally composed of other steps. The flow is not executed in a
56  	 * transaction because the individual steps are supposed to manage their own transaction state.
57  	 * 
58  	 * @return a flow step
59  	 */
60  	public Step build() {
61  		FlowStep step = new FlowStep();
62  		step.setName(getName());
63  		step.setFlow(flow);
64  		super.enhance(step);
65  		try {
66  			step.afterPropertiesSet();
67  		}
68  		catch (Exception e) {
69  			throw new StepBuilderException(e);
70  		}
71  		return step;
72  	}
73  
74  }