EMMA Coverage Report (generated Fri Aug 21 15:59:46 BST 2009)
[all classes][org.springframework.batch.core.partition.support]

COVERAGE SUMMARY FOR SOURCE FILE [MultiResourcePartitioner.java]

nameclass, %method, %block, %line, %
MultiResourcePartitioner.java100% (1/1)100% (4/4)86%  (78/91)89%  (16/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MultiResourcePartitioner100% (1/1)100% (4/4)86%  (78/91)89%  (16/18)
partition (int): Map 100% (1/1)82%  (60/73)82%  (9/11)
MultiResourcePartitioner (): void 100% (1/1)100% (10/10)100% (3/3)
setKeyName (String): void 100% (1/1)100% (4/4)100% (2/2)
setResources (Resource []): 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 */
16 
17package org.springframework.batch.core.partition.support;
18 
19import java.io.IOException;
20import java.util.HashMap;
21import java.util.Map;
22 
23import org.springframework.batch.item.ExecutionContext;
24import org.springframework.core.io.Resource;
25import org.springframework.util.Assert;
26 
27/**
28 * Implementation of {@link Partitioner} that locates multiple resources and
29 * associates their file names with execution context keys. Creates an
30 * {@link ExecutionContext} per resource, and labels them as
31 * <code>{partition0, partition1, ..., partitionN}</code>. The grid size is
32 * ignored.
33 * 
34 * @author Dave Syer
35 * @since 2.0
36 */
37public class MultiResourcePartitioner implements Partitioner {
38 
39        private static final String DEFAULT_KEY_NAME = "fileName";
40 
41        private static final String PARTITION_KEY = "partition";
42 
43        private Resource[] resources = new Resource[0];
44 
45        private String keyName = DEFAULT_KEY_NAME;
46 
47        /**
48         * The resources to assign to each partition. In Spring configuration you
49         * can use a pattern to select multiple resources.
50         * @param resources the resources to use
51         */
52        public void setResources(Resource[] resources) {
53                this.resources = resources;
54        }
55 
56        /**
57         * The name of the key for the file name in each {@link ExecutionContext}.
58         * Defaults to "fileName".
59         * @param keyName the value of the key
60         */
61        public void setKeyName(String keyName) {
62                this.keyName = keyName;
63        }
64 
65        /**
66         * Assign the filename of each of the injected resources to an
67         * {@link ExecutionContext}.
68         * 
69         * @see Partitioner#partition(int)
70         */
71        public Map<String, ExecutionContext> partition(int gridSize) {
72                Map<String, ExecutionContext> map = new HashMap<String, ExecutionContext>(gridSize);
73                int i = 0;
74                for (Resource resource : resources) {
75                        ExecutionContext context = new ExecutionContext();
76                        Assert.state(resource.exists(), "Resource does not exist: "+resource);
77                        try {
78                                context.putString(keyName, resource.getURL().toExternalForm());
79                        }
80                        catch (IOException e) {
81                                throw new IllegalArgumentException("File could not be located for: "+resource, e);
82                        }
83                        map.put(PARTITION_KEY + i, context);
84                        i++;
85                }
86                return map;
87        }
88 
89}

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