net.sourceforge.stripes.util
Class ResolverUtil

java.lang.Object
  extended by net.sourceforge.stripes.util.ResolverUtil

public class ResolverUtil
extends Object

Scans the classpath of its parent ClassLoader in order to locate all instances of a given interface. Loads the classes without invoking the static initalizers for the classes, thus ensuring there are no negative side-affects ensue. Since it scans the entire set of URLs belonging to its parent ClassLoader it can take some time - call it only as often as you need.

Author:
Tim Fennell

Constructor Summary
ResolverUtil()
           
 
Method Summary
static
<T> Set<Class<T>>
getImplementations(Class<T> anInterface)
          Locates all implementations of an interface, in all packages, in all URLs within the current ClassLoader.
static
<T> Set<Class<T>>
getImplementations(Class<T> anInterface, Set<String> locationFilters, Set<String> packageFilters)
          Locates all implementations of an interface in the classloader being used by this thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResolverUtil

public ResolverUtil()
Method Detail

getImplementations

public static <T> Set<Class<T>> getImplementations(Class<T> anInterface)
Locates all implementations of an interface, in all packages, in all URLs within the current ClassLoader. This can take a really long time, and it is usually sufficient to limit the search to specific packages.

Parameters:
anInterface - class object representing the interface whose implementations to find
Returns:
Set a set of Class objects, one for each implementation of anInterface

getImplementations

public static <T> Set<Class<T>> getImplementations(Class<T> anInterface,
                                                   Set<String> locationFilters,
                                                   Set<String> packageFilters)
Locates all implementations of an interface in the classloader being used by this thread. Does not scan the full chain of classloaders. Scans only in the URLs in the ClassLoader which match the filters provided, and within those URLs only checks classes within the packages defined by the package filters provided.

Parameters:
anInterface - class object representing the interface whose implementations to find
locationFilters - restricts the locations in the classpath that will be searched to those who contain one of the specified filters as a substring.
packageFilters - restricts the classes that will be checked to those whose name contains one of the specified filters as a substring
Returns:
Set a set of Class objects, one for each implementation of anInterface


© Copyright 2005, Stripes Development Team.