1 24 25 26 package com.rift.coad; 28 29 import java.net.URLClassLoader ; 31 import java.net.URL ; 32 import java.io.File ; 33 import java.util.Vector ; 34 35 41 public class BaseClassLoader extends URLClassLoader { 42 43 private Vector urls = new Vector (); 45 46 47 50 public BaseClassLoader(URL [] urls,ClassLoader parent) { 51 super(urls,parent); 52 for (int index = 0; index < urls.length; index++) { 53 this.urls.add(urls[index]); 54 } 55 } 56 57 58 64 public void addLib(String path) throws CoadException { 65 try { 66 File file = new File (path); 67 if (file.isFile() == false) { 68 throw new CoadException("The path [" + path 69 + "] does not point to a valid file."); 70 } 71 URL url = file.toURL(); 72 73 synchronized (urls) { 75 for (int index = 0; index < urls.size(); index++) { 76 URL loadedURL = (URL )urls.get(index); 77 if (loadedURL.equals(url)) { 78 return; 80 } 81 } 82 urls.add(url); 83 } 84 85 addURL(url); 87 } catch (CoadException ex) { 88 throw ex; 89 } catch (Exception ex) { 90 throw new CoadException("Failed to load file [" + path 91 + "] because : " + ex.getMessage(),ex); 92 } 93 } 94 95 } 96 | Popular Tags |