001/* 002 * Copyright 2006-2008 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.configuration.xml; 017 018import java.util.Collection; 019 020import org.springframework.beans.MutablePropertyValues; 021import org.springframework.beans.factory.config.BeanDefinition; 022import org.springframework.beans.factory.support.AbstractBeanDefinition; 023import org.springframework.beans.factory.support.BeanDefinitionBuilder; 024import org.springframework.beans.factory.support.GenericBeanDefinition; 025import org.springframework.beans.factory.xml.ParserContext; 026import org.w3c.dom.Element; 027 028/** 029 * Internal parser for the <flow/> elements inside a job. 030 * 031 * @see JobParser 032 * 033 * @author Dave Syer 034 * 035 */ 036public class FlowElementParser { 037 038 private static final String ID_ATTR = "id"; 039 040 private static final String REF_ATTR = "parent"; 041 042 /** 043 * Parse the flow and turn it into a list of transitions. 044 * 045 * @param element the <flow/gt; element to parse 046 * @param parserContext the parser context for the bean factory 047 * @return a collection of bean definitions for 048 * {@link org.springframework.batch.core.job.flow.support.StateTransition} 049 * instances objects 050 */ 051 public Collection<BeanDefinition> parse(Element element, ParserContext parserContext) { 052 053 String refAttribute = element.getAttribute(REF_ATTR); 054 String idAttribute = element.getAttribute(ID_ATTR); 055 056 BeanDefinitionBuilder stateBuilder = BeanDefinitionBuilder 057 .genericBeanDefinition("org.springframework.batch.core.job.flow.support.state.FlowState"); 058 059 AbstractBeanDefinition flowDefinition = new GenericBeanDefinition(); 060 flowDefinition.setParentName(refAttribute); 061 MutablePropertyValues propertyValues = flowDefinition.getPropertyValues(); 062 propertyValues.addPropertyValue("name", idAttribute); 063 stateBuilder.addConstructorArgValue(flowDefinition); 064 stateBuilder.addConstructorArgValue(idAttribute); 065 return InlineFlowParser.getNextElements(parserContext, stateBuilder.getBeanDefinition(), element); 066 067 } 068}