1 16 17 package org.springframework.util; 18 19 28 public abstract class ClassLoaderUtils { 29 30 38 public static String showClassLoaderHierarchy(Object obj, String role) { 39 return showClassLoaderHierarchy(obj, role, "\n", "\t"); 40 } 41 42 51 public static String showClassLoaderHierarchy(Object obj, String role, String lineBreak, String tabText) { 52 String s = "object of " + obj.getClass() + ": role is " + role + lineBreak; 53 return s + showClassLoaderHierarchy(obj.getClass().getClassLoader(), lineBreak, tabText, 0); 54 } 55 56 62 public static String showClassLoaderHierarchy(ClassLoader cl) { 63 return showClassLoaderHierarchy(cl, "\n", "\t"); 64 } 65 66 73 public static String showClassLoaderHierarchy(ClassLoader cl, String lineBreak, String tabText) { 74 return showClassLoaderHierarchy(cl, lineBreak, tabText, 0); 75 } 76 77 85 private static String showClassLoaderHierarchy(ClassLoader cl, String lineBreak, String tabText, int indent) { 86 if (cl == null) { 87 ClassLoader ccl = Thread.currentThread().getContextClassLoader(); 88 return "context class loader=[" + ccl + "] hashCode=" + ccl.hashCode(); 89 } 90 StringBuffer buf = new StringBuffer (); 91 for (int i = 0; i < indent; i++) { 92 buf.append(tabText); 93 } 94 buf.append("[").append(cl).append("] hashCode=").append(cl.hashCode()).append(lineBreak); 95 ClassLoader parent = cl.getParent(); 96 return buf.toString() + showClassLoaderHierarchy(parent, lineBreak, tabText, indent + 1); 97 } 98 99 } 100 | Popular Tags |