1 32 33 package com.jeantessier.classreader; 34 35 import java.io.*; 36 import java.util.*; 37 38 import org.apache.log4j.*; 39 40 public class ModifiedOnlyDispatcher implements ClassfileLoaderDispatcher { 41 private ClassfileLoaderDispatcher delegate; 42 43 private Map timestamps = new HashMap(); 44 45 public ModifiedOnlyDispatcher(ClassfileLoaderDispatcher delegate) { 46 this.delegate = delegate; 47 } 48 49 public int dispatch(String filename) { 50 int result = ACTION_IGNORE; 51 52 File file = new File(filename); 53 54 Long timestamp = (Long ) timestamps.get(filename); 55 56 Logger.getLogger(getClass()).debug(filename + " has timestamp " + timestamp); 57 58 if (file.isDirectory()) { 59 Logger.getLogger(getClass()).debug("Delegating ..."); 60 result = delegate.dispatch(filename); 61 } else if (timestamp == null || timestamp.longValue() < file.lastModified()) { 62 timestamp = new Long (file.lastModified()); 63 timestamps.put(filename, timestamp); 64 65 Logger.getLogger(getClass()).debug("Delegating ..."); 66 result = delegate.dispatch(filename); 67 } else { 68 Logger.getLogger(getClass()).debug("Already dispatched \"" + filename + "\": IGNORE"); 69 } 70 71 return result; 72 } 73 } 74 | Popular Tags |