001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of either the BSD licence or the GNU Lesser General 006 * Public Licence. These should be distributed with the code. 007 * If you do not have copies see: 008 * 009 * http://www.opensource.org/licenses/bsd-license.php 010 * http://www.gnu.org/copyleft/lesser.html 011 * 012 * Copyright for this code is held jointly by the individual 013 * authors. These should be listed in @author doc comments. 014 * 015 * For more information on the BioJava project and its aims, 016 * or to join the biojava-l mailing list, visit the home page 017 * at: 018 * 019 * http://www.biojava.org/ 020 * 021 */ 022 023package org.biojava.utils; 024 025/** 026 * Utility methods for manipulating class objects and resources. 027 * 028 * @author Thomas Down 029 * @since 1.4 030 */ 031 032public class ClassTools { 033 private ClassTools() { 034 } 035 036 /** 037 * Get the classloader which loaded the class of <code>obj</code>. 038 */ 039 040 public static ClassLoader getClassLoader(Object obj) { 041 return getClassLoader(obj.getClass()); 042 } 043 044 /** 045 * Get the classloader which loaded <code>clazz</code>. This is 046 * a "safe" method which handles <code>null</code> classloaders 047 * and returns the system classloader instead. 048 */ 049 050 public static ClassLoader getClassLoader(Class clazz) { 051 ClassLoader cl = clazz.getClassLoader(); 052 if (cl == null) { 053 cl = ClassLoader.getSystemClassLoader(); 054 } 055 return cl; 056 } 057}