EMMA Coverage Report (generated Thu Jan 24 13:37:04 CST 2013)
[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)100% (79/79)100% (17/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapJobRegistry100% (1/1)100% (5/5)100% (79/79)100% (17/17)
MapJobRegistry (): void 100% (1/1)100% (8/8)100% (2/2)
getJob (String): Job 100% (1/1)100% (25/25)100% (4/4)
getJobNames (): Set 100% (1/1)100% (5/5)100% (1/1)
register (JobFactory): void 100% (1/1)100% (32/32)100% (7/7)
unregister (String): void 100% (1/1)100% (9/9)100% (3/3)

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;
23import java.util.Set;
24 
25import java.util.concurrent.ConcurrentMap;
26import java.util.concurrent.ConcurrentHashMap;
27 
28import org.springframework.batch.core.Job;
29import org.springframework.batch.core.configuration.DuplicateJobException;
30import org.springframework.batch.core.configuration.JobFactory;
31import org.springframework.batch.core.configuration.JobRegistry;
32import org.springframework.batch.core.launch.NoSuchJobException;
33import org.springframework.util.Assert;
34 
35/**
36 * Simple, thread-safe, map-based implementation of {@link JobRegistry}. 
37 * 
38 * @author Dave Syer
39 * @author Robert Fischer
40 * 
41 */
42public class MapJobRegistry implements JobRegistry {
43 
44        /**
45        * The map holding the registered job factories.
46        */
47        // The "final" ensures that it is visible and initialized when the constructor resolves.
48        private final ConcurrentMap<String, JobFactory> map = new ConcurrentHashMap<String, JobFactory>();
49 
50        public void register(JobFactory jobFactory) throws DuplicateJobException {
51                Assert.notNull(jobFactory);
52                String name = jobFactory.getJobName();
53                Assert.notNull(name, "Job configuration must have a name.");
54                JobFactory previousValue = map.putIfAbsent(name, jobFactory);
55                if(previousValue != null) {
56                        throw new DuplicateJobException("A job configuration with this name [" + name
57                                        + "] was already registered");
58                }
59        }
60 
61        public void unregister(String name) {
62                Assert.notNull(name, "Job configuration must have a name.");
63                map.remove(name);
64        }
65 
66        public Job getJob(String name) throws NoSuchJobException {
67                JobFactory factory = map.get(name);
68                if(factory == null) {
69                        throw new NoSuchJobException("No job configuration with the name [" + name + "] was registered");
70                } else {
71                        return factory.createJob();
72                }
73        }
74 
75        /**
76        * Provides an unmodifiable view of the job names.
77        */
78        public Set<String> getJobNames() {
79                return Collections.unmodifiableSet(map.keySet());
80        }
81 
82}

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