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