Hilbert II - Version 0.03.08

org.qedeq.kernel.utility
Class ResourceLoaderUtility

java.lang.Object
  extended byorg.qedeq.kernel.utility.ResourceLoaderUtility

public final class ResourceLoaderUtility
extends Object

Utility methods for accessing classes and resources using an appropriate class loader. Adapted from org.apache.myfaces.trinidad.util.ClassLoaderUtils.

Version:
$Revision: 1.3 $

Method Summary
static ClassLoader getContextClassLoader()
          Dynamically accesses the current context class loader.
static InputStream getResourceAsStream(String name)
          Locates the stream resource with the specified name.
static InputStream getResourceAsStream(String name, ClassLoader callerClassLoader)
          Locates the resource stream with the specified name.
static URL getResourceUrl(File startDirectory, String resourceDirectoryName, String resourceName)
          Get resource URL.
static URL getResourceUrl(String name)
          Locates the resource with the specified name.
static URL getResourceUrl(String name, ClassLoader callerClassLoader)
          Locates the resource with the specified name.
static Class loadClass(String name)
          Loads the class with the specified name.
static Class loadClass(String name, ClassLoader callerClassLoader)
          Loads the class with the specified name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadClass

public static Class loadClass(String name)
                       throws ClassNotFoundException
Loads the class with the specified name. For Java 2 callers, the current thread's context class loader is preferred, falling back on the system class loader of the caller when the current thread's context is not set, or the caller is pre Java 2.

Parameters:
name - Name of class to load.
Returns:
The resulting Class object
Throws:
ClassNotFoundException - Class was not found.

getResourceUrl

public static URL getResourceUrl(String name)
Locates the resource with the specified name. For Java 2 callers, the current thread's context class loader is preferred, falling back on the system class loader of the caller when the current thread's context is not set, or the caller is pre Java 2.

Parameters:
name - Resource name.
Returns:
Rsulting URL object. Maybe null.

getResourceAsStream

public static InputStream getResourceAsStream(String name)
Locates the stream resource with the specified name. For Java 2 callers, the current thread's context class loader is preferred, falling back on the system class loader of the caller when the current thread's context is not set, or the caller is pre Java 2.

Parameters:
name - the name of the resource
Returns:
the resulting InputStream object

loadClass

public static Class loadClass(String name,
                              ClassLoader callerClassLoader)
                       throws ClassNotFoundException
Loads the class with the specified name. For Java 2 callers, the current thread's context class loader is preferred, falling back on the class loader of the caller when the current thread's context is not set, or the caller is pre Java 2. If the callerClassLoader is null, then fall back on the system class loader.

Parameters:
name - the name of the class
callerClassLoader - the calling class loader context
Returns:
the resulting Class object
Throws:
ClassNotFoundException - if the class was not found

getResourceUrl

public static URL getResourceUrl(String name,
                                 ClassLoader callerClassLoader)
Locates the resource with the specified name. For Java 2 callers, the current thread's context class loader is preferred, falling back on the class loader of the caller when the current thread's context is not set, or the caller is pre Java 2. If the callerClassLoader is null, then fall back on the system class loader.

Parameters:
name - the name of the resource
callerClassLoader - the calling class loader context
Returns:
the resulting URL object

getResourceAsStream

public static InputStream getResourceAsStream(String name,
                                              ClassLoader callerClassLoader)
Locates the resource stream with the specified name. For Java 2 callers, the current thread's context class loader is preferred, falling back on the class loader of the caller when the current thread's context is not set, or the caller is pre Java 2. If the callerClassLoader is null, then fall back on the system class loader.

Parameters:
name - the name of the resource
callerClassLoader - the calling class loader context
Returns:
the resulting InputStream object

getContextClassLoader

public static ClassLoader getContextClassLoader()
Dynamically accesses the current context class loader. Returns null if there is no per-thread context class loader. Also if the JRE is below 1.2 or something else went wrong the method returns null.

Returns:
ClassLoader.

getResourceUrl

public static URL getResourceUrl(File startDirectory,
                                 String resourceDirectoryName,
                                 String resourceName)
Get resource URL. The resource is loaded from the file

Parameters:
startDirectory - Start looking from this directory.
resourceDirectoryName - Within this directory (relative to startDirectory).
resourceName - Look for this resource file.
Returns:
Resource URL.

Hilbert II - Version 0.03.08

©left GNU General Public Licence
All Rights Reserved.