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