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