1 28 29 package org.objectweb.util.launcher; 30 31 32 import java.net.MalformedURLException ; 33 import java.net.URLClassLoader ; 34 import java.net.URL ; 35 36 import org.objectweb.util.trace.TraceSystem; 37 38 39 51 public class XBootClassLoader 52 extends URLClassLoader 53 { 54 60 63 public XBootClassLoader() { 64 super(new URL [0]); 65 } 66 67 72 public XBootClassLoader(ClassLoader parent) { 73 super(new URL [0], parent); 74 } 75 76 82 94 protected Class loadClass(String name, boolean resolve) 95 throws ClassNotFoundException 96 { Class c = findLoadedClass(name); 98 if (c == null) 99 try { c = findClass(name); 101 } catch (ClassNotFoundException e) { 102 return super.loadClass(name, resolve); 103 } 104 if (resolve) 105 resolveClass(c); 106 return c; 107 } 108 109 115 123 public Class findClass(String name) 124 throws ClassNotFoundException 125 { 126 return super.findClass(name); 127 } 128 129 137 public Class loadClass(String name) 138 throws ClassNotFoundException 139 { 140 TraceSystem.get("classloader").debug("Loading class "+name); 141 return loadClass(name, false); 142 } 143 144 148 public void addURL(URL url) 149 { TraceSystem.get("classloader").info("Registering URL "+url); 151 try { 153 url.openConnection().connect(); 154 } catch (Exception ex) { 155 throw new LauncherException(ex); 156 } 157 if (!java.util.Arrays.asList(getURLs()).contains(url)) 158 super.addURL(url); 159 } 160 161 162 167 public void addURL(String url) 168 throws MalformedURLException 169 { 170 this.addURL(new URL (url)); 171 } 172 173 174 179 public void addURL(String [] urls) 180 throws MalformedURLException 181 { 182 for (int i=0 ; i < urls.length ; i++) 183 this.addURL(urls[i]); 184 } 185 186 187 193 public boolean equals(Object obj) 194 { 195 if (obj instanceof XBootClassLoader) { 196 XBootClassLoader loader = (XBootClassLoader) obj; 197 return java.util.Arrays.equals(getURLs(), loader.getURLs()); 198 } 199 return false ; 200 } 201 } 202 | Popular Tags |