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 ch.qos.logback.core.joran;
11  
12  import java.util.HashMap;
13  
14  import ch.qos.logback.core.joran.GenericConfigurator;
15  import ch.qos.logback.core.joran.action.Action;
16  import ch.qos.logback.core.joran.action.NestedComplexPropertyIA;
17  import ch.qos.logback.core.joran.action.NestedBasicPropertyIA;
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    HashMap<Pattern, Action> rulesMap;
25    
26    public SimpleConfigurator(HashMap<Pattern, Action> rules) {
27      this.rulesMap = rules;
28    }
29    
30    @Override
31    protected void addImplicitRules(Interpreter interpreter) {
32      NestedComplexPropertyIA nestedIA = new NestedComplexPropertyIA();
33      nestedIA.setContext(context);
34      interpreter.addImplicitAction(nestedIA);
35  
36      NestedBasicPropertyIA nestedSimpleIA = new NestedBasicPropertyIA();
37      nestedSimpleIA.setContext(context);
38      interpreter.addImplicitAction(nestedSimpleIA);
39    }
40  
41    @Override
42    protected void addInstanceRules(RuleStore rs) {
43      for(Pattern pattern : rulesMap.keySet()) {
44        Action action = rulesMap.get(pattern);
45        rs.addRule(pattern, action);
46      }
47    }
48  
49  }