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 org.springframework.beans.factory.config.BeanDefinition; |
19 | import org.springframework.beans.factory.config.RuntimeBeanReference; |
20 | import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
21 | import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; |
22 | import org.springframework.transaction.support.DefaultTransactionDefinition; |
23 | import org.springframework.util.StringUtils; |
24 | import org.w3c.dom.Element; |
25 | |
26 | /** |
27 | * Parser for the lt;job-repository/gt; element in the Batch namespace. Sets up and returns |
28 | * a JobRepositoryFactoryBean. |
29 | * |
30 | * @author Thomas Risberg |
31 | * @since 2.0 |
32 | * |
33 | */ |
34 | public class JobRepositoryParser extends AbstractSingleBeanDefinitionParser { |
35 | |
36 | protected String getBeanClassName(Element element) { |
37 | return "org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"; |
38 | } |
39 | |
40 | /** |
41 | * Parse and create a bean definition for a |
42 | * {@link org.springframework.batch.core.repository.support.JobRepositoryFactoryBean}. |
43 | */ |
44 | protected void doParse(Element element, BeanDefinitionBuilder builder) { |
45 | |
46 | String dataSource = element.getAttribute("data-source"); |
47 | |
48 | String transactionManager = element.getAttribute("transaction-manager"); |
49 | |
50 | String isolationLevelForCreate = element.getAttribute("isolation-level-for-create"); |
51 | |
52 | String tablePrefix = element.getAttribute("table-prefix"); |
53 | |
54 | RuntimeBeanReference ds = new RuntimeBeanReference(dataSource); |
55 | builder.addPropertyValue("dataSource", ds); |
56 | RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager); |
57 | builder.addPropertyValue("transactionManager", tx); |
58 | if (StringUtils.hasText(isolationLevelForCreate)) { |
59 | builder.addPropertyValue("isolationLevelForCreate", DefaultTransactionDefinition.PREFIX_ISOLATION+isolationLevelForCreate); |
60 | } |
61 | if (StringUtils.hasText(tablePrefix)) { |
62 | builder.addPropertyValue("tablePrefix", tablePrefix); |
63 | } |
64 | |
65 | builder.setRole(BeanDefinition.ROLE_SUPPORT); |
66 | |
67 | } |
68 | |
69 | } |