Class AnnotationAcceptingListener
- java.lang.Object
-
- org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener
-
- All Implemented Interfaces:
ResourceProcessor
public final class AnnotationAcceptingListener extends java.lang.Object implements ResourceProcessor
A scanner listener that processes Java class files (resource names ending in ".class") annotated with one or more of a set of declared annotations.Java classes of a Java class file are processed, using ASM, to ascertain if those classes are annotated with one or more of the set of declared annotations.
Such an annotated Java class of a Java class file is loaded if the class is public or is an inner class that is static and public.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
AnnotationAcceptingListener.AnnotatedClassVisitor
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.lang.String>
annotations
private java.util.Set<java.lang.Class<?>>
classes
private java.lang.ClassLoader
classloader
private AnnotationAcceptingListener.AnnotatedClassVisitor
classVisitor
-
Constructor Summary
Constructors Constructor Description AnnotationAcceptingListener(java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
Create a scanner listener to check for annotated Java classes in Java class files.AnnotationAcceptingListener(java.lang.ClassLoader classloader, java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
Create a scanner listener to check for annotated Java classes in Java class files.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(java.lang.String name)
Accept a scanned resource.java.util.Set<java.lang.Class<?>>
getAnnotatedClasses()
Get the set of annotated classes.private java.util.Set<java.lang.String>
getAnnotationSet(java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
static AnnotationAcceptingListener
newJaxrsResourceAndProviderListener()
Create a scanning listener to check for Java classes in Java class files annotated withPath
orProvider
.static AnnotationAcceptingListener
newJaxrsResourceAndProviderListener(java.lang.ClassLoader classLoader)
Create a scanning listener to check for Java classes in Java class files annotated withPath
orProvider
.void
process(java.lang.String name, java.io.InputStream in)
Process a scanned resource.
-
-
-
Field Detail
-
classloader
private final java.lang.ClassLoader classloader
-
classes
private final java.util.Set<java.lang.Class<?>> classes
-
annotations
private final java.util.Set<java.lang.String> annotations
-
classVisitor
private final AnnotationAcceptingListener.AnnotatedClassVisitor classVisitor
-
-
Constructor Detail
-
AnnotationAcceptingListener
public AnnotationAcceptingListener(java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
Create a scanner listener to check for annotated Java classes in Java class files.- Parameters:
annotations
- the set of annotation classes to check on Java class files.
-
AnnotationAcceptingListener
public AnnotationAcceptingListener(java.lang.ClassLoader classloader, java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
Create a scanner listener to check for annotated Java classes in Java class files.- Parameters:
classloader
- the class loader to use to load Java classes that are annotated with any one of the annotations.annotations
- the set of annotation classes to check on Java class files.
-
-
Method Detail
-
newJaxrsResourceAndProviderListener
public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener()
Create a scanning listener to check for Java classes in Java class files annotated withPath
orProvider
.- Returns:
- new instance of
AnnotationAcceptingListener
which looks forPath
orProvider
annotated classes.
-
newJaxrsResourceAndProviderListener
public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener(java.lang.ClassLoader classLoader)
Create a scanning listener to check for Java classes in Java class files annotated withPath
orProvider
.- Parameters:
classLoader
- the class loader to use to load Java classes that are annotated with any one of the annotations.- Returns:
- new instance of
AnnotationAcceptingListener
which looks forPath
orProvider
annotated classes.
-
getAnnotatedClasses
public java.util.Set<java.lang.Class<?>> getAnnotatedClasses()
Get the set of annotated classes.- Returns:
- the set of annotated classes.
-
getAnnotationSet
private java.util.Set<java.lang.String> getAnnotationSet(java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
-
accept
public boolean accept(java.lang.String name)
Description copied from interface:ResourceProcessor
Accept a scanned resource.- Specified by:
accept
in interfaceResourceProcessor
- Parameters:
name
- the resource name.- Returns:
- true if the resource is accepted for processing, otherwise false.
-
process
public void process(java.lang.String name, java.io.InputStream in) throws java.io.IOException
Description copied from interface:ResourceProcessor
Process a scanned resource.This method will be invoked after the listener has accepted the resource.
- Specified by:
process
in interfaceResourceProcessor
- Parameters:
name
- the resource name.in
- the input stream of the resource- Throws:
java.io.IOException
- if an error occurs when processing the resource.
-
-