org.apache.cocoon.util
Class ClassUtils

java.lang.Object
  |
  +--org.apache.cocoon.util.ClassUtils

public class ClassUtils
extends java.lang.Object

A collection of class management utility methods.

Version:
CVS $Id: ClassUtils.java,v 1.5 2002/03/08 04:15:02 vgritsenko Exp $
Author:
Ricardo Rocha, Stefano Mazzocchi

Constructor Summary
ClassUtils()
           
 
Method Summary
static java.lang.ClassLoader getClassLoader()
          Return the context classloader.
static java.net.URL getResource(java.lang.String resource)
          Return a resource URL.
static boolean implementsInterface(java.lang.Class class1, java.lang.Class iface)
          Tests if a class implements a given interface
static boolean implementsInterface(java.lang.String className, java.lang.String iface)
          Tests if a class implements a given interface
static long lastModified(java.lang.Class aClass)
          Determine the last modification date for this class file or its enclosing library
static java.lang.Class loadClass(java.lang.String className)
          Load a class given its name.
static java.lang.Object newInstance(java.lang.String className)
          Create a new instance given a class name
static java.lang.String which(java.lang.Class aClass)
          Gets the absolute pathname of the class file containing the specified class name, as prescribed by the current classpath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtils

public ClassUtils()
Method Detail

newInstance

public static java.lang.Object newInstance(java.lang.String className)
                                    throws java.lang.Exception
Create a new instance given a class name
Parameters:
className - A class name
Returns:
A new instance
Throws:
java.lang.Exception - If an instantiation error occurs

loadClass

public static java.lang.Class loadClass(java.lang.String className)
                                 throws java.lang.ClassNotFoundException
Load a class given its name. BL: We wan't to use a known ClassLoader--hopefully the heirarchy is set correctly.
Parameters:
className - A class name
Returns:
The class pointed to by className
Throws:
java.lang.ClassNotFoundException - If a loading error occurs

getResource

public static java.net.URL getResource(java.lang.String resource)
                                throws java.net.MalformedURLException
Return a resource URL. BL: if this is command line operation, the classloading issues are more sane. During servlet execution, we explicitly set the ClassLoader.
Returns:
The context classloader.
Throws:
java.net.MalformedURLException - If a loading error occurs

getClassLoader

public static java.lang.ClassLoader getClassLoader()
Return the context classloader. BL: if this is command line operation, the classloading issues are more sane. During servlet execution, we explicitly set the ClassLoader.
Returns:
The context classloader.

implementsInterface

public static boolean implementsInterface(java.lang.String className,
                                          java.lang.String iface)
                                   throws java.lang.Exception
Tests if a class implements a given interface
Returns:
true if class implements given interface.

implementsInterface

public static boolean implementsInterface(java.lang.Class class1,
                                          java.lang.Class iface)
Tests if a class implements a given interface
Returns:
true if class implements given interface.

lastModified

public static long lastModified(java.lang.Class aClass)
                         throws java.io.IOException,
                                java.lang.IllegalArgumentException
Determine the last modification date for this class file or its enclosing library
Parameters:
aClass - A class whose last modification date is queried
Returns:
The time the given class was last modified
Throws:
java.io.IOException - IOError
java.lang.IllegalArgumentException - The class was not loaded from a file or directory

which

public static java.lang.String which(java.lang.Class aClass)
Gets the absolute pathname of the class file containing the specified class name, as prescribed by the current classpath.
Parameters:
aClass - Name of the class.


Copyright � 1999-2002 Apache Software Foundation. All Rights Reserved.