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 | package org.springframework.batch.core.listener; |
17 | |
18 | import java.util.ArrayList; |
19 | import java.util.Arrays; |
20 | import java.util.Iterator; |
21 | import java.util.List; |
22 | |
23 | import org.springframework.batch.core.SkipListener; |
24 | |
25 | /** |
26 | * @author Dave Syer |
27 | * |
28 | */ |
29 | public class CompositeSkipListener implements SkipListener { |
30 | |
31 | private List listeners = new ArrayList(); |
32 | |
33 | /** |
34 | * Public setter for the listeners. |
35 | * |
36 | * @param listeners |
37 | */ |
38 | public void setListeners(SkipListener[] listeners) { |
39 | this.listeners = Arrays.asList(listeners); |
40 | } |
41 | |
42 | /** |
43 | * Register additional listener. |
44 | * |
45 | * @param listener |
46 | */ |
47 | public void register(SkipListener listener) { |
48 | if (!listeners.contains(listener)) { |
49 | listeners.add(listener); |
50 | } |
51 | } |
52 | |
53 | /* (non-Javadoc) |
54 | * @see org.springframework.batch.core.SkipListener#onSkipInRead(java.lang.Throwable) |
55 | */ |
56 | public void onSkipInRead(Throwable t) { |
57 | for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { |
58 | SkipListener listener = (SkipListener) iterator.next(); |
59 | listener.onSkipInRead(t); |
60 | } |
61 | } |
62 | |
63 | /* (non-Javadoc) |
64 | * @see org.springframework.batch.core.SkipListener#onSkipInWrite(java.lang.Object, java.lang.Throwable) |
65 | */ |
66 | public void onSkipInWrite(Object item, Throwable t) { |
67 | for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { |
68 | SkipListener listener = (SkipListener) iterator.next(); |
69 | listener.onSkipInWrite(item, t); |
70 | } |
71 | } |
72 | } |