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[email protected][email protected]} beans
35[email protected]}. Include a bean of this type along
36 * with your job configuration, and use the same
37[email protected][email protected]} when
38[email protected]} to launch.
39 * 
40[email protected]
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[email protected]}.
52         * 
53[email protected]gistry 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[email protected]ializingBean#afterPropertiesSet()
63         */
64        public void afterPropertiesSet() throws Exception {
65                Assert.notNull(jobConfigurationRegistry, "JobConfigurationRegistry must not be null");
66        }
67 
68        /**
69[email protected]} instances that were
70         * regsistered by this post processor.
71[email protected]osableBean#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[email protected]Job} then register it.
83[email protected]a
84[email protected]}.
85         * 
86[email protected]ig.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[email protected]ig.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