001/* 002 * Copyright 2006-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.configuration.xml; 017 018import org.springframework.batch.core.job.flow.support.DefaultStateTransitionComparator; 019import org.springframework.beans.factory.config.RuntimeBeanReference; 020import org.springframework.beans.factory.support.BeanDefinitionBuilder; 021import org.springframework.beans.factory.xml.ParserContext; 022import org.springframework.util.StringUtils; 023import org.w3c.dom.Element; 024 025/** 026 * @author Dave Syer 027 * @author Michael Minella 028 * 029 */ 030public class TopLevelFlowParser extends AbstractFlowParser { 031 032 private static final String ABSTRACT_ATTR = "abstract"; 033 034 /** 035 * @param element the top level element containing a flow definition 036 * @param parserContext the {@link ParserContext} 037 */ 038 @Override 039 protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { 040 CoreNamespaceUtils.autoregisterBeansForNamespace(parserContext, element); 041 String flowName = element.getAttribute(ID_ATTR); 042 builder.getRawBeanDefinition().setAttribute("flowName", flowName); 043 builder.addPropertyValue("name", flowName); 044 builder.addPropertyValue("stateTransitionComparator", new RuntimeBeanReference(DefaultStateTransitionComparator.STATE_TRANSITION_COMPARATOR)); 045 String abstractAttr = element.getAttribute(ABSTRACT_ATTR); 046 if (StringUtils.hasText(abstractAttr)) { 047 builder.setAbstract(abstractAttr.equals("true")); 048 } 049 super.doParse(element, parserContext, builder); 050 } 051 052}