EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.item.file.mapping]

COVERAGE SUMMARY FOR SOURCE FILE [PatternMatchingCompositeLineMapper.java]

nameclass, %method, %block, %line, %
PatternMatchingCompositeLineMapper.java100% (1/1)80%  (4/5)76%  (39/51)73%  (8/11)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PatternMatchingCompositeLineMapper100% (1/1)80%  (4/5)76%  (39/51)73%  (8/11)
afterPropertiesSet (): void 0%   (0/1)0%   (0/12)0%   (0/3)
PatternMatchingCompositeLineMapper (): void 100% (1/1)100% (8/8)100% (2/2)
mapLine (String, int): Object 100% (1/1)100% (11/11)100% (1/1)
setFieldSetMappers (Map): void 100% (1/1)100% (15/15)100% (3/3)
setTokenizers (Map): 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.item.file.mapping;
18 
19import java.util.Map;
20 
21import org.springframework.batch.item.file.LineMapper;
22import org.springframework.batch.item.file.transform.LineTokenizer;
23import org.springframework.batch.item.file.transform.PatternMatchingCompositeLineTokenizer;
24import org.springframework.batch.support.PatternMatcher;
25import org.springframework.beans.factory.InitializingBean;
26import org.springframework.util.Assert;
27 
28/**
29 * <p>
30 * A {@link LineMapper} implementation that stores a mapping of String patterns
31 * to delegate {@link LineTokenizer}s as well as a mapping of String patterns to
32 * delegate {@link FieldSetMapper}s. Each line received will be tokenized and
33 * then mapped to a field set.
34 * 
35 * <p>
36 * Both the tokenizing and the mapping work in a similar way. The line will be
37 * checked for its matching pattern. If the key matches a pattern in the map of
38 * delegates, then the corresponding delegate will be used. Patterns are sorted
39 * starting with the most specific, and the first match succeeds.
40 * 
41 * @see PatternMatchingCompositeLineTokenizer
42 * 
43 * @author Dan Garrette
44 * @author Dave Syer
45 * @since 2.0
46 */
47public class PatternMatchingCompositeLineMapper<T> implements LineMapper<T>, InitializingBean {
48 
49        private PatternMatchingCompositeLineTokenizer tokenizer = new PatternMatchingCompositeLineTokenizer();
50 
51        private PatternMatcher<FieldSetMapper<T>> patternMatcher;
52 
53        /*
54         * (non-Javadoc)
55         * 
56         * @see
57         * org.springframework.batch.item.file.mapping.LineMapper#mapLine(java.lang
58         * .String, int)
59         */
60    @Override
61        public T mapLine(String line, int lineNumber) throws Exception {
62                return patternMatcher.match(line).mapFieldSet(this.tokenizer.tokenize(line));
63        }
64 
65        /*
66         * (non-Javadoc)
67         * 
68         * @see
69         * org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
70         */
71    @Override
72        public void afterPropertiesSet() throws Exception {
73                this.tokenizer.afterPropertiesSet();
74                Assert.isTrue(this.patternMatcher != null, "The 'fieldSetMappers' property must be non-empty");
75        }
76 
77        public void setTokenizers(Map<String, LineTokenizer> tokenizers) {
78                this.tokenizer.setTokenizers(tokenizers);
79        }
80 
81        public void setFieldSetMappers(Map<String, FieldSetMapper<T>> fieldSetMappers) {
82                Assert.isTrue(!fieldSetMappers.isEmpty(), "The 'fieldSetMappers' property must be non-empty");
83                this.patternMatcher = new PatternMatcher<FieldSetMapper<T>>(fieldSetMappers);
84        }
85}

[all classes][org.springframework.batch.item.file.mapping]
EMMA 2.0.5312 (C) Vladimir Roubtsov