| 1 | package org.springframework.batch.item.support; |
| 2 | |
| 3 | import java.util.Iterator; |
| 4 | import java.util.List; |
| 5 | |
| 6 | import org.springframework.batch.item.ClearFailedException; |
| 7 | import org.springframework.batch.item.FlushFailedException; |
| 8 | import org.springframework.batch.item.ItemWriter; |
| 9 | |
| 10 | /** |
| 11 | * Calls a collection of ItemWriters in fixed-order sequence. |
| 12 | * |
| 13 | * @author Robert Kasanicky |
| 14 | */ |
| 15 | public class CompositeItemWriter implements ItemWriter { |
| 16 | |
| 17 | private List delegates; |
| 18 | |
| 19 | public void setDelegates(List delegates) { |
| 20 | this.delegates = delegates; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Calls injected ItemProcessors in order. |
| 25 | */ |
| 26 | public void write(Object data) throws Exception { |
| 27 | for (Iterator iterator = delegates.listIterator(); iterator.hasNext();) { |
| 28 | ((ItemWriter) iterator.next()).write(data); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | public void clear() throws ClearFailedException { |
| 33 | for (Iterator iterator = delegates.listIterator(); iterator.hasNext();) { |
| 34 | ((ItemWriter) iterator.next()).clear(); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | public void flush() throws FlushFailedException { |
| 39 | for (Iterator iterator = delegates.listIterator(); iterator.hasNext();) { |
| 40 | ((ItemWriter) iterator.next()).flush(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | } |