EMMA Coverage Report (generated Fri Aug 21 15:59:46 BST 2009)
[all classes][org.springframework.batch.core.configuration.support]

COVERAGE SUMMARY FOR SOURCE FILE [JobRegistryBeanPostProcessor.java]

nameclass, %method, %block, %line, %
JobRegistryBeanPostProcessor.java100% (1/1)100% (6/6)100% (71/71)100% (19/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JobRegistryBeanPostProcessor100% (1/1)100% (6/6)100% (71/71)100% (19/19)
JobRegistryBeanPostProcessor (): void 100% (1/1)100% (11/11)100% (3/3)
afterPropertiesSet (): void 100% (1/1)100% (5/5)100% (2/2)
destroy (): void 100% (1/1)100% (20/20)100% (4/4)
postProcessAfterInitialization (Object, String): Object 100% (1/1)100% (29/29)100% (7/7)
postProcessBeforeInitialization (Object, String): Object 100% (1/1)100% (2/2)100% (1/1)
setJobRegistry (JobRegistry): void 100% (1/1)100% (4/4)100% (2/2)

1/*
2 * Copyright 2006-2007 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 */
16package org.springframework.batch.core.configuration.support;
17 
18import java.util.Collection;
19import java.util.HashSet;
20 
21import org.springframework.batch.core.Job;
22import org.springframework.batch.core.configuration.DuplicateJobException;
23import org.springframework.batch.core.configuration.JobLocator;
24import org.springframework.batch.core.configuration.JobRegistry;
25import org.springframework.beans.BeansException;
26import org.springframework.beans.FatalBeanException;
27import org.springframework.beans.factory.DisposableBean;
28import org.springframework.beans.factory.InitializingBean;
29import org.springframework.beans.factory.config.BeanPostProcessor;
30import org.springframework.util.Assert;
31 
32/**
33 * A {@link BeanPostProcessor} that registers {@link Job} beans
34 * with a {@link JobRegistry}. Include a bean of this type along
35 * with your job configuration, and use the same
36 * {@link JobRegistry} as a {@link JobLocator} when
37 * you need to locate a {@link JobLocator} to launch.
38 * 
39 * @author Dave Syer
40 * 
41 */
42public class JobRegistryBeanPostProcessor implements BeanPostProcessor, InitializingBean, DisposableBean {
43 
44        // It doesn't make sense for this to have a default value...
45        private JobRegistry jobConfigurationRegistry = null;
46 
47        private Collection<String> jobNames = new HashSet<String>();
48 
49        /**
50         * Injection setter for {@link JobRegistry}.
51         * 
52         * @param jobRegistry the jobConfigurationRegistry to set
53         */
54        public void setJobRegistry(JobRegistry jobRegistry) {
55                this.jobConfigurationRegistry = jobRegistry;
56        }
57 
58        /**
59         * Make sure the registry is set before use.
60         * 
61         * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
62         */
63        public void afterPropertiesSet() throws Exception {
64                Assert.notNull(jobConfigurationRegistry, "JobConfigurationRegistry must not be null");
65        }
66 
67        /**
68         * De-register all the {@link Job} instances that were
69         * regsistered by this post processor.
70         * @see org.springframework.beans.factory.DisposableBean#destroy()
71         */
72        public void destroy() throws Exception {
73                for (String name : jobNames) {
74                        jobConfigurationRegistry.unregister(name);
75                }
76                jobNames.clear();
77        }
78 
79        /**
80         * If the bean is an instance of {@link Job} then register it.
81         * @throws FatalBeanException if there is a
82         * {@link DuplicateJobException}.
83         * 
84         * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object,
85         * java.lang.String)
86         */
87        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
88                if (bean instanceof Job) {
89                        Job job = (Job) bean;
90                        try {
91                                jobConfigurationRegistry.register(new ReferenceJobFactory(job));
92                                jobNames.add(job.getName());
93                        }
94                        catch (DuplicateJobException e) {
95                                throw new FatalBeanException("Cannot register job configuration", e);
96                        }
97                }
98                return bean;
99        }
100 
101        /**
102         * Do nothing.
103         * 
104         * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object,
105         * java.lang.String)
106         */
107        public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
108                return bean;
109        }
110 
111}

[all classes][org.springframework.batch.core.configuration.support]
EMMA 2.0.5312 (C) Vladimir Roubtsov