View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 1999-2006, 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 chapter3;
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  public class SimpleConfigurator extends GenericConfigurator {
23  
24    final Map<Pattern, Action> ruleMap;
25    final List<ImplicitAction> iaList;
26  
27    public SimpleConfigurator(Map<Pattern, Action> ruleMap) {
28      this(ruleMap, null);
29    }
30  
31    public SimpleConfigurator(Map<Pattern, Action> ruleMap, List<ImplicitAction> iaList) {
32      this.ruleMap = ruleMap;
33      this.iaList = iaList;
34    }
35  
36    @Override
37    protected void addInstanceRules(RuleStore rs) {
38  
39      for (Pattern pattern : ruleMap.keySet()) {
40        Action action = ruleMap.get(pattern);
41        rs.addRule(pattern, action);
42      }
43    }
44  
45    @Override
46    protected void addImplicitRules(Interpreter interpreter) {
47      if(iaList == null) {
48        return;
49      }
50      for (ImplicitAction ia : iaList) {
51        interpreter.addImplicitAction(ia);
52      }
53    }
54  
55  }