001/* 002 * Copyright 2012-2013 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; 017 018import org.springframework.batch.core.Job; 019import org.springframework.batch.core.Step; 020import org.springframework.beans.factory.FactoryBean; 021 022/** 023 * Convenience factory for {@link Step} instances given a {@link StepLocator}. 024 * Most implementations of {@link Job} implement StepLocator, so that can be a 025 * good starting point. 026 * 027 * @author Dave Syer 028 * 029 */ 030public class StepLocatorStepFactoryBean implements FactoryBean<Step> { 031 032 public StepLocator stepLocator; 033 034 public String stepName; 035 036 /** 037 * @param stepLocator instance of {@link StepLocator} to be used by the factory bean. 038 */ 039 public void setStepLocator(StepLocator stepLocator) { 040 this.stepLocator = stepLocator; 041 } 042 043 /** 044 * @param stepName the name to be associated with the step. 045 */ 046 public void setStepName(String stepName) { 047 this.stepName = stepName; 048 } 049 050 /** 051 * 052 * @see FactoryBean#getObject() 053 */ 054 @Override 055 public Step getObject() throws Exception { 056 return stepLocator.getStep(stepName); 057 } 058 059 /** 060 * Tell clients that we are a factory for {@link Step} instances. 061 * 062 * @see FactoryBean#getObjectType() 063 */ 064 @Override 065 public Class<? extends Step> getObjectType() { 066 return Step.class; 067 } 068 069 /** 070 * Always return true as optimization for bean factory. 071 * 072 * @see FactoryBean#isSingleton() 073 */ 074 @Override 075 public boolean isSingleton() { 076 return true; 077 } 078 079}