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 [ClassPathXmlJobRegistry.java]

nameclass, %method, %block, %line, %
ClassPathXmlJobRegistry.java100% (1/1)78%  (7/9)92%  (110/120)85%  (23/27)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ClassPathXmlJobRegistry100% (1/1)78%  (7/9)92%  (110/120)85%  (23/27)
register (JobFactory): void 0%   (0/1)0%   (0/5)0%   (0/2)
unregister (String): void 0%   (0/1)0%   (0/5)0%   (0/2)
<static initializer> 100% (1/1)100% (4/4)100% (2/2)
ClassPathXmlJobRegistry (): void 100% (1/1)100% (8/8)100% (2/2)
afterPropertiesSet (): void 100% (1/1)100% (80/80)100% (14/14)
getJob (String): Job 100% (1/1)100% (5/5)100% (1/1)
getJobNames (): Collection 100% (1/1)100% (4/4)100% (1/1)
setApplicationContext (ApplicationContext): void 100% (1/1)100% (4/4)100% (2/2)
setJobPaths (Resource []): void 100% (1/1)100% (5/5)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 */
16 
17package org.springframework.batch.core.configuration.support;
18 
19import java.util.Arrays;
20import java.util.Collection;
21import java.util.List;
22 
23import org.apache.commons.logging.Log;
24import org.apache.commons.logging.LogFactory;
25import org.springframework.batch.core.Job;
26import org.springframework.batch.core.configuration.DuplicateJobException;
27import org.springframework.batch.core.configuration.JobFactory;
28import org.springframework.batch.core.configuration.ListableJobRegistry;
29import org.springframework.batch.core.launch.NoSuchJobException;
30import org.springframework.beans.BeansException;
31import org.springframework.beans.factory.InitializingBean;
32import org.springframework.context.ApplicationContext;
33import org.springframework.context.ApplicationContextAware;
34import org.springframework.core.io.Resource;
35 
36/**
37 * Implementation of the {@link ListableJobRegistry} interface that assumes all
38 * Jobs will be loaded from ClassPathXml resources.
39 * 
40 * @author Lucas Ward
41 * @author Dave Syer
42 * @since 2.0
43 */
44public class ClassPathXmlJobRegistry implements ListableJobRegistry, ApplicationContextAware, InitializingBean {
45 
46        private static Log logger = LogFactory.getLog(ClassPathXmlJobRegistry.class);
47 
48        private List<Resource> jobPaths;
49 
50        private ApplicationContext parent;
51 
52        private ListableJobRegistry jobRegistry = new MapJobRegistry();
53 
54        public void setJobPaths(Resource[] jobPaths) {
55                this.jobPaths = Arrays.asList(jobPaths);
56        }
57 
58        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
59                parent = applicationContext;
60        }
61 
62        public Job getJob(String name) throws NoSuchJobException {
63                return jobRegistry.getJob(name);
64        }
65 
66        public void afterPropertiesSet() throws Exception {
67 
68                for (Resource resource : jobPaths) {
69                        ClassPathXmlApplicationContextFactory applicationContextFactory = new ClassPathXmlApplicationContextFactory();
70                        applicationContextFactory.setPath(resource);
71                        applicationContextFactory.setApplicationContext(parent);
72                        ApplicationContext context = applicationContextFactory.createApplicationContext();
73                        String[] names = context.getBeanNamesForType(Job.class);
74 
75                        for (String name : names) {
76                                logger.debug("Registering job: " + name + " from context: " + resource);
77                                ApplicationContextJobFactory jobFactory = new ApplicationContextJobFactory(applicationContextFactory,
78                                                name);
79                                jobRegistry.register(jobFactory);
80                        }
81                }
82 
83                if (jobRegistry.getJobNames().isEmpty()) {
84                        throw new NoSuchJobException("Could not locate any jobs in resources provided.");
85                }
86 
87        }
88 
89        public Collection<String> getJobNames() {
90                return jobRegistry.getJobNames();
91        }
92 
93        public void register(JobFactory jobFactory) throws DuplicateJobException {
94                jobRegistry.register(jobFactory);
95        }
96 
97        public void unregister(String jobName) {
98                jobRegistry.unregister(jobName);
99        }
100}

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