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.implicitAction;
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  
22  public class FruitContextAction extends Action {
23  
24      private boolean inError = false;
25  
26      @Override
27      public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException {
28  
29          inError = false;
30  
31          try {
32              ec.pushObject(context);
33          } catch (Exception oops) {
34              inError = true;
35              addError("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("The object at the of the stack is not the context named [" + context.getName() + "] pushed earlier.");
50          } else {
51              addInfo("Popping context named [" + context.getName() + "] from the object stack");
52              ec.popObject();
53          }
54      }
55  
56  }