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.action;
15  
16  import org.xml.sax.Attributes;
17  
18  import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
19  import ch.qos.logback.core.model.Model;
20  import ch.qos.logback.core.model.StatusListenerModel;
21  import ch.qos.logback.core.status.StatusListener;
22  import ch.qos.logback.core.util.OptionHelper;
23  
24  public class StatusListenerAction extends BaseModelAction {
25  
26      boolean inError = false;
27      Boolean effectivelyAdded = null;
28      StatusListener statusListener = null;
29  
30      @Override
31      protected boolean validPreconditions(SaxEventInterpretationContext interpretationContext, String name,
32              Attributes attributes) {
33          String className = attributes.getValue(CLASS_ATTRIBUTE);
34          if (OptionHelper.isNullOrEmpty(className)) {
35              addError("Missing class name for statusListener. Near [" + name + "] line "
36                      + getLineNumber(interpretationContext));
37              return false;
38          }
39          return true;
40      }
41  
42      @Override
43      protected Model buildCurrentModel(SaxEventInterpretationContext interpretationContext, String name,
44              Attributes attributes) {
45          StatusListenerModel statusListenerModel = new StatusListenerModel();
46          statusListenerModel.setClassName(attributes.getValue(CLASS_ATTRIBUTE));
47          return statusListenerModel;
48      }
49  
50  }