com.norconex.commons.lang
Class ClassFinder

java.lang.Object
  extended by com.norconex.commons.lang.ClassFinder

public final class ClassFinder
extends Object

Utility class for finding names of classes implementing an interface or class in directories or JAR files. In order to find if a class is potential candidate, it is "loaded" first, but into a temporary class loader. Still, if it is important to you that classes do not get loaded, you can use other approaches, such as byte-code scanning. See Apache ClassScan sandbox project for code that does that.

Author:
Pascal Essiembre

Method Summary
static List<String> findImplementors(File file, Class<?> superClass)
          Finds the names of all classes implementing the super class.
static List<String> findImplementors(List<File> files, Class<?> superClass)
          Finds the names of all classes implementing the super class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

findImplementors

public static List<String> findImplementors(List<File> files,
                                            Class<?> superClass)
Finds the names of all classes implementing the super class. This method is null-safe. If no classes are found, an empty list will be returned.

Parameters:
files - directories and JARs to scan for classes
superClass - the class from which to find implementors
Returns:
list of class names

findImplementors

public static List<String> findImplementors(File file,
                                            Class<?> superClass)
Finds the names of all classes implementing the super class. This method is null-safe. If no classes are found, an empty list will be returned. If the file is null or does not exists, or if it is not a JAR or directory, an empty string list will be returned.

Parameters:
file - directory or JAR to scan for classes
superClass - the class from which to find implementors
Returns:
list of class names


Copyright © 2008-2013 Norconex Inc.. All Rights Reserved.