org.apache.xbean.finder
Class AnnotationFinder

java.lang.Object
  extended by org.apache.xbean.finder.AnnotationFinder
All Implemented Interfaces:
IAnnotationFinder

public class AnnotationFinder
extends Object
implements IAnnotationFinder

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.

Version:
$Rev: 1326452 $ $Date: 2012-04-15 17:24:14 -0700 (Sun, 15 Apr 2012) $

Nested Class Summary
 class AnnotationFinder.Annotatable
           
 class AnnotationFinder.AnnotationInfo
           
 class AnnotationFinder.ClassInfo
           
 class AnnotationFinder.FieldInfo
           
static class AnnotationFinder.GenericAwareInfoBuildingVisitor
           
static interface AnnotationFinder.Info
           
 class AnnotationFinder.InfoBuildingVisitor
           
 class AnnotationFinder.MethodInfo
           
 class AnnotationFinder.PackageInfo
           
 class AnnotationFinder.SubArchive
           
 
Field Summary
protected  Map<String,AnnotationFinder.ClassInfo> classInfos
           
protected  Map<String,AnnotationFinder.ClassInfo> originalInfos
           
 
Constructor Summary
AnnotationFinder(Archive archive)
           
 
Method Summary
 AnnotationFinder enableFindImplementations()
           
 AnnotationFinder enableFindSubclasses()
           
 AnnotationFinder enableMetaAnnotations()
           
 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)
           
<T> List<Class<? extends T>>
findImplementations(Class<T> clazz)
           
 List<Class<?>> findInheritedAnnotatedClasses(Class<? extends Annotation> annotation)
          Naive implementation - works extremelly slow O(n^3)
 List<Annotated<Class<?>>> findMetaAnnotatedClasses(Class<? extends Annotation> annotation)
           
 List<Annotated<Field>> findMetaAnnotatedFields(Class<? extends Annotation> annotation)
           
 List<Annotated<Method>> findMetaAnnotatedMethods(Class<? extends Annotation> annotation)
           
<T> List<Class<? extends T>>
findSubclasses(Class<T> clazz)
           
 List<String> getAnnotatedClassNames()
           
protected  List<AnnotationFinder.Info> getAnnotationInfos(String name)
           
 Archive getArchive()
           
 List<String> getClassesNotLoaded()
          Returns a list of classes that could not be loaded in last invoked findAnnotated* method.
 boolean hasMetaAnnotations()
           
protected  List<AnnotationFinder.Info> initAnnotationInfos(String name)
           
 boolean isAnnotationPresent(Class<? extends Annotation> annotation)
           
 AnnotationFinder link()
          The link() method must be called to successfully use the findSubclasses and findImplementations methods
protected  void readClassDef(Class clazz)
           
protected  void readClassDef(InputStream in)
           
protected  void readClassDef(String className)
           
 AnnotationFinder select(Class<?>... clazz)
           
 AnnotationFinder select(Iterable<String> clazz)
           
 AnnotationFinder select(String... clazz)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classInfos

protected final Map<String,AnnotationFinder.ClassInfo> classInfos

originalInfos

protected final Map<String,AnnotationFinder.ClassInfo> originalInfos
Constructor Detail

AnnotationFinder

public AnnotationFinder(Archive archive)
Method Detail

hasMetaAnnotations

public boolean hasMetaAnnotations()

getAnnotatedClassNames

public List<String> getAnnotatedClassNames()
Specified by:
getAnnotatedClassNames in interface IAnnotationFinder

getArchive

public Archive getArchive()

link

public AnnotationFinder link()
The link() method must be called to successfully use the findSubclasses and findImplementations methods

Returns:
Throws:
IOException

enableMetaAnnotations

public AnnotationFinder enableMetaAnnotations()

enableFindImplementations

public AnnotationFinder enableFindImplementations()

enableFindSubclasses

public AnnotationFinder enableFindSubclasses()

isAnnotationPresent

public boolean isAnnotationPresent(Class<? extends Annotation> annotation)
Specified by:
isAnnotationPresent in interface IAnnotationFinder

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.

Specified by:
getClassesNotLoaded in interface IAnnotationFinder
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)
Specified by:
findAnnotatedPackages in interface IAnnotationFinder

findAnnotatedClasses

public List<Class<?>> findAnnotatedClasses(Class<? extends Annotation> annotation)
Specified by:
findAnnotatedClasses in interface IAnnotationFinder

findMetaAnnotatedClasses

public List<Annotated<Class<?>>> findMetaAnnotatedClasses(Class<? extends Annotation> annotation)
Specified by:
findMetaAnnotatedClasses in interface IAnnotationFinder

findInheritedAnnotatedClasses

public List<Class<?>> findInheritedAnnotatedClasses(Class<? extends Annotation> annotation)
Naive implementation - works extremelly slow O(n^3)

Specified by:
findInheritedAnnotatedClasses in interface IAnnotationFinder
Parameters:
annotation -
Returns:
list of directly or indirectly (inherited) annotated classes

findAnnotatedMethods

public List<Method> findAnnotatedMethods(Class<? extends Annotation> annotation)
Specified by:
findAnnotatedMethods in interface IAnnotationFinder

findMetaAnnotatedMethods

public List<Annotated<Method>> findMetaAnnotatedMethods(Class<? extends Annotation> annotation)
Specified by:
findMetaAnnotatedMethods in interface IAnnotationFinder

findMetaAnnotatedFields

public List<Annotated<Field>> findMetaAnnotatedFields(Class<? extends Annotation> annotation)
Specified by:
findMetaAnnotatedFields in interface IAnnotationFinder

findAnnotatedConstructors

public List<Constructor> findAnnotatedConstructors(Class<? extends Annotation> annotation)
Specified by:
findAnnotatedConstructors in interface IAnnotationFinder

findAnnotatedFields

public List<Field> findAnnotatedFields(Class<? extends Annotation> annotation)
Specified by:
findAnnotatedFields in interface IAnnotationFinder

findClassesInPackage

public List<Class<?>> findClassesInPackage(String packageName,
                                           boolean recursive)
Specified by:
findClassesInPackage in interface IAnnotationFinder

findSubclasses

public <T> List<Class<? extends T>> findSubclasses(Class<T> clazz)
Specified by:
findSubclasses in interface IAnnotationFinder

findImplementations

public <T> List<Class<? extends T>> findImplementations(Class<T> clazz)
Specified by:
findImplementations in interface IAnnotationFinder

getAnnotationInfos

protected List<AnnotationFinder.Info> getAnnotationInfos(String name)

initAnnotationInfos

protected List<AnnotationFinder.Info> initAnnotationInfos(String name)

readClassDef

protected void readClassDef(String className)

readClassDef

protected void readClassDef(InputStream in)
                     throws IOException
Throws:
IOException

readClassDef

protected void readClassDef(Class clazz)

select

public AnnotationFinder select(Class<?>... clazz)

select

public AnnotationFinder select(String... clazz)

select

public AnnotationFinder select(Iterable<String> clazz)


Copyright © 1999-2012 The Apache Software Foundation. All Rights Reserved.