001/* 002 * Copyright 2006-2011 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 */ 016package org.springframework.batch.core.step.builder; 017 018import org.springframework.batch.core.Step; 019import org.springframework.batch.core.job.flow.Flow; 020import org.springframework.batch.core.job.flow.FlowStep; 021 022/** 023 * A step builder for {@link FlowStep} instances. A flow step delegates processing to a nested flow composed of other 024 * steps. 025 * 026 * @author Dave Syer 027 * 028 * @since 2.2 029 */ 030public class FlowStepBuilder extends StepBuilderHelper<FlowStepBuilder> { 031 032 private Flow flow; 033 034 /** 035 * Create a new builder initialized with any properties in the parent. The parent is copied, so it can be re-used. 036 * 037 * @param parent a parent helper containing common step properties 038 */ 039 public FlowStepBuilder(StepBuilderHelper<?> parent) { 040 super(parent); 041 } 042 043 /** 044 * Provide a flow to execute during the step. 045 * 046 * @param flow the flow to execute 047 * @return this for fluent chaining 048 */ 049 public FlowStepBuilder flow(Flow flow) { 050 this.flow = flow; 051 return this; 052 } 053 054 /** 055 * Build a step that executes the flow provided, normally composed of other steps. The flow is not executed in a 056 * transaction because the individual steps are supposed to manage their own transaction state. 057 * 058 * @return a flow step 059 */ 060 public Step build() { 061 FlowStep step = new FlowStep(); 062 step.setName(getName()); 063 step.setFlow(flow); 064 super.enhance(step); 065 try { 066 step.afterPropertiesSet(); 067 } 068 catch (Exception e) { 069 throw new StepBuilderException(e); 070 } 071 return step; 072 } 073 074}