com.opensymphony.xwork2.util.finder
Class ClassFinder

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

public class ClassFinder
extends java.lang.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: 894090 $ $Date: 2009-12-27 19:18:29 +0100 (Sun, 27 Dec 2009) $
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
           
 
Constructor Summary
ClassFinder(java.lang.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, java.util.Collection<java.net.URL> urls)
           
ClassFinder(ClassLoaderInterface classLoaderInterface, java.util.Collection<java.net.URL> urls, boolean extractBaseInterfaces)
           
ClassFinder(ClassLoaderInterface classLoaderInterface, java.util.Collection<java.net.URL> urls, boolean extractBaseInterfaces, java.util.Set<java.lang.String> protocols)
           
ClassFinder(ClassLoaderInterface classLoaderInterface, java.util.Collection<java.net.URL> urls, boolean extractBaseInterfaces, java.util.Set<java.lang.String> protocols, Test<java.lang.String> classNameFilter)
           
ClassFinder(ClassLoaderInterface classLoader, java.lang.String... dirNames)
           
ClassFinder(ClassLoaderInterface classLoader, java.net.URL url)
           
ClassFinder(java.util.List<java.lang.Class> classes)
           
 
Method Summary
 java.util.List<java.lang.Class> findAnnotatedClasses(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
           
 java.util.List<java.lang.reflect.Constructor> findAnnotatedConstructors(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
           
 java.util.List<java.lang.reflect.Field> findAnnotatedFields(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
           
 java.util.List<java.lang.reflect.Method> findAnnotatedMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
           
 java.util.List<java.lang.Package> findAnnotatedPackages(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
           
 java.util.List<java.lang.Class> findClasses()
           
 java.util.List<java.lang.Class> findClasses(Test<ClassFinder.ClassInfo> test)
           
 java.util.List<java.lang.Class> findClassesInPackage(java.lang.String packageName, boolean recursive)
           
 java.util.List<java.lang.String> getClassesNotLoaded()
          Returns a list of classes that could not be loaded in last invoked findAnnotated* method.
 boolean isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFinder

public ClassFinder(ClassLoaderInterface classLoader)
            throws java.lang.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:
java.lang.Exception - if something goes wrong

ClassFinder

public ClassFinder(ClassLoaderInterface classLoader,
                   boolean excludeParent)
            throws java.lang.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:
java.lang.Exception - if something goes wrong.

ClassFinder

public ClassFinder(ClassLoaderInterface classLoader,
                   ClassLoaderInterface exclude)
            throws java.lang.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:
java.lang.Exception - if something goes wrong

ClassFinder

public ClassFinder(ClassLoaderInterface classLoader,
                   java.net.URL url)

ClassFinder

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

ClassFinder

public ClassFinder(ClassLoaderInterface classLoaderInterface,
                   java.util.Collection<java.net.URL> urls)

ClassFinder

public ClassFinder(ClassLoaderInterface classLoaderInterface,
                   java.util.Collection<java.net.URL> urls,
                   boolean extractBaseInterfaces)

ClassFinder

public ClassFinder(ClassLoaderInterface classLoaderInterface,
                   java.util.Collection<java.net.URL> urls,
                   boolean extractBaseInterfaces,
                   java.util.Set<java.lang.String> protocols)

ClassFinder

public ClassFinder(ClassLoaderInterface classLoaderInterface,
                   java.util.Collection<java.net.URL> urls,
                   boolean extractBaseInterfaces,
                   java.util.Set<java.lang.String> protocols,
                   Test<java.lang.String> classNameFilter)

ClassFinder

public ClassFinder(java.lang.Class... classes)

ClassFinder

public ClassFinder(java.util.List<java.lang.Class> classes)
Method Detail

isAnnotationPresent

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

getClassesNotLoaded

public java.util.List<java.lang.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 java.util.List<java.lang.Package> findAnnotatedPackages(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)

findAnnotatedClasses

public java.util.List<java.lang.Class> findAnnotatedClasses(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)

findAnnotatedMethods

public java.util.List<java.lang.reflect.Method> findAnnotatedMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)

findAnnotatedConstructors

public java.util.List<java.lang.reflect.Constructor> findAnnotatedConstructors(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)

findAnnotatedFields

public java.util.List<java.lang.reflect.Field> findAnnotatedFields(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)

findClassesInPackage

public java.util.List<java.lang.Class> findClassesInPackage(java.lang.String packageName,
                                                            boolean recursive)

findClasses

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

findClasses

public java.util.List<java.lang.Class> findClasses()


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