View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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 chapters.onJoran.calculator;
15  
16  import java.util.HashMap;
17  import java.util.Map;
18  
19  import ch.qos.logback.core.Context;
20  import ch.qos.logback.core.ContextBase;
21  import ch.qos.logback.core.joran.action.Action;
22  import ch.qos.logback.core.joran.spi.ElementSelector;
23  import ch.qos.logback.core.util.StatusPrinter;
24  import chapters.onJoran.SimpleConfigurator;
25  
26  /**
27   * This examples illustrates collaboration between multiple actions through the
28   * common execution context stack.
29   * 
30   * @author Ceki Gülcü
31   */
32  public class Calculator1 {
33  
34      public static void main(String[] args) throws Exception {
35          Context context = new ContextBase();
36  
37          Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>();
38  
39          // Associate "/computation" pattern with ComputationAction1
40          ruleMap.put(new ElementSelector("/computation"), new ComputationAction1());
41  
42          // Other associations
43          ruleMap.put(new ElementSelector("/computation/literal"), new LiteralAction());
44          ruleMap.put(new ElementSelector("/computation/add"), new AddAction());
45          ruleMap.put(new ElementSelector("/computation/multiply"), new MultiplyAction());
46  
47          SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
48          // link the configurator with its context
49          simpleConfigurator.setContext(context);
50  
51          simpleConfigurator.doConfigure(args[0]);
52          // Print any errors that might have occured.
53          StatusPrinter.print(context);
54      }
55  }