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.core.sift;
11  
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  import ch.qos.logback.core.Appender;
16  import ch.qos.logback.core.Context;
17  import ch.qos.logback.core.joran.event.SaxEvent;
18  import ch.qos.logback.core.joran.spi.JoranException;
19  
20  public abstract class AppenderFactoryBase<E> {
21  
22    final List<SaxEvent> eventList;
23    Context context;
24    
25    protected AppenderFactoryBase(Context context, List<SaxEvent> eventList) {
26      this.context = context;
27      this.eventList = new ArrayList<SaxEvent>(eventList);
28      removeHoardElement();
29  
30    }
31  
32    void removeHoardElement() {
33      eventList.remove(0);
34      eventList.remove(eventList.size() - 1);
35    }
36  
37    public abstract SiftingJoranConfiguratorBase<E> getSiftingJoranConfigurator(String k);
38    
39    Appender<E> buildAppender(Context context, String k) throws JoranException {
40      SiftingJoranConfiguratorBase<E> sjc = getSiftingJoranConfigurator(k);
41      sjc.setContext(context);
42      sjc.doConfigure(eventList);
43      return sjc.getAppender();
44    }
45  
46    public List<SaxEvent> getEventList() {
47      return eventList;
48    }
49  
50  }