| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.plugin; |
| 18 | |
|
| 19 | |
import java.io.File; |
| 20 | |
import java.net.MalformedURLException; |
| 21 | |
import java.net.URL; |
| 22 | |
import java.util.HashMap; |
| 23 | |
import java.util.Iterator; |
| 24 | |
import java.util.Map; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | 0 | public class ModificationTracker implements Modifiable { |
| 32 | |
|
| 33 | 0 | protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass()); |
| 34 | |
|
| 35 | |
|
| 36 | 0 | private final Map dirTree = new HashMap(); |
| 37 | |
|
| 38 | |
public synchronized void addURL(URL url) { |
| 39 | 0 | addURL(dirTree, url); |
| 40 | 0 | } |
| 41 | |
|
| 42 | |
private void addURL(Map parentMap, URL url) { |
| 43 | 0 | Node node = new Node(url); |
| 44 | 0 | if (!parentMap.keySet().contains(node)) { |
| 45 | 0 | Map subDir = new HashMap(); |
| 46 | 0 | parentMap.put(node, subDir); |
| 47 | 0 | if (node.getFile().isDirectory()) { |
| 48 | 0 | File[] files = node.getFile().listFiles(); |
| 49 | 0 | for (int index = 0; index < files.length; index++) { |
| 50 | |
try { |
| 51 | 0 | addURL(subDir, files[index].toURL()); |
| 52 | 0 | } catch (MalformedURLException e) { |
| 53 | |
|
| 54 | 0 | throw new RuntimeException(e); |
| 55 | 0 | } |
| 56 | |
} |
| 57 | |
} |
| 58 | |
} |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
public boolean isModified() { |
| 62 | 0 | return isModified(dirTree); |
| 63 | |
} |
| 64 | |
|
| 65 | |
private boolean isModified(Map dirTree) { |
| 66 | 0 | for (Iterator iterator = dirTree.keySet().iterator(); iterator.hasNext();) { |
| 67 | 0 | Node node = (Node) iterator.next(); |
| 68 | 0 | if (node.isModified() || isModified((Map)dirTree.get(node))) { |
| 69 | 0 | return true; |
| 70 | |
} |
| 71 | 0 | } |
| 72 | 0 | return false; |
| 73 | |
} |
| 74 | |
|
| 75 | 0 | private class Node implements Modifiable { |
| 76 | |
private URL url; |
| 77 | |
private File file; |
| 78 | |
private long lastModified; |
| 79 | 0 | public Node(URL url) { |
| 80 | 0 | this.url = url; |
| 81 | 0 | this.file = new File(url.getFile()); |
| 82 | 0 | this.lastModified = file.lastModified(); |
| 83 | 0 | } |
| 84 | |
public URL getURL() { |
| 85 | 0 | return url; |
| 86 | |
} |
| 87 | |
public File getFile() { |
| 88 | 0 | return file; |
| 89 | |
} |
| 90 | |
public long getLastModified() { |
| 91 | 0 | return lastModified; |
| 92 | |
} |
| 93 | |
public boolean isModified() { |
| 94 | 0 | return lastModified != file.lastModified(); |
| 95 | |
} |
| 96 | |
public boolean equals(Object object) { |
| 97 | 0 | if (object instanceof Node) { |
| 98 | 0 | return ((Node)object).getURL().equals(getURL()); |
| 99 | |
} |
| 100 | 0 | return false; |
| 101 | |
} |
| 102 | |
public int hashCode() { |
| 103 | 0 | return url.hashCode(); |
| 104 | |
} |
| 105 | |
} |
| 106 | |
|
| 107 | |
} |