001/**
002 * Copyright 2010-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.common.util.log4j;
017
018import org.apache.commons.lang3.ObjectUtils;
019import org.kuali.common.util.Assert;
020import org.kuali.common.util.CollectionUtils;
021import org.kuali.common.util.nullify.Nullifier;
022
023/**
024 * @deprecated
025 */
026@Deprecated
027public class Log4JContextNullifier implements Nullifier {
028
029        org.kuali.common.util.log4j.model.Log4JContext context;
030
031        public Log4JContextNullifier() {
032                this(null);
033        }
034
035        public Log4JContextNullifier(org.kuali.common.util.log4j.model.Log4JContext context) {
036                super();
037                this.context = context;
038        }
039
040        @Override
041        public void nullify() {
042
043                Assert.notNull(context);
044
045                nullify(context);
046                nullify(context.getRoot());
047                for (org.kuali.common.util.log4j.model.Logger logger : CollectionUtils.toEmptyList(context.getLoggers())) {
048                        nullify(logger);
049                }
050
051        }
052
053        protected void nullify(org.kuali.common.util.log4j.model.Log4JContext context) {
054                if (ObjectUtils.equals(org.kuali.common.util.log4j.model.Log4JContext.DEFAULT_RESET_VALUE, context.getReset())) {
055                        context.setReset(null);
056                }
057
058                if (ObjectUtils.equals(org.kuali.common.util.log4j.model.Log4JContext.DEFAULT_DEBUG_VALUE, context.getDebug())) {
059                        context.setDebug(null);
060                }
061
062                if (ObjectUtils.equals(org.kuali.common.util.log4j.model.Log4JContext.DEFAULT_THRESHOLD_VALUE, context.getThreshold())) {
063                        context.setThreshold(null);
064                }
065        }
066
067        protected void nullify(org.kuali.common.util.log4j.model.Logger logger) {
068                if (logger == null) {
069                        return;
070                }
071                if (ObjectUtils.equals(org.kuali.common.util.log4j.model.Logger.DEFAULT_ADDITIVITY_VALUE, logger.getAdditivity())) {
072                        logger.setAdditivity(null);
073                }
074                if (logger.getLevel() == null) {
075                        return;
076                }
077                if (ObjectUtils.equals(org.kuali.common.util.log4j.model.Level.DEFAULT_JAVA_CLASS, logger.getLevel().getJavaClass())) {
078                        logger.getLevel().setJavaClass(null);
079                }
080        }
081
082        public org.kuali.common.util.log4j.model.Log4JContext getContext() {
083                return context;
084        }
085
086        public void setContext(org.kuali.common.util.log4j.model.Log4JContext context) {
087                this.context = context;
088        }
089
090}