View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.joran.replay;
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 FruitFactoryAction extends Action implements InPlayListener {
28  
29      List<SaxEvent> seList = new ArrayList<SaxEvent>();
30  
31      @Override
32      public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException {
33          ec.addInPlayListener(this);
34      }
35  
36      @Override
37      public void end(InterpretationContext ec, String name) throws ActionException {
38          ec.removeInPlayListener(this);
39  
40          Object o = ec.peekObject();
41          if (o instanceof FruitShell) {
42              FruitShell fs = (FruitShell) o;
43              FruitFactory fruitFactory = new FruitFactory();
44              fruitFactory.setEventList(new ArrayList<SaxEvent>(seList));
45              fs.setFruitFactory(fruitFactory);
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  }