package uk.ac.vamsas.client.simpleclient; /** * Element of the VamsasFileWatcherThread event generator chain. * Keep a reference to this element before adding it to the chain * in order to control the generation of events with halt and enable. * * doWatch will do nothing if the element is not enabled. * */ public class VamsasFileWatcherElement extends WatcherElement { VamsasFile watched=null; /** * create a new, enabled watch element * @param watcher file being watched * @param handler handler to call on state change */ public VamsasFileWatcherElement(VamsasFile watcher, WatcherCallBack handler) { this(watcher, handler, true); } protected void initWatch() { if (watched==null) return; watched.unLock(); // very very essential! watcher = new FileWatcher(watched.getVamsasFile()); } protected void endWatch() { // leaves watcher in state its in. } /** * new watcher with flag to initially skip watching this sessionfile * @param watcher * @param handler * @param enableWatching */ public VamsasFileWatcherElement(VamsasFile watcher, WatcherCallBack handler, boolean enableWatching) { super(handler); this.watched = watcher; if (enableWatching) enableWatch(); else haltWatch(); } /** * @return the watched */ public VamsasFile getWatched() { return watched; } protected String getSubject() { return watched.getVamsasFile().toString(); } }