com.opensymphony.xwork2.util.finder
Class ClassFinder

java.lang.Object
  extended by com.opensymphony.xwork2.util.finder.ClassFinder

public class ClassFinder
extends Object

ClassFinder searches the classpath of the specified ClassLoaderInterface for packages, classes, constructors, methods, or fields with specific annotations. For security reasons ASM is used to find the annotations. Classes are not loaded unless they match the requirements of a called findAnnotated* method. Once loaded, these classes are cached. The getClassesNotLoaded() method can be used immediately after any find* method to get a list of classes which matched the find requirements (i.e. contained the annotation), but were unable to be loaded.

Version:
$Rev$ $Date$
Author:
David Blevins

Nested Class Summary
 class ClassFinder.Annotatable
           
 class ClassFinder.AnnotationInfo
           
 class ClassFinder.ClassInfo
           
 class ClassFinder.FieldInfo
           
static interface ClassFinder.Info
           
 class ClassFinder.InfoBuildingVisitor
           
 class ClassFinder.MethodInfo
           
 class ClassFinder.PackageInfo
           
 
Field Summary
private  Map<String,List<ClassFinder.Info>> annotated
           
private  List<String> classesNotLoaded
           
private  Map<String,ClassFinder.ClassInfo> classInfos
           
private  ClassLoaderInterface classLoaderInterface
           
private  boolean extractBaseInterfaces
           
private static Logger LOG
           
 
Constructor Summary
ClassFinder(Class... classes)
           
ClassFinder(ClassLoaderInterface classLoader)
          Creates a ClassFinder that will search the urls in the specified ClassLoaderInterface excluding the urls in the ClassLoaderInterface's parent.
ClassFinder(ClassLoaderInterface classLoader, boolean excludeParent)
          Creates a ClassFinder that will search the urls in the specified ClassLoaderInterface.
ClassFinder(ClassLoaderInterface classLoader, ClassLoaderInterface exclude)
          Creates a ClassFinder that will search the urls in the specified classloader excluding the urls in the 'exclude' ClassLoaderInterface.
ClassFinder(ClassLoaderInterface classLoaderInterface, Collection<URL> urls)
           
ClassFinder(ClassLoaderInterface classLoaderInterface, Collection<URL> urls, boolean extractBaseInterfaces)
           
ClassFinder(ClassLoaderInterface classLoaderInterface, Collection<URL> urls, boolean extractBaseInterfaces, Set<String> protocols)
           
ClassFinder(ClassLoaderInterface classLoader, String... dirNames)
           
ClassFinder(ClassLoaderInterface classLoader, URL url)
           
ClassFinder(List<Class> classes)
           
 
Method Summary
private  List<String> file(URL location)
           
 List<Class> findAnnotatedClasses(Class<? extends Annotation> annotation)
           
 List<Constructor> findAnnotatedConstructors(Class<? extends Annotation> annotation)
           
 List<Field> findAnnotatedFields(Class<? extends Annotation> annotation)
           
 List<Method> findAnnotatedMethods(Class<? extends Annotation> annotation)
           
 List<Package> findAnnotatedPackages(Class<? extends Annotation> annotation)
           
 List<Class> findClasses()
           
 List<Class> findClasses(Test<ClassFinder.ClassInfo> test)
           
 List<Class> findClassesInPackage(String packageName, boolean recursive)
           
private  List<ClassFinder.Info> getAnnotationInfos(String name)
           
 List<String> getClassesNotLoaded()
          Returns a list of classes that could not be loaded in last invoked findAnnotated* method.
private static Collection<URL> getUrls(ClassLoaderInterface classLoaderInterface, boolean excludeParent)
           
private static Collection<URL> getUrls(ClassLoaderInterface classLoader, ClassLoaderInterface excludeParent)
           
private static List<URL> getURLs(ClassLoaderInterface classLoader, String[] dirNames)
           
 boolean isAnnotationPresent(Class<? extends Annotation> annotation)
           
private  List<String> jar(JarInputStream jarStream)
           
private  List<String> jar(URL location)
           
private  void readClassDef(String className)
           
