View Javadoc

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