EMMA Coverage Report (generated Tue May 06 07:29:23 PDT 2008)
[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% (22/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

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

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