org.clapper.util.classutil
Class ClassUtil

java.lang.Object
  extended by org.clapper.util.classutil.ClassUtil

public class ClassUtil
extends java.lang.Object

Miscellaneous class-related utility methods.

Version:
$Revision: 6735 $
Author:
Copyright © 2006 Brian M. Clapper

Method Summary
static boolean fileCanContainClasses(java.io.File file)
          Determine whether a file is a jar file, zip file or directory (i.e., represents places that can be searched for classes).
static java.lang.String getShortClassName(java.lang.Class cls)
          Strip the package name from a fully-qualified class name and return just the short class name.
static java.lang.String getShortClassName(java.lang.String fullClassName)
          Strip the package name from a fully-qualified class name and return just the short class name.
static java.lang.Object instantiateClass(java.lang.String className)
          Convenience method that loads a class and attempts to instantiate it via its default constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fileCanContainClasses

public static boolean fileCanContainClasses(java.io.File file)
Determine whether a file is a jar file, zip file or directory (i.e., represents places that can be searched for classes).

Parameters:
file - the file to check
Returns:
true if the file represents a place that can be searched for classes, false if not

getShortClassName

public static java.lang.String getShortClassName(java.lang.String fullClassName)
Strip the package name from a fully-qualified class name and return just the short class name.

Parameters:
fullClassName - the full class name
Returns:
the short name

getShortClassName

public static java.lang.String getShortClassName(java.lang.Class cls)
Strip the package name from a fully-qualified class name and return just the short class name.

Parameters:
cls - the Class object whose name is to be trimmed
Returns:
the short name

instantiateClass

public static java.lang.Object instantiateClass(java.lang.String className)
                                         throws ClassUtilException
Convenience method that loads a class and attempts to instantiate it via its default constructor. This method catches all the explicit, checked exceptions that can occur and wraps them in a ClassUtilException, reducing the number of lines of code necessary to instantiate a class given its name. Note that this method only catches and wraps checked exceptions. Unchecked exceptions, such as ExceptionInInitializerError, are propagated directly to the caller.

Parameters:
className - the fully-qualified class name
Returns:
the instantiated object
Throws:
ClassUtilException - on error


Copyright © 2004-2007 Brian M. Clapper. All Rights Reserved.