diff options
Diffstat (limited to 'nailgun_launcher/CBTUrlClassLoader.java')
-rw-r--r-- | nailgun_launcher/CBTUrlClassLoader.java | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/nailgun_launcher/CBTUrlClassLoader.java b/nailgun_launcher/CBTUrlClassLoader.java index c05391b..b799bc0 100644 --- a/nailgun_launcher/CBTUrlClassLoader.java +++ b/nailgun_launcher/CBTUrlClassLoader.java @@ -3,6 +3,7 @@ import java.io.*; import java.net.*; import java.util.*; import static cbt.Stage0Lib.*; +import java.util.concurrent.ConcurrentHashMap; class CbtURLClassLoader extends java.net.URLClassLoader{ public String toString(){ return ( @@ -10,13 +11,35 @@ class CbtURLClassLoader extends java.net.URLClassLoader{ + "(\n " + Arrays.toString(getURLs()) + ",\n " - + join("\n ",getParent().toString().split("\n")) + + join("\n ",(getParent() == null?"":getParent().toString()).split("\n")) + "\n)" ); } + ClassLoaderCache2<Class> cache = new ClassLoaderCache2<Class>( + new ConcurrentHashMap<String, Object>(), + new ConcurrentHashMap<Object, Class>() + ); public Class loadClass(String name) throws ClassNotFoundException{ + Class _class = super.loadClass(name); + if(_class == null) throw new ClassNotFoundException(name); + else return _class; + } + public Class loadClass(String name, Boolean resolve) throws ClassNotFoundException{ //System.out.println("loadClass("+name+") on \n"+this); - return super.loadClass(name); + if(!cache.contains(name)) + try{ + cache.put(super.loadClass(name, resolve), name); + } catch (ClassNotFoundException e){ + cache.put(Object.class, name); + } + Class _class = cache.get(name); + if(_class == Object.class){ + if( name == "java.lang.Object" ) + return Object.class; + else return null; + } else { + return _class; + } } void assertExist(URL[] urls){ for(URL url: urls){ @@ -30,7 +53,7 @@ class CbtURLClassLoader extends java.net.URLClassLoader{ assertExist(urls); } public CbtURLClassLoader(URL[] urls){ - super(urls); + super(urls, null); assertExist(urls); } }
\ No newline at end of file |