001/*
002 * Copyright 2006-2014 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 org.springframework.batch.core.job.flow.support.DefaultStateTransitionComparator;
019import org.springframework.beans.factory.config.BeanDefinition;
020import org.springframework.beans.factory.config.RuntimeBeanReference;
021import org.springframework.beans.factory.support.BeanDefinitionBuilder;
022import org.springframework.beans.factory.xml.ParserContext;
023import org.w3c.dom.Element;
024
025/**
026 * @author Dave Syer
027 * @author Michael Minella
028 *
029 */
030public class InlineFlowParser extends AbstractFlowParser {
031        private final String flowName;
032
033        /**
034         * Construct a {@link InlineFlowParser} with the specified name and using the
035         * provided job repository ref.
036         *
037         * @param flowName the name of the flow
038         * @param jobFactoryRef the reference to the {@link JobParserJobFactoryBean}
039         * from the enclosing tag
040         */
041        public InlineFlowParser(String flowName, String jobFactoryRef) {
042                this.flowName = flowName;
043                setJobFactoryRef(jobFactoryRef);
044
045        }
046
047        @Override
048        protected boolean shouldGenerateId() {
049                return true;
050        }
051
052        /**
053         * @param element the top level element containing a flow definition
054         * @param parserContext the {@link ParserContext}
055         */
056        @Override
057        protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
058                builder.getRawBeanDefinition().setAttribute("flowName", flowName);
059                builder.addPropertyValue("name", flowName);
060                builder.addPropertyValue("stateTransitionComparator", new RuntimeBeanReference(DefaultStateTransitionComparator.STATE_TRANSITION_COMPARATOR));
061                super.doParse(element, parserContext, builder);
062                builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
063                parserContext.popAndRegisterContainingComponent();
064
065        }
066}