com.jaxfront.core.util.io.classloader
Class ClassScope

java.lang.Object
  extended by com.jaxfront.core.util.io.classloader.ClassScope

public abstract class ClassScope
extends java.lang.Object

A simple static API for listing classes loaded in a JVM. getClassLocation(Class) from http://www.javaworld.com/javaworld/javaqa/2003-07/01-qa-0711-classsrc.html also thrown in for a good measure. See individual methods for further details.

NOTE: use for testing/debugging only.


Method Summary
static java.lang.String dump()
           
static java.lang.String dump(java.lang.ClassLoader[] loaders)
           
static java.lang.ClassLoader[] getCallerClassLoaderTree()
          Returns the class loader set "relevant" to the calling class, as described in the article.
static java.net.URL getClassLocation(java.lang.Class cls)
          Given a Class object, attempts to find its .class location [returns null if no such definiton could be found].
static java.lang.Class[] getLoadedClasses(java.lang.ClassLoader loader)
          Given a class loader instance, returns all classes currently loaded by that class loader.
static java.lang.Class[] getLoadedClasses(java.lang.ClassLoader[] loaders)
          A convenience multi-loader version of getLoadedClasses(ClassLoader).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

dump

public static java.lang.String dump()

dump

public static java.lang.String dump(java.lang.ClassLoader[] loaders)

getCallerClassLoaderTree

public static java.lang.ClassLoader[] getCallerClassLoaderTree()
Returns the class loader set "relevant" to the calling class, as described in the article. Starting with the class that is the caller of this method, it collects all class loaders that are loaders for all classes on the call stack and their respective parent loaders.

Returns:
ClassLoader array [never null]
Throws:
java.lang.RuntimeException - if the caller context resolver could not be instantiated

getClassLocation

public static java.net.URL getClassLocation(java.lang.Class cls)
Given a Class object, attempts to find its .class location [returns null if no such definiton could be found].

Returns:
URL that points to the class definition [null if not found]

getLoadedClasses

public static java.lang.Class[] getLoadedClasses(java.lang.ClassLoader loader)
Given a class loader instance, returns all classes currently loaded by that class loader.

Parameters:
defining - class loader to inspect [may not be null]
Returns:
Class array such that every Class has 'loader' as its defining class loader [never null, may be empty]
Throws:
java.lang.RuntimeException - if the "classes" field hack is not possible in this JRE

getLoadedClasses

public static java.lang.Class[] getLoadedClasses(java.lang.ClassLoader[] loaders)
A convenience multi-loader version of getLoadedClasses(ClassLoader).

Parameters:
an - array of defining class loaders to inspect [may not be null]
Returns:
Class array [never null, may be empty]
Throws:
java.lang.RuntimeException - if the "classes" field hack is not possible in this JRE