BATCH-63: added first cut of <job-repository> parser

This commit is contained in:
trisberg
2008-10-31 20:45:30 +00:00
parent 1723b2642e
commit ac6493b4cd
5 changed files with 172 additions and 0 deletions

View File

@@ -31,5 +31,6 @@ public class CoreNamespaceHandler extends NamespaceHandlerSupport {
*/
public void init() {
this.registerBeanDefinitionParser("job", new JobParser());
this.registerBeanDefinitionParser("job-repository", new JobRepositoryParser());
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.configuration.xml;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.w3c.dom.Element;
/**
* Parser for the lt;job-repository/gt; element in the Batch namespace. Sets up and returns
* a JobRepositoryFactoryBean.
*
* @author Thomas Risberg
* @since 2.0
*
*/
public class JobRepositoryParser extends AbstractSingleBeanDefinitionParser {
private final Log logger = LogFactory.getLog(getClass());
protected String getBeanClassName(Element element) {
return "org.springframework.batch.core.repository.support.JobRepositoryFactoryBean";
}
/**
* Parse and create a bean definition for a
* {@link org.springframework.batch.core.repository.support.JobRepositoryFactoryBean}.
*/
protected void doParse(Element element, BeanDefinitionBuilder builder) {
String dataSource = element.getAttribute("data-source");
String transactionManager = element.getAttribute("transaction-manager");
if (logger.isDebugEnabled()) {
logger.debug("Using data-source: " + dataSource);
logger.debug("Using transaction-manager: " + transactionManager);
}
RuntimeBeanReference ds = new RuntimeBeanReference(dataSource);
builder.addPropertyValue("dataSource", ds);
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
builder.addPropertyValue("transactionManager", tx);
builder.setRole(BeanDefinition.ROLE_SUPPORT);
}
}

View File

@@ -177,6 +177,48 @@ The decider is a reference to a JobExecutionDecider that can produce a status to
</xsd:complexType>
</xsd:element>
<xsd:element name="job-repository">
<xsd:annotation>
<xsd:documentation><![CDATA[
Configures a SimplJobRepository using a JobRepositoryFactoryBean.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:attribute name="data-source" type="xsd:string" default="dataSource">
<xsd:annotation>
<xsd:documentation source="java:org.springframework.transaction.PlatformTransactionManager"><![CDATA[
The bean name of the DataSource that is to be used. This attribute
is not required, and only needs to be specified explicitly
if the bean name of the desired DataSource is not 'dataSource'.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="javax.sql.DataSource"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="transaction-manager" type="xsd:string" default="transactionManager">
<xsd:annotation>
<xsd:documentation source="java:org.springframework.transaction.PlatformTransactionManager"><![CDATA[
The bean name of the TransactionManager that is to be used. This attribute
is not required, and only needs to be specified explicitly
if the bean name of the desired TransactionManager is not 'transactionManager'.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.transaction.PlatformTransactionManager"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="flowType">
<xsd:sequence>
<xsd:choice minOccurs="1" maxOccurs="unbounded" >

View File

@@ -0,0 +1,46 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.configuration.xml;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Thomas Risberg
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class JobRepositoryParserTests {
@Autowired
@Qualifier("jobRepo1")
private JobRepository jobRepository;
@Test
public void testOneStep() throws Exception {
assertNotNull(jobRepository);
}
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init="true">
<beans:property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<beans:property name="url" value="jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true" />
</beans:bean>
<beans:bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<beans:property name="dataSource" ref="dataSource"/>
</beans:bean>
<job-repository id="jobRepo1"/>
</beans:beans>