1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.batch.item.support;
18
19 import java.util.List;
20
21 import org.springframework.batch.item.ItemProcessor;
22 import org.springframework.beans.factory.InitializingBean;
23 import org.springframework.util.Assert;
24
25
26
27
28
29
30
31
32
33
34
35
36 public class CompositeItemProcessor<I, O> implements ItemProcessor<I, O>, InitializingBean {
37
38 private List<ItemProcessor<Object, Object>> delegates;
39
40 @SuppressWarnings("unchecked")
41 public O process(I item) throws Exception {
42 Object result = item;
43
44 for (ItemProcessor<Object, Object> delegate : delegates) {
45 if (result == null) {
46 return null;
47 }
48 result = delegate.process(result);
49 }
50 return (O) result;
51 }
52
53 public void afterPropertiesSet() throws Exception {
54 Assert.notNull(delegates, "The 'delgates' may not be null");
55 Assert.notEmpty(delegates, "The 'delgates' may not be empty");
56 }
57
58 public void setDelegates(List<ItemProcessor<Object, Object>> delegates) {
59 this.delegates = delegates;
60 }
61
62 }