Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.util
Class ClassUtils

java.lang.Object
  extended by com.jivesoftware.util.ClassUtils

public class ClassUtils
extends java.lang.Object

A utility class to assist with loading classes or resources by name. Many application servers use custom classloaders, which will break uses of:

    Class.forName(className);
 
This utility attempts to load the class or resource using a number of different mechanisms to work around this problem.


Method Summary
static java.lang.Class forName(java.lang.String className)
          Loads the class with the specified name.
static java.net.URL getResource(java.lang.String resourceName, java.lang.Class callingClass)
          Load a given resource.
static java.io.InputStream getResourceAsStream(java.lang.String name)
          Loads the given resource as a stream.
static java.io.InputStream getResourceAsStream(java.lang.String resourceName, java.lang.Class callingClass)
          This is a convenience method to load a resource as a stream.
static java.lang.Class loadClass(java.lang.String className, java.lang.Class callingClass)
          Load a class with a given name.
static java.lang.Object newInstance(java.lang.String className)
          Creates a new instance of the class with the specified name.
static void propertiesLoaded()
           
static byte[] readStream(java.io.InputStream in, int size)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

forName

public static java.lang.Class forName(java.lang.String className)
                               throws java.lang.ClassNotFoundException
Loads the class with the specified name.

Parameters:
className - the name of the class
Returns:
the resulting Class object
Throws:
java.lang.ClassNotFoundException - if the class was not found

newInstance

public static java.lang.Object newInstance(java.lang.String className)
                                    throws java.lang.ClassNotFoundException,
                                           java.lang.IllegalAccessException,
                                           java.lang.InstantiationException
Creates a new instance of the class with the specified name.

Parameters:
className - The name of the class
Returns:
A new instance of the class with the specified name.
Throws:
java.lang.ClassNotFoundException - If class cannot be found.
java.lang.IllegalAccessException - If caller cannot access the class.
java.lang.InstantiationException - If class instantiation fails.

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String name)
Loads the given resource as a stream.

Parameters:
name - the name of the resource that exists in the classpath.
Returns:
the resource as an input stream or null if the resource was not found.

propertiesLoaded

public static void propertiesLoaded()

loadClass

public static java.lang.Class loadClass(java.lang.String className,
                                        java.lang.Class callingClass)
                                 throws java.lang.ClassNotFoundException
Load a class with a given name.

It will try to load the class in the following order:

Parameters:
className - The name of the class to load
callingClass - The Class object of the calling object
Throws:
java.lang.ClassNotFoundException - If the class cannot be found anywhere.

getResource

public static java.net.URL getResource(java.lang.String resourceName,
                                       java.lang.Class callingClass)
Load a given resource.

This method will try to load the resource using the following methods (in order):

Parameters:
resourceName - The name of the resource to load
callingClass - The Class object of the calling object

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String resourceName,
                                                      java.lang.Class callingClass)
This is a convenience method to load a resource as a stream.

The algorithm used to find the resource is given in getResource()

Parameters:
resourceName - The name of the resource to load
callingClass - The Class object of the calling object

readStream

public static byte[] readStream(java.io.InputStream in,
                                int size)
                         throws java.io.IOException
Throws:
java.io.IOException

Jive Forums Project Page

Copyright © 1999-2006 Jive Software.