View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  
20  package org.eclipse.jetty.annotations;
21  
22  import java.util.List;
23  
24  import javax.servlet.annotation.HandlesTypes;
25  
26  import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
27  import org.eclipse.jetty.annotations.AnnotationParser.Value;
28  import org.eclipse.jetty.plus.annotation.ContainerInitializer;
29  import org.eclipse.jetty.util.Loader;
30  import org.eclipse.jetty.util.log.Log;
31  
32  /**
33   * ContainerInitializerAnnotationHandler
34   *
35   *  Discovers classes that contain the specified annotation, either at class or
36   *  method level. The specified annotation is derived from an @HandlesTypes on
37   *  a ServletContainerInitializer class. 
38   */
39  public class ContainerInitializerAnnotationHandler implements DiscoverableAnnotationHandler
40  {
41      ContainerInitializer _initializer;
42      Class _annotation;
43  
44      public ContainerInitializerAnnotationHandler (ContainerInitializer initializer, Class annotation)
45      {
46          _initializer = initializer;
47          _annotation = annotation;
48      }
49      
50      /** 
51       * Handle finding a class that is annotated with the annotation we were constructed with.
52       * @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handleClass(java.lang.String, int, int, java.lang.String, java.lang.String, java.lang.String[], java.lang.String, java.util.List)
53       */
54      public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotationName,
55                              List<Value> values)
56      { 
57           _initializer.addAnnotatedTypeName(className);
58      }
59  
60      public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
61                              List<Value> values)
62      {
63         _initializer.addAnnotatedTypeName(className);
64      }
65  
66      public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation,
67                               List<Value> values)
68      {
69         _initializer.addAnnotatedTypeName(className);
70      }
71  
72      @Override
73      public String getAnnotationName()
74      {
75         return _annotation.getName();
76      }
77      
78      public ContainerInitializer getContainerInitializer()
79      {
80          return _initializer;
81      }
82  
83  }