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