1 | package org.springframework.batch.item.xml.stax; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.List; |
5 | |
6 | import javax.xml.stream.events.XMLEvent; |
7 | |
8 | /** |
9 | * Holds a list of XML events, typically corresponding to a single record. |
10 | * |
11 | * @deprecated no longer used, to be removed in 2.0 |
12 | * |
13 | * @author tomas.slanina |
14 | */ |
15 | class EventSequence { |
16 | |
17 | private static final int BEFORE_BEGINNING = -1; |
18 | |
19 | private List events; |
20 | |
21 | private int currentIndex; |
22 | |
23 | /** |
24 | * Creates instance of this class. |
25 | * |
26 | */ |
27 | public EventSequence() { |
28 | init(); |
29 | } |
30 | |
31 | /** |
32 | * Adds event to the list of stored events. |
33 | * |
34 | * @param event |
35 | */ |
36 | public void addEvent(XMLEvent event) { |
37 | events.add(event); |
38 | } |
39 | |
40 | /** |
41 | * Gets next XMLEvent from cache and moves cursor to next event. |
42 | * If cache contains no more events, null is returned. |
43 | */ |
44 | public XMLEvent nextEvent() { |
45 | return (hasNext()) ? (XMLEvent)events.get(++currentIndex) :null; |
46 | } |
47 | |
48 | /** |
49 | * Gets next XMLEvent from cache but cursor remains on the same position. |
50 | * If cache contains no more events, null is returned. |
51 | */ |
52 | public XMLEvent peek() { |
53 | return (hasNext()) ? (XMLEvent)events.get(currentIndex+1) :null; |
54 | } |
55 | |
56 | /** |
57 | * Removes events from the internal cache. |
58 | * |
59 | */ |
60 | public void clear() { |
61 | init(); |
62 | } |
63 | |
64 | /** |
65 | * Resets cursor to the cache start. |
66 | * |
67 | */ |
68 | public void reset() { |
69 | currentIndex = BEFORE_BEGINNING; |
70 | } |
71 | |
72 | /** |
73 | * Check if there are more events. Returns true if there are more events and |
74 | * false otherwise. |
75 | * |
76 | * @return true if the event reader has more events, false otherwise |
77 | */ |
78 | public boolean hasNext() { |
79 | return currentIndex + 1 < events.size(); |
80 | } |
81 | |
82 | private void init() { |
83 | events = (events != null) ? new ArrayList(events.size()) |
84 | : new ArrayList(1000); |
85 | |
86 | reset(); |
87 | } |
88 | |
89 | |
90 | } |