| 1 | /* |
| 2 | * Copyright 2012-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 | package org.springframework.batch.core.job.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.JobExecutionDecider; |
| 21 | |
| 22 | /** |
| 23 | * @author Dave Syer |
| 24 | * |
| 25 | */ |
| 26 | public class JobFlowBuilder extends FlowBuilder<FlowJobBuilder> { |
| 27 | |
| 28 | private FlowJobBuilder parent; |
| 29 | |
| 30 | public JobFlowBuilder(FlowJobBuilder parent) { |
| 31 | super(parent.getName()); |
| 32 | this.parent = parent; |
| 33 | } |
| 34 | |
| 35 | public JobFlowBuilder(FlowJobBuilder parent, Step step) { |
| 36 | super(parent.getName()); |
| 37 | this.parent = parent; |
| 38 | start(step); |
| 39 | } |
| 40 | |
| 41 | public JobFlowBuilder(FlowJobBuilder parent, JobExecutionDecider decider) { |
| 42 | super(parent.getName()); |
| 43 | this.parent = parent; |
| 44 | start(decider); |
| 45 | } |
| 46 | |
| 47 | public JobFlowBuilder(FlowJobBuilder parent, Flow flow) { |
| 48 | super(parent.getName()); |
| 49 | this.parent = parent; |
| 50 | start(flow); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Build a flow and inject it into the parent builder. The parent builder is then returned so it can be enhanced |
| 55 | * before building an actual job. Normally called explicitly via {@link #end()}. |
| 56 | * |
| 57 | * @see org.springframework.batch.core.job.builder.FlowBuilder#build() |
| 58 | */ |
| 59 | @Override |
| 60 | public FlowJobBuilder build() { |
| 61 | Flow flow = flow(); |
| 62 | parent.flow(flow); |
| 63 | return parent; |
| 64 | } |
| 65 | |
| 66 | } |