View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2008, 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  package ch.qos.logback.access.sift;
11  
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  import org.xml.sax.Attributes;
16  
17  import ch.qos.logback.core.joran.action.Action;
18  import ch.qos.logback.core.joran.event.InPlayListener;
19  import ch.qos.logback.core.joran.event.SaxEvent;
20  import ch.qos.logback.core.joran.spi.ActionException;
21  import ch.qos.logback.core.joran.spi.InterpretationContext;
22  
23  public class SiftAction  extends Action implements InPlayListener {
24    List<SaxEvent> seList;
25    
26    @Override
27    public void begin(InterpretationContext ec, String name, Attributes attributes)
28        throws ActionException {
29      seList = new ArrayList<SaxEvent>();
30      ec.addInPlayListener(this);
31    }
32  
33    @Override
34    public void end(InterpretationContext ec, String name) throws ActionException {
35      ec.removeInPlayListener(this);
36      Object o = ec.peekObject();
37      if (o instanceof SiftingAppender) {
38        SiftingAppender siftingAppender = (SiftingAppender) o; 
39        AppenderFactory appenderFactory = new AppenderFactory(context, seList, siftingAppender.getDiscriminatorKey());
40        siftingAppender.setAppenderFactory(appenderFactory);
41      }
42    }
43  
44    public void inPlay(SaxEvent event) {
45      seList.add(event);
46    }
47  
48    public List<SaxEvent> getSeList() {
49      return seList;
50    }
51  
52      
53  
54  
55  }