001/*
002 * Copyright 2006-2009 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.batch.core.job.flow.support.state.StepState;
021import org.springframework.beans.factory.config.BeanDefinition;
022import org.springframework.beans.factory.parsing.BeanComponentDefinition;
023import org.springframework.beans.factory.support.AbstractBeanDefinition;
024import org.springframework.beans.factory.support.BeanDefinitionBuilder;
025import org.springframework.beans.factory.xml.ParserContext;
026import org.w3c.dom.Element;
027
028/**
029 * Internal parser for the <step/> elements inside a job. A step element
030 * references a bean definition for a
031 * {@link org.springframework.batch.core.Step} and goes on to (optionally) list
032 * a set of transitions from that step to others with <next on="pattern"
033 * to="stepName"/>. Used by the {@link JobParser}.
034 * 
035 * @see JobParser
036 * 
037 * @author Dave Syer
038 * @author Thomas Risberg
039 * @since 2.0
040 */
041public class InlineStepParser extends AbstractStepParser {
042
043        /**
044         * Parse the step and turn it into a list of transitions.
045         * 
046         * @param element the <step/gt; element to parse
047         * @param parserContext the parser context for the bean factory
048         * @param jobFactoryRef the reference to the {@link JobParserJobFactoryBean}
049         *        from the enclosing tag
050         * @return a collection of bean definitions for
051         *         {@link org.springframework.batch.core.job.flow.support.StateTransition}
052         *         instances objects
053         */
054        public Collection<BeanDefinition> parse(Element element, ParserContext parserContext, String jobFactoryRef) {
055
056                BeanDefinitionBuilder stateBuilder = BeanDefinitionBuilder.genericBeanDefinition(StepState.class);
057                String stepId = element.getAttribute(ID_ATTR);
058
059                AbstractBeanDefinition bd = parseStep(element, parserContext, jobFactoryRef);
060                parserContext.registerBeanComponent(new BeanComponentDefinition(bd, stepId));
061                stateBuilder.addConstructorArgReference(stepId);
062
063                return InlineFlowParser.getNextElements(parserContext, stepId, stateBuilder.getBeanDefinition(), element);
064
065        }
066
067}