com.vladium.util
Class ClassLoaderResolver

java.lang.Object
  extended by com.vladium.util.ClassLoaderResolver

public abstract class ClassLoaderResolver
extends java.lang.Object

This non-instantiable non-subclassable class acts as the global point for choosing a ClassLoader for dynamic class/resource loading at any point in an application.

Author:
Vlad Roubtsov, (C) 2003
See Also:
ResourceLoader, IClassLoadStrategy, ClassLoaderResolver.DefaultClassLoadStrategy

Nested Class Summary
private static class ClassLoaderResolver.CallerResolver
          A helper class to get the call context.
private static class ClassLoaderResolver.DefaultClassLoadStrategy
           
 
Field Summary
private static int CALL_CONTEXT_OFFSET
           
private static ClassLoaderResolver.CallerResolver CALLER_RESOLVER
           
private static IClassLoadStrategy s_strategy
           
 
Constructor Summary
private ClassLoaderResolver()
           
 
Method Summary
static java.lang.Class getCallerClass(int callerOffset)
           
static java.lang.ClassLoader getClassLoader()
          This method selects the "best" classloader instance to be used for class/resource loading by whoever calls this method.
static java.lang.ClassLoader getClassLoader(java.lang.Class caller)
          This method selects the "best" classloader instance to be used for class/resource loading by whoever calls this method.
static IClassLoadStrategy getStrategy()
          Gets the current classloader selection strategy setting.
static boolean isChild(java.lang.ClassLoader loader1, java.lang.ClassLoader loader2)
          Returns 'true' if 'loader2' is a delegation child of 'loader1' [or if 'loader1'=='loader2'].
static IClassLoadStrategy setStrategy(IClassLoadStrategy strategy)
          Sets the classloader selection strategy to be used by subsequent calls to getClassLoader().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_strategy

private static IClassLoadStrategy s_strategy

CALL_CONTEXT_OFFSET

private static final int CALL_CONTEXT_OFFSET
See Also:
Constant Field Values

CALLER_RESOLVER

private static final ClassLoaderResolver.CallerResolver CALLER_RESOLVER
Constructor Detail

ClassLoaderResolver

private ClassLoaderResolver()
Method Detail

getClassLoader

public static java.lang.ClassLoader getClassLoader(java.lang.Class caller)
This method selects the "best" classloader instance to be used for class/resource loading by whoever calls this method. The decision typically involves choosing between the caller's current, thread context, system, and other classloaders in the JVM and is made by the IClassLoadStrategy instance established by the last call to setStrategy(com.vladium.util.IClassLoadStrategy).

This method does not throw.

Parameters:
caller - [null input eliminates the caller's current classloader from consideration]
Returns:
classloader to be used by the caller ['null' indicates the primordial loader]

getClassLoader

public static java.lang.ClassLoader getClassLoader()
This method selects the "best" classloader instance to be used for class/resource loading by whoever calls this method. The decision typically involves choosing between the caller's current, thread context, system, and other classloaders in the JVM and is made by the IClassLoadStrategy instance established by the last call to setStrategy(com.vladium.util.IClassLoadStrategy).

This method uses its own caller to set the call context. To be able to override this decision explicitly, use getClassLoader(Class).

This method does not throw.

Returns:
classloader to be used by the caller ['null' indicates the primordial loader]

getCallerClass

public static java.lang.Class getCallerClass(int callerOffset)

isChild

public static boolean isChild(java.lang.ClassLoader loader1,
                              java.lang.ClassLoader loader2)
Returns 'true' if 'loader2' is a delegation child of 'loader1' [or if 'loader1'=='loader2']. Of course, this works only for classloaders that set their parent pointers correctly. 'null' is interpreted as the primordial loader [i.e., everybody's parent].


getStrategy

public static IClassLoadStrategy getStrategy()
Gets the current classloader selection strategy setting.


setStrategy

public static IClassLoadStrategy setStrategy(IClassLoadStrategy strategy)
Sets the classloader selection strategy to be used by subsequent calls to getClassLoader(). An instance of ClassLoaderResolver.DefaultClassLoadStrategy is in effect if this method is never called.

Parameters:
strategy - new strategy [may not be null]
Returns:
previous setting