1 19 20 package org.lucane.common; 21 22 import java.net.*; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 26 29 public class LucaneClassLoader extends URLClassLoader 30 { 31 private static LucaneClassLoader instance = null; 33 34 39 public static LucaneClassLoader getInstance() 40 { 41 if(instance == null) 42 instance = new LucaneClassLoader(); 43 44 return instance; 45 } 46 47 private ArrayList urls; 48 49 52 private LucaneClassLoader() 53 { 54 super(new URL[0], LucaneClassLoader.class.getClassLoader()); 55 this.urls = new ArrayList (); 56 } 57 58 63 public void addUrl(URL url) 64 { 65 this.urls.add(url); 66 this.addURL(url); 67 } 68 69 74 public void addUrl(String url) 75 throws MalformedURLException 76 { 77 this.addUrl(new URL(url)); 78 } 79 80 86 public String getClassPath() 87 { 88 String sep = System.getProperty("path.separator"); 89 StringBuffer cp = new StringBuffer (); 90 URL[] urls = ((URLClassLoader)this.getParent()).getURLs(); 91 for(int i=0;i<urls.length;i++) 92 { 93 cp.append(urlToFile(urls[i])); 94 cp.append(sep); 95 } 96 97 Iterator i = this.urls.iterator(); 98 while(i.hasNext()) 99 { 100 URL url = (URL)i.next(); 101 cp.append(urlToFile(url)); 102 cp.append(sep); 103 } 104 105 return cp.toString(); 106 } 107 108 114 private String urlToFile(URL url) 115 { 116 String file = url.toString(); 117 file = file.substring("jar:file:///".length()); 118 file = file.substring(0, file.length()-2); 119 return file; 120 } 121 } 122 | Popular Tags |