fc.util
Class ClassUtil

java.lang.Object
  extended by fc.util.ClassUtil

public final class ClassUtil
extends java.lang.Object


Constructor Summary
ClassUtil()
           
 
Method Summary
static java.lang.String getClassLoaderInfo(java.lang.Class c)
          Returns classloader information about the specified class.
static java.lang.String getClassLoaderInfo(java.lang.Object obj)
          Returns classloader information about the specified object
static java.lang.String getClassName()
          This method can be called from either a instance or a static method.
static java.lang.String getLoadedFromPath(java.lang.Class caller)
          Returns either the directory or jar file from which the specified class was loaded
static java.lang.String getMainClassName()
          Returns the fully qualified name of the class that contained the main() method used to invoke the application.
static java.lang.String getParentDir(java.lang.Class caller)
          Returns the right most parent directory from which the actual class was loaded.
static java.net.URL getParentDirAsURL(java.lang.Class caller)
          Returns the parent directory from which the actual class was loaded.
static boolean isSystemClass(java.lang.Class c)
          Returns true is the specified class is a system/JDK class.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtil

public ClassUtil()
Method Detail

getClassLoaderInfo

public static java.lang.String getClassLoaderInfo(java.lang.Object obj)
Returns classloader information about the specified object


getClassLoaderInfo

public static java.lang.String getClassLoaderInfo(java.lang.Class c)
Returns classloader information about the specified class.


getClassName

public static java.lang.String getClassName()
This method can be called from either a instance or a static method. Returns the class name in which the calling method was declared.

Important note: The returned class name is wherever the method is invoked from. For instance methods, it is the runtime virtual class. For static it is the class name where the method was declared (static methods are not virtual and bound at compile time). For example:


Class A 
        { 
        static void foo(...) {
                System.out.print(ClassUtil.getClassName());
                }
        }

public class B extends A
        {
        }

% java B  
will print:
        A [NOT B]


getMainClassName

public static java.lang.String getMainClassName()
Returns the fully qualified name of the class that contained the main() method used to invoke the application. Note: this method must be called from the same thread (the "main" thread) that started the application. Newly started threads that call this method will instead obtain the class name containing that thread's run() method.


isSystemClass

public static boolean isSystemClass(java.lang.Class c)
Returns true is the specified class is a system/JDK class. This method should work, but given the vagaries of classes, classloaders, etc, there isn't any guarantee.

Parameters:
caller - the object or Class Class corresponding to that object

getLoadedFromPath

public static java.lang.String getLoadedFromPath(java.lang.Class caller)
Returns either the directory or jar file from which the specified class was loaded

This does not work for system/bootstrap classes and will return null for system classes.

Parameters:
caller - the Class class to be looked up

getParentDir

public static java.lang.String getParentDir(java.lang.Class caller)
Returns the right most parent directory from which the actual class was loaded. This is the leaf directory where the actual class is located.

For classes loaded from other sources (jar, etc), the return value will be null.

This also does not work for system/bootstrap classes (they are typically loaded from jars) either (those will return null also)

Parameters:
caller - the Class class to be looked up

getParentDirAsURL

public static java.net.URL getParentDirAsURL(java.lang.Class caller)
Returns the parent directory from which the actual class was loaded. This is the leaf directory where the actual class is located.

For classes loaded from other sources (jar, etc), a URL will be returned. For jar URL's, the URL.getProtocol() method returns "jar", so that can be useful for further processing as needed.

Parameters:
caller - the Class class to be looked up

main

public static void main(java.lang.String[] args)