1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.sift;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.xml.sax.Attributes;
20
21 import ch.qos.logback.core.joran.action.Action;
22 import ch.qos.logback.core.joran.event.InPlayListener;
23 import ch.qos.logback.core.joran.event.SaxEvent;
24 import ch.qos.logback.core.joran.spi.ActionException;
25 import ch.qos.logback.core.joran.spi.InterpretationContext;
26
27 public class SiftAction extends Action implements InPlayListener {
28 List<SaxEvent> seList;
29
30 @Override
31 public void begin(InterpretationContext ec, String name, Attributes attributes)
32 throws ActionException {
33 seList = new ArrayList<SaxEvent>();
34 ec.addInPlayListener(this);
35 }
36
37 @Override
38 public void end(InterpretationContext ec, String name) throws ActionException {
39 ec.removeInPlayListener(this);
40 Object o = ec.peekObject();
41 if (o instanceof SiftingAppender) {
42 SiftingAppender sa = (SiftingAppender) o;
43 AppenderFactory appenderFactory = new AppenderFactory(seList, sa
44 .getDiscriminatorKey());
45 sa.setAppenderFactory(appenderFactory);
46 }
47 }
48
49 public void inPlay(SaxEvent event) {
50 seList.add(event);
51 }
52
53 public List<SaxEvent> getSeList() {
54 return seList;
55 }
56
57 }