1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.joran.spi;
15
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import ch.qos.logback.core.joran.event.BodyEvent;
21 import ch.qos.logback.core.joran.event.EndEvent;
22 import ch.qos.logback.core.joran.event.SaxEvent;
23 import ch.qos.logback.core.joran.event.StartEvent;
24
25 public class EventPlayer {
26
27 final SaxEventInterpreter interpreter;
28 final List<SaxEvent> saxEvents;
29 int currentIndex;
30
31 public EventPlayer(SaxEventInterpreter interpreter, List<SaxEvent> saxEvents) {
32 this.interpreter = interpreter;
33 this.saxEvents = saxEvents;
34 }
35
36
37
38
39
40
41
42 public List<SaxEvent> getCopyOfPlayerEventList() {
43 return new ArrayList<SaxEvent>(saxEvents);
44 }
45
46 public void play() {
47
48 for (currentIndex = 0; currentIndex < saxEvents.size(); currentIndex++) {
49 SaxEvent se = saxEvents.get(currentIndex);
50
51 if (se instanceof StartEvent) {
52 interpreter.startElement((StartEvent) se);
53 continue;
54 }
55 if (se instanceof BodyEvent) {
56 interpreter.characters((BodyEvent) se);
57 continue;
58 }
59 if (se instanceof EndEvent) {
60 interpreter.endElement((EndEvent) se);
61 continue;
62 }
63
64 }
65 }
66
67 public void addEventsDynamically(List<SaxEvent> eventList, int offset) {
68 this.saxEvents.addAll(currentIndex + offset, eventList);
69 }
70 }