e.g. Calendar Search Help
You must enter a value before pressing Search
spring

Class: org.springframework.util.ClassLoaderUtils   ©

 OK to copy?
01 /*
02  * Copyright 2002-2004 the original author or authors.
03  * 
04  * Licensed under the Apache License, Version 2.0 (the "License");
05  * you may not use this file except in compliance with the License.
06  * You may obtain a copy of the License at
07  * 
08  *      http://www.apache.org/licenses/LICENSE-2.0
09  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */ 
16 
17 package org.springframework.util;
18 
19 /**
20  * Utility class for diagnostic purposes, to analyze the
21  * ClassLoader hierarchy for any object.
22  * @author Rod Johnson
23  * @since 02 April 2001
24  * @see java.lang.ClassLoader
25  */
26 public abstract class ClassLoaderUtils {
27 
28     /**
29      * Show the class loader hierarchy for this class.
30      * @param obj object to analyze loader hierarchy for
31      * @param role a description of the role of this class in the application
32      * (e.g., "servlet" or "EJB reference")
33      * @param delim line break
34      * @param tabText text to use to set tabs
35      * @return a String showing the class loader hierarchy for this class
36      */
37     public static String showClassLoaderHierarchy(Object obj, String role, String delim, String tabText) {
38         String s = "object of " + obj.getClass() + ": role is " + role + delim;
39         return s + showClassLoaderHierarchy(obj.getClass().getClassLoader(), delim, tabText, 0);
40     }
41 
42     /**
43      * Show the class loader hierarchy for this class.
44      * @param cl class loader to analyze hierarchy for
45      * @param delim line break
46      * @param tabText text to use to set tabs
47      * @param indent nesting level (from 0) of this loader; used in pretty printing
48      * @return a String showing the class loader hierarchy for this class
49      */
50     public static String showClassLoaderHierarchy(ClassLoader cl, String delim, String tabText, int indent) {
51         if (cl == null) {
52             String s = "null classloader " + delim;
Rate53             ClassLoader ctxcl = Thread.currentThread().getContextClassLoader();
54             s += "Context class loader=" + ctxcl + " hc=" + ctxcl.hashCode();
55             return s;
56         }
57         String s = "";
58         for (int i = 0; i < indent; i++) {
59             s += tabText;
60         }
61         s += cl + " hc=" + cl.hashCode() + delim;
62         ClassLoader parent = cl.getParent();
63         return s + showClassLoaderHierarchy(parent, delim, tabText, indent + 1);
64     }
65 
66 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
53 0% of 0