1 17 package org.alfresco.util; 18 19 import java.net.URL ; 20 21 26 public class Debug 27 { 28 35 public static String whichClass(String className) throws ClassNotFoundException 36 { 37 String path = className; 38 39 if (path.startsWith("/") == false) 41 { 42 path = "/" + path; 43 } 44 path = path.replace('.', '/'); 45 path = path + ".class"; 46 47 URL url = Debug.class.getResource(path); 49 if (url == null) 50 { 51 throw new ClassNotFoundException (className); 52 } 53 54 String location = url.toExternalForm(); 56 if (location.startsWith("jar")) 57 { 58 location = location.substring(10, location.lastIndexOf("!")); 59 } 60 else if (location.startsWith("file:")) 61 { 62 location = location.substring(6); 63 } 64 65 return location; 66 } 67 68 75 public static String whichClassLoader(String className) throws ClassNotFoundException 76 { 77 String result = "Could not determine class loader for " + className; 78 79 Class clazz = Class.forName(className); 80 ClassLoader loader = clazz.getClassLoader(); 81 82 if (loader != null) 83 { 84 result = clazz.getClassLoader().toString(); 85 } 86 87 return result; 88 } 89 90 97 public static String whichClassLoaderHierarchy(String className) throws ClassNotFoundException 98 { 99 StringBuffer buffer = new StringBuffer (); 100 Class clazz = Class.forName(className); 101 ClassLoader loader = clazz.getClassLoader(); 102 if (loader != null) 103 { 104 buffer.append(loader.toString()); 105 106 ClassLoader parent = loader.getParent(); 107 while (parent != null) 108 { 109 buffer.append("\n-> ").append(parent.toString()); 110 parent = parent.getParent(); 111 } 112 } 113 else 114 { 115 buffer.append("Could not determine class loader for " + className); 116 } 117 118 return buffer.toString(); 119 } 120 } 121 | Popular Tags |