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

COVERAGE SUMMARY FOR SOURCE FILE [SimpleItemHandler.java]

nameclass, %method, %block, %line, %
SimpleItemHandler.java100% (1/1)100% (10/10)100% (62/62)100% (25/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleItemHandler100% (1/1)100% (10/10)100% (62/62)100% (25/25)
SimpleItemHandler (ItemReader, ItemWriter): void 100% (1/1)100% (14/14)100% (5/5)
clear (): void 100% (1/1)100% (4/4)100% (2/2)
doRead (): Object 100% (1/1)100% (4/4)100% (1/1)
doWrite (Object): void 100% (1/1)100% (5/5)100% (2/2)
flush (): void 100% (1/1)100% (4/4)100% (2/2)
handle (StepContribution): ExitStatus 100% (1/1)100% (16/16)100% (6/6)
mark (): void 100% (1/1)100% (4/4)100% (2/2)
read (StepContribution): Object 100% (1/1)100% (3/3)100% (1/1)
reset (): void 100% (1/1)100% (4/4)100% (2/2)
write (Object, StepContribution): 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 */
16package org.springframework.batch.core.step.item;
17 
18import org.apache.commons.logging.Log;
19import org.apache.commons.logging.LogFactory;
20import org.springframework.batch.core.StepContribution;
21import org.springframework.batch.item.ClearFailedException;
22import org.springframework.batch.item.FlushFailedException;
23import org.springframework.batch.item.ItemReader;
24import org.springframework.batch.item.ItemWriter;
25import org.springframework.batch.item.MarkFailedException;
26import org.springframework.batch.item.ResetFailedException;
27import org.springframework.batch.repeat.ExitStatus;
28 
29/**
30 * Simplest possible implementation of {@link ItemHandler} with no skipping or
31 * recovering. Just delegates all calls to the provided {@link ItemReader} and
32 * {@link ItemWriter}.
33 * 
34 * Provides extension points by protected {@link #read(StepContribution)} and
35 * {@link #write(Object, StepContribution)} methods that can be overriden to
36 * provide more sophisticated behavior (e.g. skipping).
37 * 
38 * @author Dave Syer
39 * @author Robert Kasanicky
40 */
41public class SimpleItemHandler implements ItemHandler {
42 
43        protected final Log logger = LogFactory.getLog(getClass());
44 
45        private ItemReader itemReader;
46 
47        private ItemWriter itemWriter;
48 
49        /**
50         * @param itemReader
51         * @param itemWriter
52         */
53        public SimpleItemHandler(ItemReader itemReader, ItemWriter itemWriter) {
54                super();
55                this.itemReader = itemReader;
56                this.itemWriter = itemWriter;
57        }
58 
59        /**
60         * Get the next item from {@link #read(StepContribution)} and if not null
61         * pass the item to {@link #write(Object, StepContribution)}.
62         * 
63         * @see org.springframework.batch.core.step.item.ItemHandler#handle(org.springframework.batch.core.StepContribution)
64         */
65        public ExitStatus handle(StepContribution contribution) throws Exception {
66                Object item = read(contribution);
67                if (item == null) {
68                        return ExitStatus.FINISHED;
69                }
70                contribution.incrementItemCount();
71                write(item, contribution);
72                return ExitStatus.CONTINUABLE;
73        }
74 
75        /**
76         * @param contribution current context
77         * @return next item for writing
78         */
79        protected Object read(StepContribution contribution) throws Exception {
80                return doRead();
81        }
82 
83        /**
84         * @return item
85         * @throws Exception
86         */
87        protected final Object doRead() throws Exception {
88                return itemReader.read();
89        }
90 
91        /**
92         * 
93         * @param item the item to write
94         * @param contribution current context
95         */
96        protected void write(Object item, StepContribution contribution) throws Exception {
97                doWrite(item);
98        }
99 
100        /**
101         * @param item
102         * @throws Exception
103         */
104        protected final void doWrite(Object item) throws Exception {
105                itemWriter.write(item);
106        }
107 
108        /**
109         * @throws MarkFailedException
110         * @see org.springframework.batch.item.ItemReader#mark()
111         */
112        public void mark() throws MarkFailedException {
113                itemReader.mark();
114        }
115 
116        /**
117         * @throws ResetFailedException
118         * @see org.springframework.batch.item.ItemReader#reset()
119         */
120        public void reset() throws ResetFailedException {
121                itemReader.reset();
122        }
123 
124        /**
125         * @throws ClearFailedException
126         * @see org.springframework.batch.item.ItemWriter#clear()
127         */
128        public void clear() throws ClearFailedException {
129                itemWriter.clear();
130        }
131 
132        /**
133         * @throws FlushFailedException
134         * @see org.springframework.batch.item.ItemWriter#flush()
135         */
136        public void flush() throws FlushFailedException {
137                itemWriter.flush();
138        }
139 
140}

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