org.apache.myfaces.trinidad.util
Class ClassLoaderUtils

java.lang.Object
  extended by org.apache.myfaces.trinidad.util.ClassLoaderUtils

public final class ClassLoaderUtils
extends Object

Utility methods for accessing classes and resources using an appropriate class loader.

Version:
$Name: $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/util/ClassLoaderUtils.java#0 $) $Date: 10-nov-2005.18:49:08 $

Method Summary
static ClassLoader getContextClassLoader()
          Dynamically accesses the current context class loader.
static URL getResource(String name)
          Locates the resource with the specified name.
static URL getResource(String name, ClassLoader callerClassLoader)
          Locates the resource with the specified name.
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
<T> List<T>
getServices(String service)
          Instantiate a service from a file in /META-INF/services.
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 - the name of the class
Returns:
the resulting Class object
Throws:
ClassNotFoundException - if the class was not found

getResource

public static URL getResource(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 - the name of the resource
Returns:
the resulting URL object

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

getResource

public static URL getResource(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.


getServices

public static <T> List<T> getServices(String service)
Instantiate a service from a file in /META-INF/services.

The following is an excerpt from the JAR File specification: A service provider identifies itself by placing a provider-configuration file in the resource directory META-INF/services. The file's name should consist of the fully-qualified name of the abstract service class. The file should contain a newline-separated list of unique concrete provider-class names. Space and tab characters, as well as blank lines, are ignored. The comment character is '#' (0x23); on each line all characters following the first comment character are ignored. The file must be encoded in UTF-8.

Parameters:
service - the classname of the abstract service class. eg: javax.servlet.Filter


Copyright © 2001-2012 The Apache Software Foundation. All Rights Reserved.