net.sf.jguiraffe.di
Interface ClassLoaderProvider

All Known Subinterfaces:
DependencyProvider
All Known Implementing Classes:
DefaultClassLoaderProvider, RestrictedDependencyProvider

public interface ClassLoaderProvider

Definition of an interface for objects that act as a registry for class loaders.

In complex environments different class loaders can play an important role. Thus the dependency injection framework supports the registration of arbitrary class loaders; they are assigned a symbolic name. When a class is loaded, a class loader can be specified by the symbolic name it was registered.

This interface provides access to the registered class loaders by their symbolic name. It can be used by components that need to load class per reflection.

Version:
$Id: ClassLoaderProvider.java 156 2009-03-03 21:04:47Z oheger $
Author:
Oliver Heger

Field Summary
static java.lang.String CONTEXT_CLASS_LOADER
          Constant for the reserved name of the context class loader.
 
Method Summary
 java.util.Set<java.lang.String> classLoaderNames()
          Returns a set with the names of all registered class loaders.
 java.lang.ClassLoader getClassLoader(java.lang.String name)
          Returns a reference to the class loader with the specified symbolic name.
 java.lang.ClassLoader getDefaultClassLoader()
          Returns the default class loader used for dynamically loading classes.
 java.lang.Class<?> loadClass(java.lang.String name, java.lang.String loaderRef)
          Returns the class specified by the given name.
 void registerClassLoader(java.lang.String name, java.lang.ClassLoader loader)
          Allows to register a ClassLoader by name.
 void setDefaultClassLoader(java.lang.ClassLoader loader)
          Sets the default class loader.
 

Field Detail

CONTEXT_CLASS_LOADER

static final java.lang.String CONTEXT_CLASS_LOADER
Constant for the reserved name of the context class loader. If this constant is passed into the getClassLoader() method, the context class loader will automatically be used.

See Also:
Constant Field Values
Method Detail

getClassLoader

java.lang.ClassLoader getClassLoader(java.lang.String name)
Returns a reference to the class loader with the specified symbolic name. The passed in name can be null, then a default class loader will be returned. The constant CONTEXT_CLASS_LOADER can be passed in, too, for obtaining a reference to the context class loader. In all other cases the parameter is interpreted as the symbolic name of a registered class loader. If no class loader is found under this name, an exception will be thrown.

Parameters:
name - the name of the desired class loader
Returns:
the class loader for this name
Throws:
InjectionException - if the class loader cannot be resolved

loadClass

java.lang.Class<?> loadClass(java.lang.String name,
                             java.lang.String loaderRef)
Returns the class specified by the given name. This is a convenience method that obtains the class loader specified by its symbolic name and immediately uses it for loading a class. If the name of the class loader is null, the default class loader will be used. Occurring exceptions are re-thrown as runtime exceptions.

Parameters:
name - the name of the class to be loaded (must not be null)
loaderRef - the name, under which the desired class loader is registered (null for the default class loader)
Returns:
the loaded class
Throws:
InjectionException - if the class cannot be loaded
java.lang.IllegalArgumentException - if the class name is null, or if the reference to the class loader cannot be resolved

registerClassLoader

void registerClassLoader(java.lang.String name,
                         java.lang.ClassLoader loader)
Allows to register a ClassLoader by name. This class loader can later be accessed using the getClassLoader() method. If the class loader reference is null, the class loader with the given name will be unregistered.

Parameters:
name - a symbolic name for the class loader (must not be null)
loader - the class loader to be registered
Throws:
java.lang.IllegalArgumentException - if the name is undefined

getDefaultClassLoader

java.lang.ClassLoader getDefaultClassLoader()
Returns the default class loader used for dynamically loading classes.

Returns:
the default class loader

setDefaultClassLoader

void setDefaultClassLoader(java.lang.ClassLoader loader)
Sets the default class loader. This class loader will be used for all dynamic class loading operations when no other class loader is specified.

Parameters:
loader - the new default class loader

classLoaderNames

java.util.Set<java.lang.String> classLoaderNames()
Returns a set with the names of all registered class loaders.

Returns:
the names of all registered class loaders


Copyright © 2009 The JGUIraffe Team. All Rights Reserved.