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 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.Interpreter;
23  import ch.qos.logback.core.joran.spi.Pattern;
24  import ch.qos.logback.core.joran.spi.RuleStore;
25  
26  /**
27   * A minimal configurator extending GenericConfigurator.
28   * 
29   * @author Ceki Gücü
30   *
31   */
32  public class SimpleConfigurator extends GenericConfigurator {
33  
34    final Map<Pattern, Action> ruleMap;
35    final List<ImplicitAction> iaList;
36  
37    public SimpleConfigurator(Map<Pattern, Action> ruleMap) {
38      this(ruleMap, null);
39    }
40  
41    public SimpleConfigurator(Map<Pattern, Action> ruleMap, List<ImplicitAction> iaList) {
42      this.ruleMap = ruleMap;
43      this.iaList = iaList;
44    }
45  
46    @Override
47    protected void addInstanceRules(RuleStore rs) {
48      for (Pattern pattern : ruleMap.keySet()) {
49        Action action = ruleMap.get(pattern);
50        rs.addRule(pattern, action);
51      }
52    }
53  
54    @Override
55    protected void addImplicitRules(Interpreter interpreter) {
56      if(iaList == null) {
57        return;
58      }
59      for (ImplicitAction ia : iaList) {
60        interpreter.addImplicitAction(ia);
61      }
62    }
63  
64  }