1 25 26 package org.objectweb.jonas.server; 27 28 import java.io.File ; 29 import java.net.URL ; 30 import java.net.URLClassLoader ; 31 32 37 public class JClassLoader extends URLClassLoader { 38 39 42 private String name = null; 43 44 49 private boolean recomputeToString = true; 50 51 56 private boolean recomputeClassPath = true; 57 58 61 private String toStringValue = null; 62 63 66 private String classpath = null; 67 68 74 public JClassLoader(String name, URL [] urls, ClassLoader parent) { 75 super(urls, parent); 76 this.name = name; 77 this.recomputeToString = true; 78 this.recomputeClassPath = true; 79 } 80 81 87 public JClassLoader(String name, URL [] urls) { 88 super(urls); 89 this.name = name; 90 this.recomputeToString = true; 91 this.recomputeClassPath = true; 92 } 93 94 98 public void addURL(URL url) { 99 if (url != null) { 100 super.addURL(url); 101 } 102 this.recomputeToString = true; 103 this.recomputeClassPath = true; 104 } 105 106 110 public void addURLs(URL [] urls) { 111 if (urls != null) { 112 for (int i = 0; i < urls.length; i++) { 113 if (urls[i] != null) { 114 super.addURL(urls[i]); 115 } 116 } 117 } 118 this.recomputeToString = true; 119 this.recomputeClassPath = true; 120 } 121 122 125 public void printURLs() { 126 System.out.println(name + " ClassLoader :"); 127 URL [] urls = super.getURLs(); 128 for (int i = 0; i < urls.length; i++) { 129 System.out.println("url=" + (new File (urls[i].getFile())).getAbsolutePath()); 130 } 131 if (getParent() != null && getParent() instanceof JClassLoader) { 133 System.out.println("parent :"); 134 ((JClassLoader) getParent()).printURLs(); 135 } 136 } 137 138 142 public String getClassPath() { 143 if (recomputeClassPath) { 145 computeClassPath(); 146 } 147 return classpath; 148 } 149 150 154 public String toString() { 155 if (recomputeToString) { 157 computeToString(); 158 } 159 return toStringValue; 160 } 161 162 165 private void computeToString() { 166 StringBuffer sb = new StringBuffer (); 167 sb.append(this.getClass().getName()); 168 sb.append("["); 169 sb.append(name); 170 sb.append(", urls="); 171 URL [] urls = getURLs(); 172 for (int u = 0; u < urls.length; u++) { 173 sb.append(urls[u]); 174 if (u != urls.length - 1) { 175 sb.append(";"); 176 } 177 } 178 sb.append("]"); 179 toStringValue = sb.toString(); 180 181 recomputeToString = false; 183 } 184 185 188 private void computeClassPath() { 189 String cp = ""; 190 if (getParent() != null && getParent() instanceof JClassLoader) { 192 cp += ((JClassLoader) getParent()).getClassPath(); 193 } 194 URL [] urls = super.getURLs(); 195 for (int i = 0; i < urls.length; i++) { 196 cp = cp + File.pathSeparator + (new File (urls[i].getFile())).getAbsolutePath(); 197 } 198 classpath = cp; 199 recomputeClassPath = false; 201 } 202 203 204 } 205 | Popular Tags |