1 | /* |
2 | * Copyright 2006-2008 the original author or authors. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.springframework.batch.core.configuration.xml; |
17 | |
18 | import java.util.Collection; |
19 | |
20 | import org.springframework.beans.factory.config.BeanDefinition; |
21 | import org.springframework.beans.factory.config.RuntimeBeanReference; |
22 | import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
23 | import org.springframework.beans.factory.xml.ParserContext; |
24 | import org.w3c.dom.Element; |
25 | |
26 | /** |
27 | * Internal parser for the <decision/> elements inside a job. A decision |
28 | * element references a bean definition for a |
29 | * {@link org.springframework.batch.core.job.flow.JobExecutionDecider} |
30 | * and goes on to list a set of transitions to other states with <next |
31 | * on="pattern" to="stepName"/>. Used by the {@link JobParser}. |
32 | * |
33 | * @see JobParser |
34 | * |
35 | * @author Dave Syer |
36 | * |
37 | */ |
38 | public class DecisionParser { |
39 | |
40 | /** |
41 | * Parse the decision and turn it into a list of transitions. |
42 | * |
43 | * @param element the <decision/gt; element to parse |
44 | * @param parserContext the parser context for the bean factory |
45 | * @return a collection of bean definitions for |
46 | * {@link org.springframework.batch.core.job.flow.support.StateTransition} |
47 | * instances objects |
48 | */ |
49 | public Collection<BeanDefinition> parse(Element element, ParserContext parserContext) { |
50 | |
51 | String refAttribute = element.getAttribute("decider"); |
52 | String idAttribute = element.getAttribute("id"); |
53 | |
54 | BeanDefinitionBuilder stateBuilder = |
55 | BeanDefinitionBuilder.genericBeanDefinition("org.springframework.batch.core.job.flow.support.state.DecisionState"); |
56 | stateBuilder.addConstructorArgValue(new RuntimeBeanReference(refAttribute)); |
57 | stateBuilder.addConstructorArgValue(idAttribute); |
58 | return FlowParser.getNextElements(parserContext, stateBuilder.getBeanDefinition(), element); |
59 | |
60 | } |
61 | } |