View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2011, 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.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  }