1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework for Java.
3    * 
4    * Copyright (C) 2000-2006, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
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  }