private  void scanDir(File dir, List<String> classNames, String packageName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Logger LOG

annotated

private final Map<String,List<ClassFinder.Info>> annotated

classInfos

private final Map<String,ClassFinder.ClassInfo> classInfos

classesNotLoaded

private final List<String> classesNotLoaded

extractBaseInterfaces

private boolean extractBaseInterfaces

classLoaderInterface

private ClassLoaderInterface classLoaderInterface
Constructor Detail

ClassFinder

public ClassFinder(ClassLoaderInterface classLoader)
            throws Exception
Creates a ClassFinder that will search the urls in the specified ClassLoaderInterface excluding the urls in the ClassLoaderInterface's parent. To include the parent ClassLoaderInterface, use: new ClassFinder(ClassLoaderInterface, false); To exclude the parent's parent, use: new ClassFinder(ClassLoaderInterface, ClassLoaderInterface.getParent().getParent());

Parameters:
classLoader - source of classes to scan
Throws:
Exception - if something goes wrong

ClassFinder

public ClassFinder(ClassLoaderInterface classLoader,
                   boolean excludeParent)
            throws Exception
Creates a ClassFinder that will search the urls in the specified ClassLoaderInterface.

Parameters:
classLoader - source of classes to scan
excludeParent - Allegedly excludes classes from parent ClassLoaderInterface, whatever that might mean
Throws:
Exception - if something goes wrong.

ClassFinder

public ClassFinder(ClassLoaderInterface classLoader,
                   ClassLoaderInterface exclude)
            throws Exception
Creates a ClassFinder that will search the urls in the specified classloader excluding the urls in the 'exclude' ClassLoaderInterface.

Parameters:
classLoader - source of classes to scan
exclude - source of classes to exclude from scanning
Throws:
Exception - if something goes wrong

ClassFinder

public ClassFinder(ClassLoaderInterface classLoader,
                   URL url)

ClassFinder

public ClassFinder(ClassLoaderInterface classLoader,
                   String... dirNames)

ClassFinder

public ClassFinder(ClassLoaderInterface classLoaderInterface,
                   Collection<URL> urls)

ClassFinder

public ClassFinder(ClassLoaderInterface classLoaderInterface,
                   Collection<URL> urls,
                   boolean extractBaseInterfaces)

ClassFinder

public ClassFinder(ClassLoaderInterface classLoaderInterface,
                   Collection<URL> urls,
                   boolean extractBaseInterfaces,
                   Set<String> protocols)

ClassFinder

public ClassFinder(Class... classes)

ClassFinder

public ClassFinder(List<Class> classes)
Method Detail

isAnnotationPresent

public boolean isAnnotationPresent(Class<? extends Annotation> annotation)

getClassesNotLoaded

public List<String> getClassesNotLoaded()
Returns a list of classes that could not be loaded in last invoked findAnnotated* method.

The list will only contain entries of classes whose byte code matched the requirements of last invoked find* method, but were unable to be loaded and included in the results.

The list returned is unmodifiable. Once obtained, the returned list will be a live view of the results from the last findAnnotated* method call.

This method is not thread safe.

Returns:
an unmodifiable live view of classes that could not be loaded in previous findAnnotated* call.

findAnnotatedPackages

public List<Package> findAnnotatedPackages(Class<? extends Annotation> annotation)

findAnnotatedClasses

public List<Class> findAnnotatedClasses(Class<? extends Annotation> annotation)

findAnnotatedMethods

public List<Method> findAnnotatedMethods(Class<? extends Annotation> annotation)

findAnnotatedConstructors

public List<Constructor> findAnnotatedConstructors(Class<? extends Annotation> annotation)

findAnnotatedFields

public List<Field> findAnnotatedFields(Class<? extends Annotation> annotation)

findClassesInPackage

public List<Class> findClassesInPackage(String packageName,
                                        boolean recursive)

findClasses

public List<Class> findClasses(Test<ClassFinder.ClassInfo> test)

findClasses

public List<Class> findClasses()

getURLs

private static List<URL> getURLs(ClassLoaderInterface classLoader,
                                 String[] dirNames)

getUrls

private static Collection<URL> getUrls(ClassLoaderInterface classLoaderInterface,
                                       boolean excludeParent)
                                throws IOException
Throws:
IOException

getUrls

private static Collection<URL> getUrls(ClassLoaderInterface classLoader,
                                       ClassLoaderInterface excludeParent)
                                throws IOException
Throws:
IOException

file

private List<String> file(URL location)

scanDir

private void scanDir(File dir,
                     List<String> classNames,
                     String packageName)

jar

private List<String> jar(URL location)
                  throws IOException
Throws:
IOException

jar

private List<String> jar(JarInputStream jarStream)
                  throws IOException
Throws:
IOException

getAnnotationInfos

private List<ClassFinder.Info> getAnnotationInfos(String name)

readClassDef

private void readClassDef(String className)


Copyright © 2000-2009 Apache Software Foundation. All Rights Reserved.