001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.joran.action;
015
016import ch.qos.logback.core.joran.action.PreconditionValidator;
017import org.xml.sax.Attributes;
018
019import ch.qos.logback.classic.Logger;
020import ch.qos.logback.classic.model.RootLoggerModel;
021import ch.qos.logback.core.joran.JoranConstants;
022import ch.qos.logback.core.joran.action.BaseModelAction;
023import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
024import ch.qos.logback.core.model.Model;
025import static ch.qos.logback.core.joran.JoranConstants.NULL;
026import static ch.qos.logback.core.joran.JoranConstants.INHERITED;
027import static ch.qos.logback.core.spi.ErrorCodes.ROOT_LEVEL_CANNOT_BE_SET_TO_NULL;
028
029public class RootLoggerAction extends BaseModelAction {
030
031    Logger root;
032    boolean inError = false;
033
034    @Override
035    protected boolean validPreconditions(SaxEventInterpretationContext interpcont, String name, Attributes attributes) {
036        PreconditionValidator pv;
037        String levelStr = attributes.getValue(JoranConstants.LEVEL_ATTRIBUTE);
038        if(NULL.equalsIgnoreCase(levelStr) || INHERITED.equalsIgnoreCase(levelStr)) {
039            addError(ROOT_LEVEL_CANNOT_BE_SET_TO_NULL);
040            return false;
041        }
042        return true;
043    }
044    @Override
045    protected Model buildCurrentModel(SaxEventInterpretationContext interpretationContext, String name,
046            Attributes attributes) {
047        RootLoggerModel rootLoggerModel = new RootLoggerModel();
048        String levelStr = attributes.getValue(JoranConstants.LEVEL_ATTRIBUTE);
049        rootLoggerModel.setLevel(levelStr);
050
051        return rootLoggerModel;
052    }
053
054}