|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sourceforge.jfacets.util.ResolverUtil<T>
public class ResolverUtil<T>
Utility for finding classes in the classpath. Borrowed from the Stripes Framework : http://www.stripesframework.org ! Thanks to Tim for that very useful piece of code :-)
| Nested Class Summary | |
|---|---|
static class |
ResolverUtil.AnnotatedWith
A Test that checks to see if each class is annotated with a specific annotation. |
static class |
ResolverUtil.IsA
A Test that checks to see if each class is assignable to the provided class. |
static interface |
ResolverUtil.Test
A simple interface that specifies how to test classes to determine if they are to be included in the results produced by the ResolverUtil. |
| Field Summary | |
|---|---|
private java.lang.ClassLoader |
classloader
The ClassLoader to use when looking for classes. |
private static JFacetsLogger |
log
An instance of Log to use for logging in this class. |
private java.util.Set<java.lang.Class<? extends T>> |
matches
The set of matches being accumulated. |
| Constructor Summary | |
|---|---|
ResolverUtil()
|
|
| Method Summary | |
|---|---|
protected void |
addIfMatching(ResolverUtil.Test test,
java.lang.String fqn)
Add the class designated by the fully qualified class name provided to the set of resolved classes if and only if it is approved by the Test supplied. |
void |
find(ResolverUtil.Test test,
java.lang.String packageName)
Scans for classes starting at the package provided and descending into subpackages. |
void |
findAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.String... packageNames)
Attempts to discover classes that are annotated with to the annotation. |
void |
findImplementations(java.lang.Class parent,
java.lang.String... packageNames)
Attempts to discover classes that are assignable to the type provided. |
java.util.Set<java.lang.Class<? extends T>> |
getClasses()
Provides access to the classes discovered so far. |
java.lang.ClassLoader |
getClassLoader()
Returns the classloader that will be used for scanning for classes. |
private void |
loadImplementationsInDirectory(ResolverUtil.Test test,
java.lang.String parent,
java.io.File location)
Finds matches in a physical directory on a filesystem. |
private void |
loadImplementationsInJar(ResolverUtil.Test test,
java.lang.String parent,
java.io.File jarfile)
Finds matching classes within a jar files that contains a folder structure matching the package structure. |
void |
setClassLoader(java.lang.ClassLoader classloader)
Sets an explicit ClassLoader that should be used when scanning for classes. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final JFacetsLogger log
private java.util.Set<java.lang.Class<? extends T>> matches
private java.lang.ClassLoader classloader
| Constructor Detail |
|---|
public ResolverUtil()
| Method Detail |
|---|
public java.util.Set<java.lang.Class<? extends T>> getClasses()
find() methods, this set will be empty.
public java.lang.ClassLoader getClassLoader()
public void setClassLoader(java.lang.ClassLoader classloader)
classloader - a ClassLoader to use when scanning for classes
public void findImplementations(java.lang.Class parent,
java.lang.String... packageNames)
getClasses().
parent - the class of interface to find subclasses or implementations ofpackageNames - one or more package names to scan (including subpackages) for classes
public void findAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.String... packageNames)
getClasses().
annotation - the annotation that should be present on matching classespackageNames - one or more package names to scan (including subpackages) for classes
public void find(ResolverUtil.Test test,
java.lang.String packageName)
getClasses().
test - an instance of ResolverUtil.Test that will be used to filter classespackageName - the name of the package from which to start scanning for
classes, e.g. net.sourceforge.stripes
private void loadImplementationsInDirectory(ResolverUtil.Test test,
java.lang.String parent,
java.io.File location)
test - a Test used to filter the classes that are discoveredparent - the package name up to this directory in the package hierarchy. E.g. if
/classes is in the classpath and we wish to examine files in /classes/org/apache then
the values of parent would be org/apachelocation - a File object representing a directory
private void loadImplementationsInJar(ResolverUtil.Test test,
java.lang.String parent,
java.io.File jarfile)
test - a Test used to filter the classes that are discoveredparent - the parent package under which classes must be in order to be consideredjarfile - the jar file to be examined for classes
protected void addIfMatching(ResolverUtil.Test test,
java.lang.String fqn)
test - the test used to determine if the class matchesfqn - the fully qualified name of a class
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||