View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework for Java.
3    * 
4    * Copyright (C) 2000-2007, 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  
11  package ch.qos.logback.core.joran;
12  
13  import java.util.HashMap;
14  import java.util.List;
15  import java.util.Map;
16  
17  import ch.qos.logback.core.joran.action.ActionConst;
18  import ch.qos.logback.core.joran.action.AppenderAction;
19  import ch.qos.logback.core.joran.action.AppenderRefAction;
20  import ch.qos.logback.core.joran.action.ContextPropertyAction;
21  import ch.qos.logback.core.joran.action.ConversionRuleAction;
22  import ch.qos.logback.core.joran.action.NestedBasicPropertyIA;
23  import ch.qos.logback.core.joran.action.NestedComplexPropertyIA;
24  import ch.qos.logback.core.joran.action.NewRuleAction;
25  import ch.qos.logback.core.joran.action.ParamAction;
26  import ch.qos.logback.core.joran.action.PropertyAction;
27  import ch.qos.logback.core.joran.action.StatusListenerAction;
28  import ch.qos.logback.core.joran.spi.InterpretationContext;
29  import ch.qos.logback.core.joran.spi.Interpreter;
30  import ch.qos.logback.core.joran.spi.Pattern;
31  import ch.qos.logback.core.joran.spi.RuleStore;
32  
33  // Based on 310985 revision 310985 as attested by http://tinyurl.com/8njps
34  // see also http://tinyurl.com/c2rp5
35  
36  /**
37   * A JoranConfiguratorBase lays most of the groundwork for concrete
38   * configurators derived from it. Concrete configurators only need to implement
39   * the {@link #addInstanceRules} method.
40   * <p>
41   * A JoranConfiguratorBase instance should not be used more than once to
42   * configure a Context.
43   * 
44   * @author Ceki G&uuml;lc&uuml;
45   */
46  abstract public class JoranConfiguratorBase extends GenericConfigurator {
47    
48  
49    public List getErrorList() {
50      return null;
51    }
52  
53    @Override
54    protected void addInstanceRules(RuleStore rs) {
55     
56      rs.addRule(new Pattern("configuration/property"),
57          new PropertyAction());
58      
59      rs.addRule(new Pattern("configuration/substitutionProperty"),
60          new PropertyAction());
61      
62      // the contextProperty pattern is deprecated. It is undocumented
63      // and will be dropped in future versions of logback
64      rs.addRule(new Pattern("configuration/contextProperty"),
65          new ContextPropertyAction());
66      
67      rs.addRule(new Pattern("configuration/conversionRule"),
68          new ConversionRuleAction());
69  
70      rs.addRule(new Pattern("configuration/statusListener"),
71          new StatusListenerAction());
72  
73      rs.addRule(new Pattern("configuration/appender"), new AppenderAction());
74      rs.addRule(new Pattern("configuration/appender/appender-ref"),
75          new AppenderRefAction());
76      rs.addRule(new Pattern("configuration/newRule"), new NewRuleAction());
77      rs.addRule(new Pattern("*/param"), new ParamAction());
78    }
79  
80    @Override
81    protected void addImplicitRules(Interpreter interpreter) {
82      // The following line adds the capability to parse nested components
83      NestedComplexPropertyIA nestedIA = new NestedComplexPropertyIA();
84      nestedIA.setContext(context);
85      interpreter.addImplicitAction(nestedIA);
86  
87      NestedBasicPropertyIA nestedSimpleIA = new NestedBasicPropertyIA();
88      nestedIA.setContext(context);
89      interpreter.addImplicitAction(nestedSimpleIA);
90    }
91  
92    @Override
93    protected void buildInterpreter() {
94      super.buildInterpreter();
95      Map<String, Object> omap = interpreter.getInterpretationContext().getObjectMap();
96      omap.put(ActionConst.APPENDER_BAG, new HashMap());
97      omap.put(ActionConst.FILTER_CHAIN_BAG, new HashMap());
98    }
99  
100   public InterpretationContext getExecutionContext() {
101     return interpreter.getInterpretationContext();
102   }
103 }