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 | |
17 | package org.springframework.batch.item.support; |
18 | |
19 | import org.springframework.batch.item.AbstractItemReader; |
20 | import org.springframework.batch.item.ItemReader; |
21 | import org.springframework.beans.factory.InitializingBean; |
22 | import org.springframework.util.Assert; |
23 | |
24 | /** |
25 | * Simple wrapper around {@link ItemReader}. The input source is expected to |
26 | * take care of open and close operations. If necessary it should be registered |
27 | * as a step scoped bean to ensure that the lifecycle methods are called. |
28 | * |
29 | * @author Dave Syer |
30 | */ |
31 | public class DelegatingItemReader extends AbstractItemReader implements InitializingBean { |
32 | |
33 | private ItemReader itemReader; |
34 | |
35 | /** |
36 | * Default constructor. |
37 | */ |
38 | public DelegatingItemReader() { |
39 | super(); |
40 | } |
41 | |
42 | /** |
43 | * Convenience constructor for setting mandatory property. |
44 | */ |
45 | public DelegatingItemReader(ItemReader itemReader) { |
46 | this(); |
47 | this.itemReader = itemReader; |
48 | } |
49 | |
50 | public void afterPropertiesSet() throws Exception { |
51 | Assert.notNull(itemReader, "ItemReader must not be null."); |
52 | } |
53 | |
54 | /** |
55 | * Get the next object from the input source. |
56 | * @throws Exception |
57 | * @see org.springframework.batch.item.ItemReader#read() |
58 | */ |
59 | public Object read() throws Exception { |
60 | return itemReader.read(); |
61 | } |
62 | |
63 | /** |
64 | * Setter for input source. |
65 | * @param source |
66 | */ |
67 | public void setItemReader(ItemReader source) { |
68 | this.itemReader = source; |
69 | } |
70 | |
71 | /* |
72 | * (non-Javadoc) |
73 | * @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionContext) |
74 | */ |
75 | public void mark() { |
76 | itemReader.mark(); |
77 | } |
78 | |
79 | /* |
80 | * (non-Javadoc) |
81 | * @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionContext) |
82 | */ |
83 | public void reset() { |
84 | itemReader.reset(); |
85 | } |
86 | } |