org.apache.velocity.util
Class ClassUtils

java.lang.Object
  extended byorg.apache.velocity.util.ClassUtils

public class ClassUtils
extends java.lang.Object

Simple utility functions for manipulating classes and resources from the classloader.

Version:
$Id: ClassUtils.java 151549 2005-02-06 06:19:43Z wglass $
Author:
Will Glass-Husain

Constructor Summary
private ClassUtils()
          Utility class; cannot be instantiated.
 
Method Summary
static java.lang.Object getNewInstance(java.lang.String classname)
          Return a new instance of the given class.
static java.io.InputStream getResourceAsStream(java.lang.Class claz, java.lang.String name)
          Finds a resource with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtils

private ClassUtils()
Utility class; cannot be instantiated.

Method Detail

getNewInstance

public static java.lang.Object getNewInstance(java.lang.String classname)
                                       throws java.lang.ClassNotFoundException,
                                              java.lang.IllegalAccessException,
                                              java.lang.InstantiationException
Return a new instance of the given class. Checks the ThreadContext classloader first, then uses the System classloader. Should replace all calls to Class.forName( claz ).newInstance() (which only calls the System class loader) when the class might be in a different classloader (e.g. in a webapp).

Parameters:
classname - the name of the class to instantiate
Returns:
Throws:
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.Class claz,
                                                      java.lang.String name)
Finds a resource with the given name. Checks the Thread Context classloader, then uses the System classloader. Should replace all calls to Class.getResourceAsString when the resource might come from a different classloader. (e.g. a webapp).

Parameters:
claz - Class to use when getting the System classloader (used if no Thread Context classloader available or fails to get resource).
name - name of the resource
Returns:


Copyright ? 2002 Apache Software Foundation. All Rights Reserved.