1010import java .util .Map ;
1111import java .util .Map .Entry ;
1212
13- public class DynamicClassLoader extends ClassLoader {
13+ public abstract class DynamicClassLoader extends ClassLoader {
1414
1515 private static Map <URL , Class <?>> classesByLocation = new HashMap <URL , Class <?>>();
1616 private static Map <Class <?>, URL > locationByClass = new HashMap <Class <?>, URL >();
1717
1818 private final long timeout ;
19- private final FileMonitor fileMonitor ;
2019 private final String binDir , sourceDir ;
2120 private final String [] classPath ;
2221
23- public DynamicClassLoader (String binDir , String sourceDir , String [] classPath , FileMonitor fileMonitor ){
24- this (binDir , sourceDir , classPath , fileMonitor , ClassLoader .getSystemClassLoader ());
22+ public DynamicClassLoader (String binDir , String sourceDir , String [] classPath ){
23+ this (binDir , sourceDir , classPath , ClassLoader .getSystemClassLoader ());
2524 }
2625
27- public DynamicClassLoader (String binDir , String sourceDir , String [] classPath ,
28- FileMonitor fileMonitor , ClassLoader parent ) {
29- this (binDir , sourceDir , classPath , fileMonitor , parent , 5000l );
26+ public DynamicClassLoader (String binDir , String sourceDir , String [] classPath , ClassLoader parent ) {
27+ this (binDir , sourceDir , classPath , parent , 5000l );
3028 }
3129
3230 public DynamicClassLoader (String binDir , String sourceDir ,
33- String [] classPath , FileMonitor fileMonitor , ClassLoader parent ,
31+ String [] classPath , ClassLoader parent ,
3432 long timeout ) {
3533 super (parent );
36- this .fileMonitor = fileMonitor ;
3734 this .binDir = binDir ;
3835 this .sourceDir = sourceDir ;
3936 this .classPath = classPath ;
4037 this .timeout = timeout ;
4138 }
4239
40+ public abstract boolean isFileModifiedSinceLastPoll (String sourcePath , long lastModified );
41+
42+ public abstract void updateFileSavedTime (File sourceFile );
43+
4344 public static void remove (URL url ){
4445 String urlToString = url .toString ().replace (FileCompiler .CLASS_SUFFIX , "" ).replace (FileCompiler .JAVA_SUFFIX , "" );
4546 for (Entry <URL , Class <?>> entry : classesByLocation .entrySet ()){
@@ -75,7 +76,7 @@ public Class<?> loadClass(String className, CompilationListener listener){
7576 if (classFile .exists ()){
7677 String absolutePath = classFile .getAbsolutePath ();
7778 boolean isAnonymous = absolutePath .contains ("$" );
78- if (fileMonitor . isFileModifiedSinceLastPoll (sourceFile .getAbsolutePath (), sourceFile .lastModified ())){
79+ if (isFileModifiedSinceLastPoll (sourceFile .getAbsolutePath (), sourceFile .lastModified ())){
7980 if (!isAnonymous ){
8081 compile (className , fileName , sourceFile , timeout , listener );
8182 }
@@ -97,7 +98,7 @@ public Class<?> loadClass(String className, CompilationListener listener){
9798 private void compile (String className , String fileName , File sourceFile , long timeout , CompilationListener listener )
9899 throws IOException {
99100 FileCompiler .compile (sourceFile , new File (binDir ), listener , timeout , classPath );
100- fileMonitor . updateFileSaveTime (sourceFile );
101+ updateFileSavedTime (sourceFile );
101102 }
102103
103104 public Class <?> loadClass (URL url , String className ){
@@ -126,9 +127,4 @@ public Class<?> loadClass(URL url, String className){
126127 return clazz ;
127128 }
128129
129- @ Override
130- public DynamicClassLoader clone (){
131- return new DynamicClassLoader (binDir , sourceDir , classPath , fileMonitor ,
132- getClass ().getClassLoader (), timeout );
133- }
134130}
0 commit comments