org.apache.xbean.finder
Class AnnotationFinder

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

public class AnnotationFinder
extends java.lang.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: 1309601 $ $Date: 2012-04-04 14:20:07 -0700 (Wed, 04 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  java.util.Map<java.lang.String,AnnotationFinder.ClassInfo> classInfos
           
protected  java.util.Map<java.lang.String,AnnotationFinder.ClassInfo> originalInfos
           
 
Constructor Summary
AnnotationFinder(Archive archive)
           
 
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<?>> findClassesInPackage(java.lang.String packageName, boolean recursive)
           
<T> java.util.List<java.lang.Class<? extends T>>
findImplementations(java.lang.Class<T> clazz)
           
 java.util.List<java.lang.Class<?>> findInheritedAnnotatedClasses(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
          Naive implementation - works extremelly slow O(n^3)
 java.util.List<Annotated<java.lang.Class<?>>> findMetaAnnotatedClasses(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
           
 java.util.List<Annotated<java.lang.reflect.Field>> findMetaAnnotatedFields(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
           
 java.util.List<Annotated<java.lang.reflect.Method>> findMetaAnnotatedMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
           
<T> java.util.List<java.lang.Class<? extends T>>
findSubclasses(java.lang.Class<T> clazz)
           
 java.util.List<java.lang.String> getAnnotatedClassNames()
           
protected  java.util.List<AnnotationFinder.Info> getAnnotationInfos(java.lang.String name)
           
 Archive getArchive()
           
 java.util.List<java.lang.String> getClassesNotLoaded()
          Returns a list of classes that could not be loaded in last invoked findAnnotated* method.
protected  java.util.List<AnnotationFinder.Info> initAnnotationInfos(java.lang.String name)
           
 boolean isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
           
 AnnotationFinder link()
          The link() method must be called to successfully use the findSubclasses and findImplementations methods
protected  void readClassDef(java.lang.Class clazz)
           
protected  void readClassDef(java.io.InputStream in)
           
protected  void readClassDef(java.lang.String className)
           
 AnnotationFinder select(java.lang.Class<?>... clazz)
           
 AnnotationFinder select(java.lang.Iterable<java.lang.String> clazz)
           
 AnnotationFinder select(java.lang.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 java.util.Map<java.lang.String,AnnotationFinder.ClassInfo> classInfos

originalInfos

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

AnnotationFinder

public AnnotationFinder(Archive archive)
Method Detail

getAnnotatedClassNames

public java.util.List<java.lang.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:
java.io.IOException

isAnnotationPresent

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

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.

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

findAnnotatedClasses

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

findMetaAnnotatedClasses

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

findInheritedAnnotatedClasses

public java.util.List<java.lang.Class<?>> findInheritedAnnotatedClasses(java.lang.Class<? extends java.lang.annotation.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 java.util.List<java.lang.reflect.Method> findAnnotatedMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Specified by:
findAnnotatedMethods in interface IAnnotationFinder

findMetaAnnotatedMethods

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

findMetaAnnotatedFields

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

findAnnotatedConstructors

public java.util.List<java.lang.reflect.Constructor> findAnnotatedConstructors(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Specified by:
findAnnotatedConstructors in interface IAnnotationFinder

findAnnotatedFields

public java.util.List<java.lang.reflect.Field> findAnnotatedFields(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Specified by:
findAnnotatedFields in interface IAnnotationFinder

findClassesInPackage

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

findSubclasses

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

findImplementations

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

getAnnotationInfos

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

initAnnotationInfos

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

readClassDef

protected void readClassDef(java.lang.String className)

readClassDef

protected void readClassDef(java.io.InputStream in)
                     throws java.io.IOException
Throws:
java.io.IOException

readClassDef

protected void readClassDef(java.lang.Class clazz)

select

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

select

public AnnotationFinder select(java.lang.String... clazz)

select

public AnnotationFinder select(java.lang.Iterable<java.lang.String> clazz)


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