EMMA Coverage Report (generated Fri Jan 30 13:20:29 EST 2009)
[all classes][org.springframework.batch.repeat.callback]

COVERAGE SUMMARY FOR SOURCE FILE [ItemReaderRepeatCallback.java]

nameclass, %method, %block, %line, %
ItemReaderRepeatCallback.java100% (1/1)100% (3/3)100% (35/35)100% (14/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ItemReaderRepeatCallback100% (1/1)100% (3/3)100% (35/35)100% (14/14)
ItemReaderRepeatCallback (ItemReader): void 100% (1/1)100% (5/5)100% (2/2)
ItemReaderRepeatCallback (ItemReader, ItemWriter): void 100% (1/1)100% (9/9)100% (4/4)
doInIteration (RepeatContext): ExitStatus 100% (1/1)100% (21/21)100% (8/8)

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.repeat.callback;
18 
19import org.springframework.batch.item.ItemReader;
20import org.springframework.batch.item.ItemWriter;
21import org.springframework.batch.repeat.ExitStatus;
22import org.springframework.batch.repeat.RepeatCallback;
23import org.springframework.batch.repeat.RepeatContext;
24 
25/**
26 * Simple wrapper for two business interfaces: get the next item from a
27 * reader and apply the given writer to the result (if not null).
28 * 
29 * @author Dave Syer
30 * 
31 */
32public class ItemReaderRepeatCallback implements RepeatCallback {
33 
34        ItemReader provider;
35 
36        ItemWriter writer;
37 
38        public ItemReaderRepeatCallback(ItemReader provider, ItemWriter writer) {
39                super();
40                this.provider = provider;
41                this.writer = writer;
42        }
43 
44        /**
45         * Default writer is null, in which case we do nothing - subclasses can
46         * extend this behaviour, but must be careful to actually exhaust the
47         * provider by calling next().
48         * @param provider
49         */
50        public ItemReaderRepeatCallback(ItemReader provider) {
51                this(provider, null);
52        }
53 
54        /**
55         * Use the writer to process the next item if there is one. Return the
56         * item processed, or null if nothing was available.
57         * @see org.springframework.batch.repeat.RepeatCallback#doInIteration(RepeatContext)
58         * @param context the current context.
59         * @return null if the data provider is exhausted.
60         */
61        public ExitStatus doInIteration(RepeatContext context) throws Exception {
62 
63                ExitStatus result = ExitStatus.FINISHED;
64                Object item = provider.read();
65 
66                if (writer != null) {
67                        if (item != null) {
68                                writer.write(item);
69                                result = ExitStatus.CONTINUABLE;
70                        }
71                        item = null;
72                }
73 
74                return result;
75        }
76 
77}

[all classes][org.springframework.batch.repeat.callback]
EMMA 2.0.5312 (C) Vladimir Roubtsov