1 package org.jboss.cache.marshall.data; 2 3 import java.lang.reflect.Method ; 4 import java.net.URL ; 5 import java.security.CodeSource ; 6 import java.security.ProtectionDomain ; 7 8 13 public class Debug 14 { 15 22 public static void displayClassInfo(Class clazz, StringBuffer results) 23 { 24 displayClassInfo(clazz, results, true); 25 } 26 27 public static void displayClassInfo(Class clazz, StringBuffer results, 28 boolean showParentClassLoaders) 29 { 30 31 ClassLoader cl = clazz.getClassLoader(); 32 results.append("\n" + clazz.getName() + "(" + Integer.toHexString(clazz.hashCode()) + ").ClassLoader=" + cl); 33 ClassLoader parent = cl; 34 while (parent != null) 35 { 36 results.append("\n.." + parent); 37 URL [] urls = getClassLoaderURLs(parent); 38 int length = urls != null ? urls.length : 0; 39 for (int u = 0; u < length; u ++) 40 { 41 results.append("\n...." + urls[u]); 42 } 43 if (showParentClassLoaders == false) 44 { 45 break; 46 } 47 if (parent != null) 48 { 49 parent = parent.getParent(); 50 } 51 } 52 CodeSource clazzCS = clazz.getProtectionDomain().getCodeSource(); 53 if (clazzCS != null) 54 { 55 results.append("\n++++CodeSource: " + clazzCS); 56 } 57 else 58 { 59 results.append("\n++++Null CodeSource"); 60 } 61 62 results.append("\nImplemented Interfaces:"); 63 Class [] ifaces = clazz.getInterfaces(); 64 for (int i = 0; i < ifaces.length; i ++) 65 { 66 Class iface = ifaces[i]; 67 results.append("\n++" + iface + "(" + Integer.toHexString(iface.hashCode()) + ")"); 68 ClassLoader loader = ifaces[i].getClassLoader(); 69 results.append("\n++++ClassLoader: " + loader); 70 ProtectionDomain pd = ifaces[i].getProtectionDomain(); 71 CodeSource cs = pd.getCodeSource(); 72 if (cs != null) 73 { 74 results.append("\n++++CodeSource: " + cs); 75 } 76 else 77 { 78 results.append("\n++++Null CodeSource"); 79 } 80 } 81 } 82 83 88 public static URL [] getClassLoaderURLs(ClassLoader cl) 89 { 90 URL [] urls = {}; 91 try 92 { 93 Class returnType = urls.getClass(); 94 Class [] parameterTypes = {}; 95 Method getURLs = cl.getClass().getMethod("getURLs", parameterTypes); 96 if (returnType.isAssignableFrom(getURLs.getReturnType())) 97 { 98 Object [] args = {}; 99 urls = (URL []) getURLs.invoke(cl, args); 100 } 101 } 102 catch (Exception ignore) 103 { 104 } 105 return urls; 106 } 107 108 } 109 | Popular Tags |