Changeset 3760
- Timestamp:
- Sep 20, 2007, 1:35:57 PM (16 years ago)
- Location:
- trunk/src/core/net/sf/basedb/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/util/JarClassLoader.java
r3679 r3760 121 121 } 122 122 return cl; 123 } 124 125 126 /** 127 Get a new class loader for the specified jar file. 128 @param jarPath The path to the jar file 129 @return A class loader object 130 @throws IOException If the jar file can't be loaded 131 */ 132 public static final ClassLoader newInstance(String jarPath) 133 throws IOException 134 { 135 return new JarClassLoader(jarPath); 123 136 } 124 137 -
trunk/src/core/net/sf/basedb/util/PluginInfo.java
r3733 r3760 139 139 Element rootElement = XMLUtil.getValidatedXML(is , installDtdURL, null).getRootElement(); 140 140 String jarname = rootElement.getAttributeValue("jarname"); 141 JarReader jarReader = JarReader.getNewInstance(jar);141 ClassLoader jarLoader = JarClassLoader.newInstance(jarFile.getPath()); 142 142 if (!jarname.equalsIgnoreCase(jarFile.getName())) 143 143 { … … 156 156 boolean hasConfigs = (configElement != null) && configElement.equals(hasConfigsValue); 157 157 158 Class c = jar Reader.loadClass(classname);158 Class c = jarLoader.loadClass(classname); 159 159 if (versionCompatible(baseVersion) && Plugin.class.isAssignableFrom(c)) 160 160 { … … 272 272 return majorCompatible && minorCompatible; 273 273 } 274 275 /**276 A private class to get information about plugin classes277 inside a jar file.278 @author Martin279 @version 2.5280 */281 private static class JarReader282 extends ClassLoader283 {284 /**285 The jar file for this reader.286 */287 private JarFile jar;288 289 /**290 @param jar The jar file that should be read291 */292 private JarReader(JarFile jar)293 {294 super(Thread.currentThread().getContextClassLoader());295 this.jar = jar;296 }297 298 private static JarReader getNewInstance (JarFile jarFile)299 {300 return new JarReader(jarFile);301 }302 303 /*304 (non-Javadoc)305 @see java.lang.ClassLoader#findClass(java.lang.String)306 */307 protected Class<?> findClass(String name)308 throws ClassNotFoundException309 {310 byte[] b;311 try312 {313 InputStream in = null;314 JarEntry jarEntry = jar.getJarEntry(classNameToPath(name));315 if (jarEntry == null)316 {317 throw new ClassNotFoundException(name+" in file "+jar.getName());318 }319 in = jar.getInputStream(jarEntry);320 b = new byte[(int)jarEntry.getSize()];321 in.read(b, 0, b.length);322 }323 catch(IOException ex)324 {325 throw new ClassNotFoundException(name, ex);326 }327 return defineClass(name, b, 0, b.length);328 }329 330 /**331 Convert a class name to a file path. Ie. replace dots with slahses and add .class332 to the end: net.sf.basedb.util.JarClassLoader -> net/sf/basedb/util/JarClassLoader.class333 */334 private String classNameToPath(String className)335 {336 return className.replaceAll("\\.", "/")+".class";337 }338 }339 274 }
Note: See TracChangeset
for help on using the changeset viewer.