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

COVERAGE SUMMARY FOR SOURCE FILE [CompositeItemProcessor.java]

nameclass, %method, %block, %line, %
CompositeItemProcessor.java100% (1/1)100% (5/5)100% (45/45)100% (14/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CompositeItemProcessor100% (1/1)100% (5/5)100% (45/45)100% (14/14)
CompositeItemProcessor (): void 100% (1/1)100% (3/3)100% (1/1)
afterPropertiesSet (): void 100% (1/1)100% (9/9)100% (3/3)
process (Object): Object 100% (1/1)100% (25/25)100% (7/7)
processItem (ItemProcessor, Object): Object 100% (1/1)100% (4/4)100% (1/1)
setDelegates (List): 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.item.support;
18 
19import java.util.List;
20 
21import org.springframework.batch.item.ItemProcessor;
22import org.springframework.beans.factory.InitializingBean;
23import org.springframework.util.Assert;
24 
25/**
26 * Composite {@link ItemProcessor} that passes the item through a sequence of
27 * injected <code>ItemTransformer</code>s (return value of previous
28 * transformation is the entry value of the next).<br/>
29 * <br/>
30 * 
31 * Note the user is responsible for injecting a chain of {@link ItemProcessor}s
32 * that conforms to declared input and output types.
33 * 
34 * @author Robert Kasanicky
35 */
36public class CompositeItemProcessor<I, O> implements ItemProcessor<I, O>, InitializingBean {
37 
38        private List<? extends ItemProcessor<?, ?>> delegates;
39 
40        @Override
41        @SuppressWarnings("unchecked")
42        public O process(I item) throws Exception {
43                Object result = item;
44 
45                for (ItemProcessor<?, ?> delegate : delegates) {
46                        if (result == null) {
47                                return null;
48                        }
49 
50                        result = processItem(delegate, result);
51                }
52                return (O) result;
53        }
54    
55    /* 
56     * Helper method to work around wildcard capture compiler error: see http://docs.oracle.com/javase/tutorial/java/generics/capture.html
57     * The method process(capture#1-of ?) in the type ItemProcessor<capture#1-of ?,capture#2-of ?> is not applicable for the arguments (Object)
58     */
59    @SuppressWarnings("unchecked")
60        private <T> Object processItem(ItemProcessor<T, ?> processor, Object input) throws Exception {
61            return processor.process((T) input);
62    }
63 
64        @Override
65        public void afterPropertiesSet() throws Exception {
66                Assert.notNull(delegates, "The 'delegates' may not be null");
67                Assert.notEmpty(delegates, "The 'delegates' may not be empty");
68        }
69 
70        public void setDelegates(List<? extends ItemProcessor<?, ?>> delegates) {
71                this.delegates = delegates;
72        }        
73 
74}

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