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

nameclass, %method, %block, %line, %
MapJobRegistry.java100% (1/1)100% (5/5)93%  (125/135)95%  (22.8/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapJobRegistry100% (1/1)100% (5/5)93%  (125/135)95%  (22.8/24)
getJobNames (): Collection 100% (1/1)75%  (15/20)67%  (2/3)
unregister (String): void 100% (1/1)77%  (17/22)95%  (4.8/5)
MapJobRegistry (): void 100% (1/1)100% (8/8)100% (2/2)
getJob (String): Job 100% (1/1)100% (38/38)100% (5/5)
register (JobFactory): void 100% (1/1)100% (47/47)100% (9/9)

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.Collections;
20import java.util.HashMap;
21import java.util.HashSet;
22import java.util.Map;
23 
24import org.springframework.batch.core.Job;
25import org.springframework.batch.core.configuration.JobFactory;
26import org.springframework.batch.core.configuration.JobRegistry;
27import org.springframework.batch.core.configuration.ListableJobRegistry;
28import org.springframework.batch.core.repository.DuplicateJobException;
29import org.springframework.batch.core.repository.NoSuchJobException;
30import org.springframework.util.Assert;
31 
32/**
33 * Simple map-based implementation of {@link JobRegistry}. Access to the map is
34 * synchronized, guarded by an internal lock.
35 * 
36 * @author Dave Syer
37 * 
38 */
39public class MapJobRegistry implements ListableJobRegistry {
40 
41        private Map map = new HashMap();
42 
43        /*
44         * (non-Javadoc)
45         * @see org.springframework.batch.container.common.configuration.JobConfigurationRegistry#registerJobConfiguration(org.springframework.batch.container.common.configuration.JobConfiguration)
46         */
47        public void register(JobFactory jobFactory) throws DuplicateJobException {
48                Assert.notNull(jobFactory);
49                String name = jobFactory.getJobName();
50                Assert.notNull(name, "Job configuration must have a name.");
51                synchronized (map) {
52                        if (map.containsKey(name)) {
53                                throw new DuplicateJobException("A job configuration with this name [" + name
54                                                + "] was already registered");
55                        }
56                        map.put(name, jobFactory);
57                }
58        }
59 
60        /*
61         * (non-Javadoc)
62         * @see org.springframework.batch.container.common.configuration.JobConfigurationRegistry#unregister(org.springframework.batch.container.common.configuration.JobConfiguration)
63         */
64        public void unregister(String name) {
65                Assert.notNull(name, "Job configuration must have a name.");
66                synchronized (map) {
67                        map.remove(name);
68                }
69 
70        }
71 
72        /*
73         * (non-Javadoc)
74         * @see org.springframework.batch.container.common.configuration.JobConfigurationLocator#getJobConfiguration(java.lang.String)
75         */
76        public Job getJob(String name) throws NoSuchJobException {
77                synchronized (map) {
78                        if (!map.containsKey(name)) {
79                                throw new NoSuchJobException("No job configuration with the name [" + name + "] was registered");
80                        }
81                        return (Job) ((JobFactory) map.get(name)).createJob();
82                }
83        }
84 
85        /*
86         * (non-Javadoc)
87         * @see org.springframework.batch.container.common.configuration.ListableJobConfigurationRegistry#getJobConfigurations()
88         */
89        public Collection getJobNames() {
90                synchronized (map) {
91                        return Collections.unmodifiableCollection(new HashSet(map.keySet()));
92                }
93        }
94 
95}

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