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 ch.qos.logback.core.joran.replay;
15  
16  import org.xml.sax.Attributes;
17  
18  import ch.qos.logback.core.joran.action.Action;
19  import ch.qos.logback.core.joran.spi.ActionException;
20  import ch.qos.logback.core.joran.spi.InterpretationContext;
21  import ch.qos.logback.core.util.OptionHelper;
22  
23  /** 
24   * The Fruit* code is intended to test Joran's replay capability
25   * */
26  public class FruitShellAction extends Action {
27  
28      FruitShell fruitShell;
29      private boolean inError = false;
30  
31      @Override
32      public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException {
33  
34          // We are just beginning, reset variables
35          fruitShell = new FruitShell();
36          inError = false;
37  
38          try {
39  
40              fruitShell.setContext(context);
41  
42              String shellName = attributes.getValue(NAME_ATTRIBUTE);
43  
44              if (OptionHelper.isEmpty(shellName)) {
45                  addWarn("No appender name given for fruitShell].");
46              } else {
47                  fruitShell.setName(shellName);
48                  addInfo("FruitShell named as [" + shellName + "]");
49              }
50  
51              ec.pushObject(fruitShell);
52          } catch (Exception oops) {
53              inError = true;
54              addError("Could not create an FruitShell", oops);
55              throw new ActionException(oops);
56          }
57      }
58  
59      @Override
60      public void end(InterpretationContext ec, String name) throws ActionException {
61          if (inError) {
62              return;
63          }
64  
65          Object o = ec.peekObject();
66  
67          if (o != fruitShell) {
68              addWarn("The object at the of the stack is not the fruitShell named [" + fruitShell.getName() + "] pushed earlier.");
69          } else {
70              addInfo("Popping fruitSHell named [" + fruitShell.getName() + "] from the object stack");
71              ec.popObject();
72              FruitContext fruitContext = (FruitContext) ec.getContext();
73              fruitContext.addFruitShell(fruitShell);
74          }
75      }
76  
77  }