View Javadoc

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