org.apache.xbean.finder
Class ClassFinder

java.lang.Object
  extended by org.apache.xbean.finder.ClassFinder

public class ClassFinder
extends Object

ClassFinder searches the classpath of the specified classloader 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: 483277 $ $Date: 2006-12-06 23:53:30 +0100 (mer., 06 déc. 2006) $
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(Class... classes)
           
ClassFinder(ClassLoader classLoader)
          Creates a ClassFinder that will search the urls in the specified classloader excluding the urls in the classloader's parent.
ClassFinder(ClassLoader classLoader, boolean excludeParent)
          Creates a ClassFinder that will search the urls in the specified classloader.
ClassFinder(ClassLoader classLoader, ClassLoader exclude)
          Creates a ClassFinder that will search the urls in the specified classloader excluding the urls in the 'exclude' classloader.
ClassFinder(ClassLoader classLoader, Collection<URL> urls)
           
ClassFinder(ClassLoader classLoader, URL url)
           
ClassFinder(List<Class> classes)
           
 
Method Summary
 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> findClassesInPackage(String packageName, boolean recursive)
           
 List<String> getClassesNotLoaded()
          Returns a list of classes that could not be loaded in last invoked findAnnotated* method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFinder

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

Parameters:
classLoader -
Throws:
Exception

ClassFinder

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

Parameters:
classLoader -
excludeParent -
Throws:
Exception

ClassFinder

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

Parameters:
classLoader -
exclude -
Throws:
Exception

ClassFinder

public ClassFinder(ClassLoader classLoader,
                   URL url)

ClassFinder

public ClassFinder(ClassLoader classLoader,
                   Collection<URL> urls)

ClassFinder

public ClassFinder(Class... classes)

ClassFinder

public ClassFinder(List<Class> classes)
Method Detail

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 and the results of this method will change after each invocation of a findAnnotated* method.

This method is not thread safe.


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)


Copyright © 2005-2006 Apache Software Foundation. All Rights Reserved.