org.qi4j.bootstrap
Class ClassScanner

java.lang.Object
  extended by org.qi4j.bootstrap.ClassScanner

public class ClassScanner
extends java.lang.Object

Scan classpath for classes that matches given criteria. Useful for automated assemblies with lots of similar classes.


Constructor Summary
ClassScanner()
           
 
Method Summary
static java.lang.Iterable<java.lang.Class<?>> findClasses(java.lang.Class<?> seedClass)
          Get all classes from the same package of the given class, and recursively in all subpackages.
static Specification<java.lang.Class<?>> matches(java.lang.String regex)
          Useful specification for filtering classes based on a regular expression matching the class names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassScanner

public ClassScanner()
Method Detail

findClasses

public static java.lang.Iterable<java.lang.Class<?>> findClasses(java.lang.Class<?> seedClass)
Get all classes from the same package of the given class, and recursively in all subpackages.

This only works if the seed class is loaded from a file: URL. Jar files are possible as well. Abstract classes are not included in the results. For further filtering use e.g. Iterables.filter.

Parameters:
seedClass - starting point for classpath scanning
Returns:
iterable of all concrete classes in the same package as the seedclass, and also all classes in subpackages.

matches

public static Specification<java.lang.Class<?>> matches(java.lang.String regex)
Useful specification for filtering classes based on a regular expression matching the class names.

Example: matches(".*Model") -> match only class names that end with Model

Example:

Parameters:
regex -
Returns:
regex class name specification