1 22 package org.jboss.test.util; 23 24 import java.lang.reflect.Method ; 25 import java.net.URL ; 26 import java.security.CodeSource ; 27 import java.security.ProtectionDomain ; 28 29 32 public class Debug 33 { 34 40 public static void displayClassInfo(Class clazz, StringBuffer results) 41 { 42 ClassLoader cl = clazz.getClassLoader(); 44 results.append("\n"+clazz.getName()+".ClassLoader="+cl); 45 ClassLoader parent = cl; 46 while( parent != null ) 47 { 48 results.append("\n.."+parent); 49 URL [] urls = getClassLoaderURLs(parent); 50 int length = urls != null ? urls.length : 0; 51 for(int u = 0; u < length; u ++) 52 { 53 results.append("\n...."+urls[u]); 54 } 55 if( parent != null ) 56 parent = parent.getParent(); 57 } 58 CodeSource clazzCS = clazz.getProtectionDomain().getCodeSource(); 59 if( clazzCS != null ) 60 results.append("\n++++CodeSource: "+clazzCS); 61 else 62 results.append("\n++++Null CodeSource"); 63 64 results.append("\nImplemented Interfaces:"); 65 Class [] ifaces = clazz.getInterfaces(); 66 for(int i = 0; i < ifaces.length; i ++) 67 { 68 results.append("\n++"+ifaces[i]); 69 ClassLoader loader = ifaces[i].getClassLoader(); 70 results.append("\n++++ClassLoader: "+loader); 71 ProtectionDomain pd = ifaces[i].getProtectionDomain(); 72 CodeSource cs = pd.getCodeSource(); 73 if( cs != null ) 74 results.append("\n++++CodeSource: "+cs); 75 else 76 results.append("\n++++Null CodeSource"); 77 } 78 } 79 80 84 public static URL [] getClassLoaderURLs(ClassLoader cl) 85 { 86 URL [] urls = {}; 87 try 88 { 89 Class returnType = urls.getClass(); 90 Class [] parameterTypes = {}; 91 Method getURLs = cl.getClass().getMethod("getURLs", parameterTypes); 92 if( returnType.isAssignableFrom(getURLs.getReturnType()) ) 93 { 94 Object [] args = {}; 95 urls = (URL []) getURLs.invoke(cl, args); 96 } 97 } 98 catch(Exception ignore) 99 { 100 } 101 return urls; 102 } 103 104 } 105 | Popular Tags |