1 17 package org.apache.geronimo.kernel.util; 18 19 import java.net.URLClassLoader ; 20 import java.net.URL ; 21 import org.apache.geronimo.kernel.config.MultiParentClassLoader; 22 23 28 public class ClassLoaderDumper { 29 public static void dump(Object o) { 30 if(o != null) dump(o.getClass().getClassLoader()); 31 } 32 public static void dump(Class cls) { 33 System.out.println("ClassLoader dump for "+cls.getName()); 34 dump(cls.getClassLoader()); 35 } 36 public static void dump(ClassLoader loader) { 37 dumpIDs("", loader); 38 dumpContents("", loader); 39 } 40 private static void dumpIDs(String prefix, ClassLoader loader) { 41 if(loader == null) return; 42 System.out.println(prefix+"ClassLoader is "+loader); 43 44 if(loader instanceof MultiParentClassLoader) { 45 MultiParentClassLoader mp = (MultiParentClassLoader) loader; 46 ClassLoader [] parents = mp.getParents(); 47 for (int i = 0; i < parents.length; i++) { 48 dumpIDs(prefix+" ", parents[i]); 49 } 50 } else { 51 dumpIDs(prefix+" ", loader.getParent()); 52 } 53 } 54 private static void dumpContents(String prefix, ClassLoader loader) { 55 if(loader == null) return; 56 System.out.println(prefix+"ClassLoader is "+loader); 57 58 if(loader instanceof URLClassLoader ) { 59 URLClassLoader url = (URLClassLoader ) loader; 60 URL [] entries = url.getURLs(); 61 for (int i = 0; i < entries.length; i++) { 62 URL entry = entries[i]; 63 System.out.println(prefix+" "+entry); 64 } 65 } 66 if(loader instanceof MultiParentClassLoader) { 67 MultiParentClassLoader mp = (MultiParentClassLoader) loader; 68 ClassLoader [] parents = mp.getParents(); 69 for (int i = 0; i < parents.length; i++) { 70 dumpContents(prefix+" ", parents[i]); 71 } 72 } else { 73 dumpContents(prefix+" ", loader.getParent()); 74 } 75 } 76 } 77 | Popular Tags |