1 //
2 // ========================================================================
3 // Copyright (c) 1995-2015 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
23 import org.eclipse.jetty.annotations.AnnotationParser.AbstractHandler;
24 import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo;
25 import org.eclipse.jetty.annotations.AnnotationParser.FieldInfo;
26 import org.eclipse.jetty.annotations.AnnotationParser.MethodInfo;
27 import org.eclipse.jetty.plus.annotation.ContainerInitializer;
28
29 /**
30 * ContainerInitializerAnnotationHandler
31 *
32 * Discovers classes that contain the specified annotation, either at class or
33 * method level. The specified annotation is derived from an @HandlesTypes on
34 * a ServletContainerInitializer class.
35 */
36 /**
37 * @author janb
38 *
39 */
40 public class ContainerInitializerAnnotationHandler extends AbstractHandler
41 {
42 final ContainerInitializer _initializer;
43 final Class _annotation;
44
45 public ContainerInitializerAnnotationHandler (ContainerInitializer initializer, Class annotation)
46 {
47 _initializer = initializer;
48 _annotation = annotation;
49 }
50
51 /**
52 * Handle finding a class that is annotated with the annotation we were constructed with.
53 *
54 * @see org.eclipse.jetty.annotations.AnnotationParser.Handler#handle(ClassInfo, String)
55 */
56 public void handle(ClassInfo info, String annotationName)
57 {
58 if (annotationName == null || !_annotation.getName().equals(annotationName))
59 return;
60
61 _initializer.addAnnotatedTypeName(info.getClassName());
62 }
63
64 /**
65 * Handle finding a field that is annotated with the annotation we were constructed with.
66 *
67 * @see org.eclipse.jetty.annotations.AnnotationParser.Handler#handle(FieldInfo, String)
68 */
69 public void handle(FieldInfo info, String annotationName)
70 {
71 if (annotationName == null || !_annotation.getName().equals(annotationName))
72 return;
73 _initializer.addAnnotatedTypeName(info.getClassInfo().getClassName());
74 }
75
76 /**
77 * Handle finding a method that is annotated with the annotation we were constructed with.
78 *
79 * @see org.eclipse.jetty.annotations.AnnotationParser.Handler#handle(MethodInfo, String)
80 */
81 public void handle(MethodInfo info, String annotationName)
82 {
83 if (annotationName == null || !_annotation.getName().equals(annotationName))
84 return;
85 _initializer.addAnnotatedTypeName(info.getClassInfo().getClassName());
86 }
87
88
89 public ContainerInitializer getContainerInitializer()
90 {
91 return _initializer;
92 }
93 }