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