1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.joran.util;
15
16 import ch.qos.logback.core.Context;
17 import ch.qos.logback.core.CoreConstants;
18 import ch.qos.logback.core.joran.spi.ConfigurationWatchList;
19 import ch.qos.logback.core.status.InfoStatus;
20 import ch.qos.logback.core.status.Status;
21 import ch.qos.logback.core.status.StatusManager;
22 import ch.qos.logback.core.status.WarnStatus;
23
24 import java.net.URL;
25
26
27
28
29 public class ConfigurationWatchListUtil {
30
31 final static ConfigurationWatchListUtil origin = new ConfigurationWatchListUtil();
32
33 private ConfigurationWatchListUtil() {
34 }
35
36 public static void registerConfigurationWatchList(Context context, ConfigurationWatchList cwl) {
37 context.putObject(CoreConstants.CONFIGURATION_WATCH_LIST, cwl);
38 }
39
40 public static void setMainWatchURL(Context context, URL url) {
41 ConfigurationWatchList cwl = getConfigurationWatchList(context);
42 if (cwl == null) {
43 cwl = new ConfigurationWatchList();
44 cwl.setContext(context);
45 context.putObject(CoreConstants.CONFIGURATION_WATCH_LIST, cwl);
46 } else {
47 cwl.clear();
48 }
49
50 cwl.setMainURL(url);
51 }
52
53 public static URL getMainWatchURL(Context context) {
54 ConfigurationWatchList cwl = getConfigurationWatchList(context);
55 if (cwl == null) {
56 return null;
57 } else {
58 return cwl.getMainURL();
59 }
60 }
61
62 public static void addToWatchList(Context context, URL url) {
63 ConfigurationWatchList cwl = getConfigurationWatchList(context);
64 if (cwl == null) {
65 addWarn(context, "Null ConfigurationWatchList. Cannot add " + url);
66 } else {
67 addInfo(context, "Adding [" + url + "] to configuration watch list.");
68 cwl.addToWatchList(url);
69 }
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 public static ConfigurationWatchList getConfigurationWatchList(Context context) {
86 return (ConfigurationWatchList) context.getObject(CoreConstants.CONFIGURATION_WATCH_LIST);
87 }
88
89 static void addStatus(Context context, Status s) {
90 if (context == null) {
91 System.out.println("Null context in " + ConfigurationWatchList.class.getName());
92 return;
93 }
94 StatusManager sm = context.getStatusManager();
95 if (sm == null)
96 return;
97 sm.add(s);
98 }
99
100 static void addInfo(Context context, String msg) {
101 addStatus(context, new InfoStatus(msg, origin));
102 }
103
104 static void addWarn(Context context, String msg) {
105 addStatus(context, new WarnStatus(msg, origin));
106 }
107 }