View Javadoc

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