Class ResolverUtil<T>

Type Parameters:
T - the generic type

public class ResolverUtil<T> extends Object

ResolverUtil is used to locate classes that are available in the/a class path and meet arbitrary conditions. The two most common conditions are that a class implements/extends another class, or that is it annotated with a specific annotation. However, through the use of the ResolverUtil.Test class it is possible to search using arbitrary conditions.

A ClassLoader is used to locate all locations (directories and jar files) in the class path that contain classes within certain packages, and then to load those classes and check them. By default the ClassLoader returned by Thread.currentThread().getContextClassLoader() is used, but this can be overridden by calling setClassLoader(ClassLoader) prior to invoking any of the find() methods.

General searches are initiated by calling the find(Test, String) and supplying a package name and a Test instance. This will cause the named package and all sub-packages to be scanned for classes that meet the test. There are also utility methods for the common use cases of scanning multiple packages for extensions of particular classes, or classes annotated with a specific annotation.

The standard usage pattern for the ResolverUtil class is as follows:

 ResolverUtil<ActionBean> resolver = new ResolverUtil<ActionBean>();
 resolver.findImplementation(ActionBean.class, pkg1, pkg2);
 resolver.find(new CustomTest(), pkg1);
 resolver.find(new CustomTest(), pkg2);
 Collection<ActionBean> beans = resolver.getClasses();
Tim Fennell