| 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.step; |
| 17 | |
| 18 | import org.springframework.batch.core.Job; |
| 19 | import org.springframework.batch.core.Step; |
| 20 | import org.springframework.beans.factory.FactoryBean; |
| 21 | |
| 22 | /** |
| 23 | * Convenience factory for {@link Step} instances given a {@link StepLocator}. |
| 24 | * Most implementations of {@link Job} implement StepLocator, so that can be a |
| 25 | * good starting point. |
| 26 | * |
| 27 | * @author Dave Syer |
| 28 | * |
| 29 | */ |
| 30 | public class StepLocatorStepFactoryBean implements FactoryBean<Step> { |
| 31 | |
| 32 | public StepLocator stepLocator; |
| 33 | |
| 34 | public String stepName; |
| 35 | |
| 36 | /** |
| 37 | * @param stepLocator |
| 38 | */ |
| 39 | public void setStepLocator(StepLocator stepLocator) { |
| 40 | this.stepLocator = stepLocator; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @param stepName |
| 45 | */ |
| 46 | public void setStepName(String stepName) { |
| 47 | this.stepName = stepName; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * |
| 52 | * @see FactoryBean#getObject() |
| 53 | */ |
| 54 | @Override |
| 55 | public Step getObject() throws Exception { |
| 56 | return stepLocator.getStep(stepName); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Tell clients that we are a factory for {@link Step} instances. |
| 61 | * |
| 62 | * @see FactoryBean#getObjectType() |
| 63 | */ |
| 64 | @Override |
| 65 | public Class<? extends Step> getObjectType() { |
| 66 | return Step.class; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Always return true as optimization for bean factory. |
| 71 | * |
| 72 | * @see FactoryBean#isSingleton() |
| 73 | */ |
| 74 | @Override |
| 75 | public boolean isSingleton() { |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | } |