1 19 package org.netbeans.modules.j2ee.websphere6; 20 21 import java.io.*; 22 import java.net.*; 23 import java.util.*; 24 25 import org.netbeans.modules.j2ee.websphere6.util.WSDebug; 26 27 34 public class WSClassLoader extends URLClassLoader { 35 36 40 private static Map instances = new HashMap(); 41 42 50 public static WSClassLoader getInstance(String serverRoot, 51 String domainRoot) { 52 if (WSDebug.isEnabled()) WSDebug.notify(WSClassLoader.class, "getInstance(" + serverRoot + ", " + domainRoot + ")"); 56 WSClassLoader instance = (WSClassLoader) instances.get(domainRoot); 58 59 if (instance == null) { 61 instance = new WSClassLoader(serverRoot, domainRoot); 62 instances.put(domainRoot, instance); 63 } 64 65 return instance; 67 } 68 69 72 private String serverRoot; 73 74 77 private String domainRoot; 78 79 86 private WSClassLoader(String serverRoot, String domainRoot) { 87 super(new URL[0], Thread.currentThread().getContextClassLoader()); 90 91 this.serverRoot = serverRoot; 93 this.domainRoot = domainRoot; 94 95 File[] directories = new File[] { 97 new File(serverRoot + "/lib/"), new File(serverRoot + "/java/jre/lib/"), new File(serverRoot + "/java/jre/lib/ext/"), new File(serverRoot + "/lib/WMQ/java/lib/"), 101 new File(serverRoot + "/cloudscape/lib/"), 102 new File(serverRoot + "/cloudscape/lib/locales/"), 103 new File(serverRoot + "/cloudscape/lib/otherjars/"), 104 new File(serverRoot + "/deploytool/itp/"), 105 new File(serverRoot + "/deploytool/itp/plugins/"), 106 new File(serverRoot + "/installedChannels/"), 107 new File(serverRoot + "/etc/"), 108 new File(serverRoot + "/optionalLibraries/Apache/Struts/1.1/") 109 }; 110 111 for (int i = 0; i < directories.length; i++) { 114 File directory = directories[i]; 115 if (directory.exists() && directory.isDirectory()) { 116 File[] children = directory.listFiles(new JarFileFilter()); 117 for (int j = 0; j < children.length; j++) { 118 try { 119 addURL(children[j].toURL()); 120 } catch (MalformedURLException e) { 121 } 123 } 124 } 125 try { 126 addURL(directory.toURL()); 127 } catch (MalformedURLException e) { 128 } 130 } 131 } 132 133 137 private ClassLoader oldLoader; 138 139 143 public void updateLoader() { 144 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "updateLoader()"); 147 System.setProperty("websphere.home", serverRoot); System.setProperty("was.install.root", serverRoot); System.setProperty("was.repository.root", domainRoot + File.separator + "config"); 154 if (WSDebug.isEnabled()) 157 System.setProperty("traceSettingsFile", "TraceSettings.properties"); 160 if (!Thread.currentThread().getContextClassLoader().equals(this)) { 163 oldLoader = Thread.currentThread().getContextClassLoader(); 164 Thread.currentThread().setContextClassLoader(this); 165 } 166 } 167 168 173 public void restoreLoader() { 174 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "restoreLoader()"); 177 if (oldLoader != null) { 179 Thread.currentThread().setContextClassLoader(oldLoader); 180 oldLoader = null; 181 } 182 } 183 184 189 private static class JarFileFilter implements FileFilter { 190 196 public boolean accept(File file) { 197 if (file.getName().endsWith(".jar")) { return true; 200 } else { 201 return false; 202 } 203 } 204 } 205 } 206 | Popular Tags |