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