1 16 package org.apache.cocoon.components.classloader; 17 18 import org.apache.avalon.framework.activity.Disposable; 19 import org.apache.avalon.framework.thread.ThreadSafe; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.util.Collections ; 24 import java.util.HashSet ; 25 import java.util.Set ; 26 27 33 public class ClassLoaderManagerImpl implements ClassLoaderManager, ThreadSafe, Disposable { 34 35 38 protected final Set fileSet = Collections.synchronizedSet(new HashSet ()); 39 40 43 private RepositoryClassLoader instance; 44 45 48 public ClassLoaderManagerImpl() { 49 reinstantiate(); 50 } 51 52 public void dispose() { 53 this.fileSet.clear(); 54 reinstantiate(); 55 } 56 57 63 public void addDirectory(File directoryName) throws IOException { 64 if (this.fileSet.add(directoryName)) { 65 this.instance.addDirectory(directoryName); 66 } 67 } 68 69 76 public Class loadClass(String className) throws ClassNotFoundException { 77 return this.instance.loadClass(className); 78 } 79 80 83 public void reinstantiate() { 84 if (this.fileSet.isEmpty()) { 85 this.instance = new RepositoryClassLoader(); 86 } else { 87 this.instance = new RepositoryClassLoader(this.fileSet); 88 } 89 } 90 } 91 | Popular Tags |