org.apache.cocoon.util
Class ClassUtils

java.lang.Object
  extended by org.apache.cocoon.util.ClassUtils

public class ClassUtils
extends Object

A collection of class management utility methods.

Version:
CVS $Id: ClassUtils.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Ricardo Rocha, Stefano Mazzocchi

Constructor Summary
ClassUtils()
           
 
Method Summary
static ClassLoader getClassLoader()
          Return the context classloader.
static URL getResource(String resource)
          Return a resource URL.
static boolean implementsInterface(Class class1, Class iface)
          Deprecated. Will be removed 2 versions after 2.1.5
static boolean implementsInterface(String className, String iface)
          Deprecated. Will be removed 2 versions after 2.1.5
static long lastModified(Class aClass)
          Deprecated. Will be removed 2 versions after 2.1.5
static Class loadClass(String className)
          Load a class given its name.
static Object newInstance(String className)
          Create a new instance given a class name
static String which(Class aClass)
          Deprecated. Will be removed 2 versions after 2.1.5
 
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 Object newInstance(String className)
                          throws Exception
Create a new instance given a class name

Parameters:
className - A class name
Returns:
A new instance
Throws:
Exception - If an instantiation error occurs

loadClass

public static Class loadClass(String className)
                       throws ClassNotFoundException
Load a class given its name. BL: We wan't to use a known ClassLoader--hopefully the hierarchy is set correctly.

Parameters:
className - A class name
Returns:
The class pointed to by className
Throws:
ClassNotFoundException - If a loading error occurs

getResource

public static URL getResource(String resource)
                       throws 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:
MalformedURLException - If a loading error occurs

getClassLoader

public static 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(String className,
                                          String iface)
                                   throws Exception
Deprecated. Will be removed 2 versions after 2.1.5

Tests if a class implements a given interface

Returns:
true if class implements given interface.
Throws:
Exception

implementsInterface

public static boolean implementsInterface(Class class1,
                                          Class iface)
Deprecated. Will be removed 2 versions after 2.1.5

Tests if a class implements a given interface

Returns:
true if class implements given interface.

lastModified

public static long lastModified(Class aClass)
                         throws IOException,
                                IllegalArgumentException
Deprecated. Will be removed 2 versions after 2.1.5

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:
IOException - IOError
IllegalArgumentException - The class was not loaded from a file or directory

which

public static String which(Class aClass)
Deprecated. Will be removed 2 versions after 2.1.5

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-2010 The Apache Software Foundation. All Rights Reserved.