1 26 27 package org.objectweb.jonas_lib.loader; 28 29 import java.io.File ; 30 import java.io.IOException ; 31 import java.net.URL ; 32 import java.net.URLClassLoader ; 33 import java.util.List ; 34 import java.util.Iterator ; 35 36 import org.objectweb.jonas_lib.loader.factory.URLFactory; 37 import org.objectweb.jonas_lib.loader.locator.Locator; 38 39 45 public abstract class AbsModuleClassLoader extends URLClassLoader { 46 47 48 private URLFactory[] factories; 49 50 51 private Locator[] locators; 52 53 54 private URL [] bases; 55 56 63 public AbsModuleClassLoader(URL [] modules) throws IOException { 64 super(new URL [0]); 65 bases = modules; 66 init(); 67 } 68 69 77 public AbsModuleClassLoader(URL [] modules, ClassLoader parent) throws IOException { 78 super(new URL [0], parent); 79 bases = modules; 80 init(); 81 } 82 83 88 protected void init() throws IOException { 89 factories = new URLFactory[bases.length]; 90 locators = new Locator[bases.length]; 91 92 for (int i = 0; i < bases.length; i++) { 94 95 factories[i] = URLFactory.getFactory(bases[i]); 96 locators[i] = Locator.getLocator(bases[i]); 97 } 98 } 99 100 109 protected void addInRepository(String location) throws IOException { 110 for (int i = 0; i < bases.length; i++) { 112 if (locators[i].hasDirectory(location) 113 || locators[i].hasFile(location)) { 114 addURL(factories[i].getURL(location)); 115 } 116 } 117 } 118 119 129 protected void addContentInRepository(String location) throws IOException { 130 for (int i = 0; i < bases.length; i++) { 132 List list = locators[i].listContent(location); 133 for (Iterator l = list.iterator(); l.hasNext();) { 134 addURL(factories[i].getURL((String ) l.next())); 135 } 136 } 137 } 138 139 142 public String toString() { 143 StringBuffer sb = new StringBuffer (); 144 145 sb.append("classloader : " + getClass().getName() + "\n"); 146 sb.append("\tmodules bases (not in loader!) : \n"); 147 for (int i = 0; i < bases.length; i++) { 148 sb.append("\t\t -" + bases[i] + "\n"); 149 } 150 sb.append("\trepositories :\n"); 151 URL [] rep = getURLs(); 152 for (int i = 0; i < rep.length; i++) { 153 sb.append("\t\t -" + rep[i] + "\n"); 154 } 155 sb.append("\tparent : " + getParent() + "\n"); 156 157 return sb.toString(); 158 } 159 160 163 public URL [] getBases() { 164 return bases; 165 } 166 167 170 public String getClasspath() { 171 URL [] urls = getURLs(); 172 StringBuffer cp = new StringBuffer (); 173 for (int i = 0; i < urls.length; i++) { 174 String url = urls[i].getFile(); 175 if (url.indexOf("!/") == -1) { 177 cp.append(File.pathSeparator + url); 178 } 179 } 180 return cp.toString(); 181 } 182 } 183 | Popular Tags |