001/* 002 * Copyright 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.jsr.configuration.xml; 017 018import javax.batch.api.Decider; 019 020import org.springframework.batch.core.Step; 021import org.springframework.batch.core.jsr.step.DecisionStep; 022import org.springframework.batch.core.repository.JobRepository; 023import org.springframework.beans.factory.FactoryBean; 024import org.springframework.beans.factory.InitializingBean; 025import org.springframework.util.Assert; 026 027/** 028 * {@link FactoryBean} for creating a {@link DecisionStep}. 029 * 030 * @author Michael Minella 031 * @since 3.0 032 */ 033public class DecisionStepFactoryBean implements FactoryBean<Step>, InitializingBean { 034 035 private Decider jsrDecider; 036 private String name; 037 private JobRepository jobRepository; 038 039 /** 040 * @param jobRepository All steps need to be able to reference a {@link JobRepository} 041 */ 042 public void setJobRepository(JobRepository jobRepository) { 043 this.jobRepository = jobRepository; 044 } 045 046 /** 047 * @param decider a {@link Decider} 048 * @throws IllegalArgumentException if the type passed in is not a valid type 049 */ 050 public void setDecider(Decider decider) { 051 this.jsrDecider = decider; 052 } 053 054 /** 055 * The name of the state 056 * 057 * @param name the name to be used by the DecisionStep. 058 */ 059 public void setName(String name) { 060 this.name = name; 061 } 062 063 /* (non-Javadoc) 064 * @see org.springframework.beans.factory.FactoryBean#getObject() 065 */ 066 @Override 067 public Step getObject() throws Exception { 068 069 DecisionStep decisionStep = new DecisionStep(jsrDecider); 070 decisionStep.setName(name); 071 decisionStep.setJobRepository(jobRepository); 072 decisionStep.setAllowStartIfComplete(true); 073 074 return decisionStep; 075 } 076 077 /* (non-Javadoc) 078 * @see org.springframework.beans.factory.FactoryBean#getObjectType() 079 */ 080 @Override 081 public Class<?> getObjectType() { 082 return DecisionStep.class; 083 } 084 085 /* (non-Javadoc) 086 * @see org.springframework.beans.factory.FactoryBean#isSingleton() 087 */ 088 @Override 089 public boolean isSingleton() { 090 return true; 091 } 092 093 @Override 094 public void afterPropertiesSet() throws Exception { 095 Assert.isTrue(jsrDecider != null, "A decider implementation is required"); 096 Assert.notNull(name, "A name is required for a decision state"); 097 } 098}