EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.core.configuration.support]

COVERAGE SUMMARY FOR SOURCE FILE [MapStepRegistry.java]

nameclass, %method, %block, %line, %
MapStepRegistry.java100% (1/1)100% (4/4)100% (125/125)100% (23/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapStepRegistry100% (1/1)100% (4/4)100% (125/125)100% (23/23)
MapStepRegistry (): void 100% (1/1)100% (8/8)100% (2/2)
getStep (String, String): Step 100% (1/1)100% (58/58)100% (8/8)
register (String, Collection): void 100% (1/1)100% (50/50)100% (10/10)
unregisterStepsFromJob (String): void 100% (1/1)100% (9/9)100% (3/3)

1/*
2 * Copyright 2012-2013 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.HashMap;
20import java.util.Map;
21import java.util.concurrent.ConcurrentHashMap;
22import java.util.concurrent.ConcurrentMap;
23 
24import org.springframework.batch.core.Step;
25import org.springframework.batch.core.configuration.DuplicateJobException;
26import org.springframework.batch.core.configuration.StepRegistry;
27import org.springframework.batch.core.launch.NoSuchJobException;
28import org.springframework.batch.core.step.NoSuchStepException;
29import org.springframework.util.Assert;
30 
31/**
32 * Simple map-based implementation of {@link StepRegistry}. Access to the map is
33 * synchronized, guarded by an internal lock.
34 *
35 * @author Sebastien Gerard
36 * @author Stephane Nicoll
37 */
38public class MapStepRegistry implements StepRegistry {
39 
40        private final ConcurrentMap<String, Map<String, Step>> map = new ConcurrentHashMap<String, Map<String, Step>>();
41 
42        @Override
43        public void register(String jobName, Collection<Step> steps) throws DuplicateJobException {
44                Assert.notNull(jobName, "The job name cannot be null.");
45                Assert.notNull(steps, "The job steps cannot be null.");
46 
47 
48                final Map<String, Step> jobSteps = new HashMap<String, Step>();
49                for (Step step : steps) {
50                        jobSteps.put(step.getName(), step);
51                }
52                final Object previousValue = map.putIfAbsent(jobName, jobSteps);
53                if (previousValue != null) {
54                        throw new DuplicateJobException("A job configuration with this name [" + jobName
55                                        + "] was already registered");
56                }
57        }
58 
59        @Override
60        public void unregisterStepsFromJob(String jobName) {
61                Assert.notNull(jobName, "Job configuration must have a name.");
62                map.remove(jobName);
63        }
64 
65        @Override
66        public Step getStep(String jobName, String stepName) throws NoSuchJobException {
67                Assert.notNull(jobName, "The job name cannot be null.");
68                Assert.notNull(stepName, "The step name cannot be null.");
69                if (!map.containsKey(jobName)) {
70                        throw new NoSuchJobException("No job configuration with the name [" + jobName + "] was registered");
71                } else {
72                        final Map<String, Step> jobSteps = map.get(jobName);
73                        if (jobSteps.containsKey(stepName)) {
74                                return jobSteps.get(stepName);
75                        } else {
76                                throw new NoSuchStepException("The step called [" + stepName + "] does not exist in the job [" +
77                                                jobName + "]");
78                        }
79                }
80        }
81 
82}

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