1 22 package org.jboss.mx.loading; 23 24 import java.net.URL ; 25 import java.util.Enumeration ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 43 public class BasicLoaderRepository 44 extends LoaderRepository 45 { 46 47 49 57 public Class loadClass(String className) throws ClassNotFoundException 58 { 59 return loadClassWithout(null, className); 60 } 61 62 71 public Class loadClassWithout(ClassLoader skipLoader, String className) throws ClassNotFoundException 72 { 73 ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader(); 75 if (ctxLoader != skipLoader) 76 { 77 try 78 { 79 return ctxLoader.loadClass(className); 80 } 81 catch (ClassNotFoundException e) 82 { 83 } 85 } 86 87 Iterator it = loaders.iterator(); 88 while (it.hasNext()) 89 { 90 ClassLoader cl = (ClassLoader ) it.next(); 91 if (cl != skipLoader) 92 { 93 try 94 { 95 return cl.loadClass(className); 96 } 97 catch (ClassNotFoundException ignored) 98 { 99 } 101 } 102 } 103 104 Class clazz = getNativeClassForName(className); 106 if (clazz != null) return clazz; 107 108 throw new ClassNotFoundException (className); 109 } 110 111 124 public Class loadClassBefore(ClassLoader stop, String className) throws ClassNotFoundException 125 { 126 Iterator it = loaders.iterator(); 127 while (it.hasNext()) 128 { 129 ClassLoader cl = (ClassLoader ) it.next(); 130 if (cl == stop) 131 break; 132 133 try 134 { 135 return cl.loadClass(className); 136 } 137 catch (ClassNotFoundException ignored) 138 { 139 } 141 } 142 143 Class clazz = getNativeClassForName(className); 145 if (clazz != null) return clazz; 146 147 throw new ClassNotFoundException (className); 148 } 149 150 public void addClassLoader(ClassLoader cl) 151 { 152 loaders.add(cl); 153 } 154 155 public boolean addClassLoaderURL(ClassLoader cl, URL url) 156 { 157 return false; 159 } 160 161 public void removeClassLoader(ClassLoader cl) 162 { 163 loaders.remove(cl); 164 } 165 166 public RepositoryClassLoader newClassLoader(final URL url, boolean addToRepository) 167 throws Exception 168 { 169 UnifiedClassLoader ucl = new UnifiedClassLoader(url); 170 if( addToRepository ) 171 this.addClassLoader(ucl); 172 return ucl; 173 } 174 public RepositoryClassLoader newClassLoader(final URL url, final URL origURL, boolean addToRepository) 175 throws Exception 176 { 177 UnifiedClassLoader ucl = new UnifiedClassLoader(url, origURL); 178 if( addToRepository ) 179 this.addClassLoader(ucl); 180 return ucl; 181 } 182 public Class loadClass(String name, boolean resolve, ClassLoader cl) 183 throws ClassNotFoundException 184 { 185 throw new ClassNotFoundException ("loadClass(String,boolean,ClassLoader) not supported"); 186 } 187 public URL getResource(String name, ClassLoader cl) 188 { 189 URL res = null; 190 if( cl instanceof UnifiedClassLoader ) 191 { 192 UnifiedClassLoader ucl = (UnifiedClassLoader) cl; 193 res = ucl.getResourceLocally(name); 194 } 195 else 196 { 197 res = cl.getResource(name); 198 } 199 return res; 200 } 201 public void getResources(String name, ClassLoader cl, List urls) 202 { 203 Enumeration resURLs = null; 204 try 205 { 206 if( cl instanceof UnifiedClassLoader ) 207 { 208 UnifiedClassLoader ucl = (UnifiedClassLoader) cl; 209 resURLs = ucl.findResourcesLocally(name); 210 } 211 else 212 { 213 resURLs = cl.getResources(name); 214 } 215 while( resURLs.hasMoreElements() ) 216 urls.add(resURLs.nextElement()); 217 } 218 catch(Exception e) 219 { 220 } 221 } 222 } 223 | Popular Tags |