org.glassfish.jersey.server.internal.scanning
Class AnnotationAcceptingListener

java.lang.Object
  extended by org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener
All Implemented Interfaces:
ResourceProcessor

public final class AnnotationAcceptingListener
extends 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.

Author:
Paul Sandoz

Constructor Summary
AnnotationAcceptingListener(Class<? extends Annotation>... annotations)
          Create a scanner listener to check for annotated Java classes in Java class files.
AnnotationAcceptingListener(ClassLoader classloader, Class<? extends Annotation>... annotations)
          Create a scanner listener to check for annotated Java classes in Java class files.
 
Method Summary
 boolean accept(String name)
          Accept a scanned resource.
 Set<Class<?>> getAnnotatedClasses()
          Get the set of annotated classes.
static AnnotationAcceptingListener newJaxrsResourceAndProviderListener()
          Create a scanning listener to check for Java classes in Java class files annotated with Path or Provider.
static AnnotationAcceptingListener newJaxrsResourceAndProviderListener(ClassLoader classLoader)
          Create a scanning listener to check for Java classes in Java class files annotated with Path or Provider.
 void process(String name, InputStream in)
          Process a scanned resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationAcceptingListener

public AnnotationAcceptingListener(Class<? extends 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(ClassLoader classloader,
                                   Class<? extends 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 with Path or Provider.

Returns:
new instance of AnnotationAcceptingListener which looks for Path or Provider annotated classes.

newJaxrsResourceAndProviderListener

public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener(ClassLoader classLoader)
Create a scanning listener to check for Java classes in Java class files annotated with Path or Provider.

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 for Path or Provider annotated classes.

getAnnotatedClasses

public Set<Class<?>> getAnnotatedClasses()
Get the set of annotated classes.

Returns:
the set of annotated classes.

accept

public boolean accept(String name)
Description copied from interface: ResourceProcessor
Accept a scanned resource.

Specified by:
accept in interface ResourceProcessor
Parameters:
name - the resource name.
Returns:
true if the resource is accepted for processing, otherwise false.

process

public void process(String name,
                    InputStream in)
             throws 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 interface ResourceProcessor
Parameters:
name - the resource name.
in - the input stream of the resource
Throws:
IOException - if an error occurs when processing the resource.


Copyright © 2007-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.