View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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 chapters.onJoran;
15  
16  import java.util.List;
17  import java.util.Map;
18  
19  import ch.qos.logback.core.joran.GenericConfigurator;
20  import ch.qos.logback.core.joran.action.Action;
21  import ch.qos.logback.core.joran.action.ImplicitAction;
22  import ch.qos.logback.core.joran.spi.ElementPath;
23  import ch.qos.logback.core.joran.spi.Interpreter;
24  import ch.qos.logback.core.joran.spi.ElementSelector;
25  import ch.qos.logback.core.joran.spi.RuleStore;
26  
27  /**
28   * A minimal configurator extending GenericConfigurator.
29   * 
30   * @author Ceki Gülcü
31   *
32   */
33  public class SimpleConfigurator extends GenericConfigurator {
34  
35      final Map<ElementSelector, Action> ruleMap;
36      final List<ImplicitAction> iaList;
37  
38      public SimpleConfigurator(Map<ElementSelector, Action> ruleMap) {
39          this(ruleMap, null);
40      }
41  
42      public SimpleConfigurator(Map<ElementSelector, Action> ruleMap, List<ImplicitAction> iaList) {
43          this.ruleMap = ruleMap;
44          this.iaList = iaList;
45      }
46  
47      @Override
48      protected void addInstanceRules(RuleStore rs) {
49          for (ElementSelector elementSelector : ruleMap.keySet()) {
50              Action action = ruleMap.get(elementSelector);
51              rs.addRule(elementSelector, action);
52          }
53      }
54  
55      @Override
56      protected void addImplicitRules(Interpreter interpreter) {
57          if (iaList == null) {
58              return;
59          }
60          for (ImplicitAction ia : iaList) {
61              interpreter.addImplicitAction(ia);
62          }
63      }
64  }