1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.joran.spi;
15
16
17 import ch.qos.logback.core.spi.ContextAwareBase;
18
19 import java.io.File;
20 import java.net.URL;
21 import java.net.URLDecoder;
22 import java.util.ArrayList;
23 import java.util.List;
24
25
26
27
28 public class ConfigurationWatchList extends ContextAwareBase {
29
30 URL mainURL;
31 List<File> fileWatchList = new ArrayList<File>();
32 List<Long> lastModifiedList = new ArrayList<Long>();
33
34 public void clear() {
35 this.mainURL = null;
36 lastModifiedList.clear();
37 fileWatchList.clear();
38 }
39
40
41
42
43
44 public void setMainURL(URL mainURL) {
45
46 this.mainURL = mainURL;
47 if (mainURL != null)
48 addAsFileToWatch(mainURL);
49 }
50
51 private void addAsFileToWatch(URL url) {
52 File file = convertToFile(url);
53 if (file != null) {
54 fileWatchList.add(file);
55 lastModifiedList.add(file.lastModified());
56 }
57 }
58
59 public void addToWatchList(URL url) {
60 addAsFileToWatch(url);
61 }
62
63 public URL getMainURL() {
64 return mainURL;
65 }
66
67 public List<File> getCopyOfFileWatchList() {
68 return new ArrayList<File>(fileWatchList);
69 }
70
71 public boolean changeDetected() {
72 int len = fileWatchList.size();
73 for (int i = 0; i < len; i++) {
74 long lastModified = lastModifiedList.get(i);
75 File file = fileWatchList.get(i);
76 if (lastModified != file.lastModified()) {
77 return true;
78 }
79 }
80 return false;
81
82 }
83
84 @SuppressWarnings("deprecation")
85 File convertToFile(URL url) {
86 String protocol = url.getProtocol();
87 if ("file".equals(protocol)) {
88 return new File(URLDecoder.decode(url.getFile()));
89 } else {
90 addInfo("URL [" + url + "] is not of type file");
91 return null;
92 }
93 }
94
95 }