1 19 20 package org.netbeans.modules.j2ee.oc4j; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.net.URL ; 25 import java.net.URLClassLoader ; 26 import java.util.Collections ; 27 import java.util.Enumeration ; 28 import java.util.HashMap ; 29 import java.util.Map ; 30 import org.openide.ErrorManager; 31 32 36 public class OC4JClassLoader extends URLClassLoader { 37 38 private ClassLoader oldLoader; 39 private String serverRoot; 40 41 private static Map <String , OC4JClassLoader> instances = new HashMap <String , OC4JClassLoader>(); 42 43 48 public static OC4JClassLoader getInstance(String serverRoot) { 49 OC4JClassLoader instance = instances.get(serverRoot); 50 if (instance == null) { 51 instance = new OC4JClassLoader(serverRoot); 52 instances.put(serverRoot, instance); 53 } 54 return instance; 55 } 56 57 private OC4JClassLoader(String serverRoot) { 58 super(new URL [0], OC4JDeploymentFactory.class.getClassLoader()); 59 60 this.serverRoot = serverRoot; 61 62 try{ 63 URL [] urls = new URL [] { 64 new File (serverRoot + "/j2ee/home/lib/adminclient.jar").toURI().toURL(), new File (serverRoot + "/j2ee/home/oc4jclient.jar").toURI().toURL(), new File (serverRoot + "/webservices/lib/wsserver.jar").toURI().toURL(), new File (serverRoot + "/j2ee/home/lib/ejb.jar").toURI().toURL(), new File (serverRoot + "/j2ee/home/lib/mx4j-jmx.jar").toURI().toURL(), new File (serverRoot + "/j2ee/home/lib/jmxri.jar").toURI().toURL(), new File (serverRoot + "/j2ee/home/lib/jmx_remote_api.jar").toURI().toURL(), new File (serverRoot + "/j2ee/home/lib/jaas.jar").toURI().toURL(), new File (serverRoot + "/lib/xmlparserv2.jar").toURI().toURL(), new File (serverRoot + "/oracle/lib/xmlparserv2.jar").toURI().toURL(), new File (serverRoot + "/j2ee/home/lib/javax77.jar").toURI().toURL(), new File (serverRoot + "/j2ee/home/lib/javax88.jar").toURI().toURL(), new File (serverRoot + "/diagnostics/lib/ojdl.jar").toURI().toURL(), new File (serverRoot + "/oracle/lib/dms.jar").toURI().toURL(), new File (serverRoot + "/oracle/jlib/dms.jar").toURI().toURL(), new File (serverRoot + "/lib/dms.jar").toURI().toURL(), new File (serverRoot + "/jlib/dms.jar").toURI().toURL(), new File (serverRoot + "/j2ee/home/lib/jta.jar").toURI().toURL(), new File (serverRoot + "/j2ee/home/lib/jms.jar").toURI().toURL(), new File (serverRoot + "/j2ee/home/lib/connector.jar").toURI().toURL(), new File (serverRoot + "/opmn/lib/optic.jar").toURI().toURL(), new File (serverRoot + "/oracle/jlib/oraclepki.jar").toURI().toURL(), new File (serverRoot + "/jlib/oraclepki.jar").toURI().toURL(), new File (serverRoot + "/oracle/jlib/ojpse.jar").toURI().toURL(), 88 new File (serverRoot + "/oracle/jdbc/lib/ojdbc14d ms.jar").toURI().toURL(), new File (serverRoot + "/oracle/jdbc/lib/ocrs12.jar").toURI().toURL(), new File (serverRoot + "/oracle/rdbms/jlib/aqapi.jar").toURI().toURL(), new File (serverRoot + "/jlib/ojpse.jar").toURI().toURL() }; 93 for (int i = 0; i < urls.length; i++) { 94 addURL(urls[i]); 95 } 96 }catch(Exception e) { 97 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 98 } 99 } 100 101 public Enumeration <URL > getResources(String name) throws IOException { 102 if (name.indexOf("jndi.properties") != -1) { return Collections.enumeration(Collections.<URL >emptyList()); 105 } 106 107 return super.getResources(name); 108 } 109 110 public synchronized void updateLoader() { 111 if (!Thread.currentThread().getContextClassLoader().equals(this)) { 112 oldLoader = Thread.currentThread().getContextClassLoader(); 113 Thread.currentThread().setContextClassLoader(this); 114 } 115 } 116 117 public synchronized void restoreLoader() { 118 if (oldLoader != null) { 119 Thread.currentThread().setContextClassLoader(oldLoader); 120 oldLoader = null; 121 } 122 } 123 } | Popular Tags |