Mp3dings 
20100427

de.mospace.lang
Class DefaultClassLoaderProvider

java.lang.Object
  extended by de.mospace.lang.MinimalClassLoaderProvider
      extended by de.mospace.lang.DefaultClassLoaderProvider
All Implemented Interfaces:
ClassLoaderProvider, Serializable
Direct Known Subclasses:
Application

public class DefaultClassLoaderProvider
extends MinimalClassLoaderProvider
implements Serializable

A fully functional implementation of the ClassLoaderProvider interface. Libraries can be registered with a DefaultClassLoaderProvider and class loaders that look for class files in these libraries can be obtained with the getClassLoader() method.

See Also:
Serialized Form

Field Summary
static long serialVersionUID
          serialization version id
 
Constructor Summary
DefaultClassLoaderProvider()
          Constructs a new ClassLoaderProvider whose getClassLoader() method will return class loaders that finally delegate to the system class loader.
DefaultClassLoaderProvider(ClassLoader parent)
          Constructs a new ClassLoaderProvider whose getClassLoader() method will return class loaders that finally delegate to the specified class loader.
 
Method Summary
 ClassLoader getClassLoader()
          Returns a class loader that looks for class files in all libraries that have been successfully registered with this ClassLoaderProvider, so far.
 URL[] getLibraries()
          Returns all libraries that have been registered with this ClassLoaderProvider, so far.
 File[] getLibraryFiles()
          Returns the library files that have been registered with this ClassLoaderProvider, so far.
static URI getRepositoryRoot(Class klass)
          Tries to determine the class path element from which the specified class has been loaded.
static File getRepositoryRootDir(Class klass)
          Tries to determine the directory that is or that contains the class path element from which the specified class has been loaded.
static boolean isTemporary(File file)
          Determines whether the path of the specified file starts with the directory specified in the Java system property java.io.tmpdir.
 boolean registerDirectory(File dir)
          Requests that the specified directory be registered, so that it is on the class path of all class loaders returned by future calls to getClassLoader().
 boolean registerLibraries(File[] jarFiles)
          Requests that the specified jar files be registered, so that they are in the class path of all class loaders returned by future calls to getClassLoader().
 boolean registerLibrary(File jarFile)
          Requests that the specified jar file be registered, so that it is in the class path of all class loaders returned by future calls to getClassLoader().
 boolean registerLibraryDirectories(File[] dirs)
          Requests that all jar files in the specified directories be registered, so that they are in the class path of all class loaders returned by future calls to getClassLoader().
 boolean registerLibraryDirectory(File dir)
          Requests that all jar files in the specified directory be registered, so that they are in the class path of all class loaders returned by future calls to getClassLoader().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
serialization version id

See Also:
Constant Field Values
Constructor Detail

DefaultClassLoaderProvider

public DefaultClassLoaderProvider()
Constructs a new ClassLoaderProvider whose getClassLoader() method will return class loaders that finally delegate to the system class loader.


DefaultClassLoaderProvider

public DefaultClassLoaderProvider(ClassLoader parent)
Constructs a new ClassLoaderProvider whose getClassLoader() method will return class loaders that finally delegate to the specified class loader.

Parameters:
parent - the delegating-parent for all class loaders returned by this ClassLoaderProvider's getClassLoader() method, may be null.
Method Detail

getRepositoryRootDir

public static File getRepositoryRootDir(Class klass)
Tries to determine the directory that is or that contains the class path element from which the specified class has been loaded.

Parameters:
klass - a class loaded from the local file system
Throws:
IllegalArgumentException - if the repository root of the specified class is not a file.

getRepositoryRoot

public static URI getRepositoryRoot(Class klass)
Tries to determine the class path element from which the specified class has been loaded.

Parameters:
klass - a non-null class object
Returns:
the URI of the class path element from which klass has been loaded

isTemporary

public static boolean isTemporary(File file)
Determines whether the path of the specified file starts with the directory specified in the Java system property java.io.tmpdir.

Parameters:
file - a non-null file object
Returns:
whether the specified file resides in the java temporary directory or one of its sub-directories
See Also:
System.getProperty(java.lang.String)

getLibraries

public final URL[] getLibraries()
Returns all libraries that have been registered with this ClassLoaderProvider, so far.

Returns:
an array containing the URLs of all libraries registered with this ClassLoaderProvider.

getLibraryFiles

public final File[] getLibraryFiles()
Returns the library files that have been registered with this ClassLoaderProvider, so far.

Returns:
an array containing the library files registered with this ClassLoaderProvider.

getClassLoader

public final ClassLoader getClassLoader()
Returns a class loader that looks for class files in all libraries that have been successfully registered with this ClassLoaderProvider, so far. Subsequent calls to this method will return the same class loader or class loaders that delegate to all class loaders previously returned.

Specified by:
getClassLoader in interface ClassLoaderProvider
Overrides:
getClassLoader in class MinimalClassLoaderProvider
Returns:
a ClassLoader that looks for class files in all successfully registered libraries.

registerLibrary

public final boolean registerLibrary(File jarFile)
Requests that the specified jar file be registered, so that it is in the class path of all class loaders returned by future calls to getClassLoader().

Specified by:
registerLibrary in interface ClassLoaderProvider
Overrides:
registerLibrary in class MinimalClassLoaderProvider
Parameters:
jarFile - a jar archive with Java class files
Returns:
true if the library had not been registered before and was successfully registered with this ClassLaoderProvider.
Throws:
IllegalArgumentException - if jarFile does not exist or is not a jar file

registerLibraries

public final boolean registerLibraries(File[] jarFiles)
Requests that the specified jar files be registered, so that they are in the class path of all class loaders returned by future calls to getClassLoader().

Specified by:
registerLibraries in interface ClassLoaderProvider
Overrides:
registerLibraries in class MinimalClassLoaderProvider
Parameters:
jarFiles - an array of jar archives with Java class files
Returns:
true if at least one jarFile was newly registered

registerLibraryDirectory

public final boolean registerLibraryDirectory(File dir)
Requests that all jar files in the specified directory be registered, so that they are in the class path of all class loaders returned by future calls to getClassLoader().

Specified by:
registerLibraryDirectory in interface ClassLoaderProvider
Overrides:
registerLibraryDirectory in class MinimalClassLoaderProvider
Parameters:
dir - a directory with jar archives. The client must assure that dir exists and is a directory. dir may contain non-jar files
Returns:
true if there was at least one jar archive in dir, for wich the request was honored.
Throws:
IllegalArgumentException - if dir is not a directory

registerLibraryDirectories

public final boolean registerLibraryDirectories(File[] dirs)
Requests that all jar files in the specified directories be registered, so that they are in the class path of all class loaders returned by future calls to getClassLoader(). Non-directory files in dirs will be ignored.

Specified by:
registerLibraryDirectories in interface ClassLoaderProvider
Overrides:
registerLibraryDirectories in class MinimalClassLoaderProvider
Parameters:
dirs - an array of directories with jar archives
Returns:
true if there was at least one jar archive in dirs, for wich the request was honored.

registerDirectory

public final boolean registerDirectory(File dir)
Requests that the specified directory be registered, so that it is on the class path of all class loaders returned by future calls to getClassLoader().

Parameters:
dir - a non-null directory with Java class files
Returns:
true if the directory was newly registered

Mp3dings 
20100427