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.implicitAction;
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  
19  public class FruitContextAction extends Action {
20  
21    private boolean inError = false;
22  
23    
24    @Override
25    public void begin(InterpretationContext ec, String name, Attributes attributes)
26        throws ActionException {
27  
28      inError = false;
29      
30      try {
31        ec.pushObject(context);
32      } catch (Exception oops) {
33        inError = true;
34        addError(
35          "Could not push context", oops);
36        throw new ActionException(oops);
37      }
38    }
39  
40    @Override
41    public void end(InterpretationContext ec, String name) throws ActionException {
42      if (inError) {
43        return;
44      }
45  
46      Object o = ec.peekObject();
47  
48      if (o != context) {
49        addWarn(
50          "The object at the of the stack is not the context named ["
51          + context.getName() + "] pushed earlier.");
52      } else {
53        addInfo(
54          "Popping context named [" + context.getName()
55          + "] from the object stack");
56        ec.popObject();
57      }
58    }
59  
60    
61  }