org.apache.qpid.util
Class ClasspathScanner

java.lang.Object
  extended by org.apache.qpid.util.ClasspathScanner

public class ClasspathScanner
extends Object

An ClasspathScanner scans the classpath for classes that implement an interface or extend a base class and have names that match a regular expression.

In order to test whether a class implements an interface or extends a class, the class must be loaded (unless the class files were to be scanned directly). Using this collector can cause problems when it scans the classpath, because loading classes will initialize their statics, which in turn may cause undesired side effects. For this reason, the collector should always be used with a regular expression, through which the class file names are filtered, and only those that pass this filter will be tested. For example, if you define tests in classes that end with the keyword "Test" then use the regular expression "Test$" to match this.

CRC Card
Responsibilities Collaborations
Find all classes matching type and name pattern on the classpath.

Todo:
Add logic to scan jars as well as directories.

Constructor Summary
ClasspathScanner()
           
 
Method Summary
static
<T> Collection<Class<? extends T>>
getMatches(Class<T> matchingClass, String matchingRegexp, boolean beanOnly)
          Scans the classpath and returns all classes that extend a specified class and match a specified name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClasspathScanner

public ClasspathScanner()
Method Detail

getMatches

public static <T> Collection<Class<? extends T>> getMatches(Class<T> matchingClass,
                                                            String matchingRegexp,
                                                            boolean beanOnly)
Scans the classpath and returns all classes that extend a specified class and match a specified name. There is an flag that can be used to indicate that only Java Beans will be matched (that is, only those classes that have a default constructor).

Parameters:
matchingClass - The class or interface to match.
matchingRegexp - The regular expression to match against the class name.
beanOnly - Flag to indicate that onyl classes with default constructors should be matched.
Returns:
All the classes that match this collector.


Licensed to the Apache Software Foundation