1 23 package com.sun.enterprise.appclient.jws.boot; 24 25 import java.io.File ; 26 import java.lang.reflect.InvocationTargetException ; 27 import java.lang.reflect.Method ; 28 import java.net.MalformedURLException ; 29 import java.net.URI ; 30 import java.net.URISyntaxException ; 31 import java.net.URL ; 32 import java.net.URLClassLoader ; 33 import java.util.jar.JarFile ; 34 35 44 public abstract class ClassPathManager { 45 46 47 private static ClassPathManager mgr = null; 48 49 53 public static ClassPathManager getClassPathManager() { 54 if (mgr == null) { 55 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 56 61 if (loader instanceof URLClassLoader ) { 62 mgr = new ClassPathManager16(loader); 63 } else { 64 mgr = new ClassPathManager15(loader); 65 } 66 } 67 return mgr; 68 } 69 70 71 private ClassLoader jnlpClassLoader = null; 72 73 77 protected ClassPathManager(ClassLoader loader) { 78 jnlpClassLoader = loader; 79 } 80 81 86 public URI locateClass(String className) throws 87 IllegalAccessException , 88 InvocationTargetException , 89 MalformedURLException , 90 URISyntaxException { 91 String resourceName = classNameToResourceName(className); 92 URL classURL = locateResource(resourceName); 93 File f = findContainingJar(classURL); 94 return f.toURI(); 95 } 96 97 101 public abstract ClassLoader getParentClassLoader(); 102 103 108 public abstract File findContainingJar(URL resourceURL) throws 109 IllegalArgumentException , 110 URISyntaxException , 111 MalformedURLException , 112 IllegalAccessException , 113 InvocationTargetException ; 114 115 120 protected ClassLoader getJNLPClassLoader() { 121 return jnlpClassLoader; 122 } 123 124 129 protected String classNameToResourceName(String className) { 130 return className.replace(".", "/") + ".class"; 131 } 132 133 138 protected URL locateResource(String resourceName) { 139 URL resourceURL = getClass().getClassLoader().getResource(resourceName); 140 return resourceURL; 141 } 142 143 148 public URL [] locateDownloadedJars() throws 149 ClassNotFoundException , 150 URISyntaxException , 151 NoSuchMethodException , 152 IllegalAccessException , 153 InvocationTargetException , 154 MalformedURLException { 155 164 String probeClassNames = System.getProperty("com.sun.aas.jar.probe.class.names", 165 "com.sun.enterprise.appclient.jws.boot.JWSACCMain," + 166 "com.sun.enterprise.appclient.Main," + 167 "com.sun.jdo.api.persistence.enhancer.ByteCodeEnhancer," + 168 "com.sun.enterprise.admin.servermgmt.DomainConfig," + 169 "com.sun.enterprise.deployment.client.DeploymentClientUtils," + 170 "javax.ejb.EJB," + 171 "com.sun.appserv.management.ext.logging.LogAnalyzer," + 172 "com.sun.mail.iap.Argument," + 173 "com.sun.activation.viewers.ImageViewer," + 174 "com.sun.codemodel.ClassType," + 175 "org.apache.derby.client.ClientDataSourceFactory," + 176 "persistence.antlr.ActionElement," + 177 "org.netbeans.modules.dbschema.ColumnElement," + 178 "com.sun.jms.spi.xa.JMSXAConnection," + 179 "com.sun.jndi.fscontext.FSContext" 180 ); 181 182 String [] classNames = probeClassNames.split(","); 183 184 188 URL [] urls = new URL [classNames.length]; 189 int nextURL = 0; 190 191 for (String className : classNames) { 192 URI jarFileURI = locateClass(className); 193 URL url = jarFileURI.toURL(); 194 urls[nextURL++] = url; 195 } 196 return urls; 197 } 198 } 199 | Popular Tags |