Package ch.qos.logback.core.joran.util

Source Code of ch.qos.logback.core.joran.util.ConfigurationWatchListUtil

/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2011, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
*   or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.core.joran.util;

import ch.qos.logback.core.Context;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.joran.spi.ConfigurationWatchList;
import ch.qos.logback.core.status.InfoStatus;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusManager;
import ch.qos.logback.core.status.WarnStatus;

import javax.security.auth.login.Configuration;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

/**
* @author Ceki Gücü
*/
public class ConfigurationWatchListUtil {

  final static ConfigurationWatchListUtil origin = new ConfigurationWatchListUtil();

  private ConfigurationWatchListUtil() {
  }

  public static void setMainWatchURL(Context context, URL url) {
    ConfigurationWatchList cwl = getConfigurationWatchList(context);
    if (cwl == null) {
      cwl = new ConfigurationWatchList();
      cwl.setContext(context);
      context.putObject(CoreConstants.CONFIGURATION_WATCH_LIST, cwl);
    } else {
      cwl.clear();
    }
    setConfigurationWatchListResetFlag(context, true);
    cwl.setMainURL(url);
  }

  public static void addToWatchList(Context context, URL url) {
    ConfigurationWatchList cwl = getConfigurationWatchList(context);
    if (cwl == null) {
      addWarn(context, "Null ConfigurationWatchList. Cannot add " + url);
    } else {
      addInfo(context, "Adding [" + url + "] to configuration watch list.");
      cwl.addToWatchList(url);
    }
  }

  public static boolean wasConfigurationWatchListReset(Context context) {
    Object o = context.getObject(CoreConstants.CONFIGURATION_WATCH_LIST_RESET);
    if(o == null)
      return false;
    else {
      return ((Boolean) o).booleanValue();
    }
  }
  public static void setConfigurationWatchListResetFlag(Context context, boolean val) {
    context.putObject(CoreConstants.CONFIGURATION_WATCH_LIST_RESET, new Boolean(val));
  }

  public static ConfigurationWatchList getConfigurationWatchList(Context context) {
    return (ConfigurationWatchList) context.getObject(CoreConstants.CONFIGURATION_WATCH_LIST);
  }

  static void addStatus(Context context, Status s) {
    if (context == null) {
      System.out.println("Null context in " + ConfigurationWatchList.class.getName());
      return;
    }
    StatusManager sm = context.getStatusManager();
    if (sm == null) return;
    sm.add(s);
  }

  static void addInfo(Context context, String msg) {
    addStatus(context, new InfoStatus(msg, origin));
  }

  static void addWarn(Context context, String msg) {
    addStatus(context, new WarnStatus(msg, origin));
  }
}
TOP

Related Classes of ch.qos.logback.core.joran.util.ConfigurationWatchListUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.