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  package org.eclipse.jetty.annotations;
20  
21  import java.util.List;
22  
23  import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
24  import org.eclipse.jetty.annotations.AnnotationParser.Value;
25  import org.eclipse.jetty.util.log.Log;
26  import org.eclipse.jetty.util.log.Logger;
27  import org.eclipse.jetty.webapp.DiscoveredAnnotation;
28  import org.eclipse.jetty.webapp.WebAppContext;
29  
30  /**
31   * WebServletAnnotationHandler
32   *
33   * Process a WebServlet annotation on a class.
34   * 
35   */
36  public class WebServletAnnotationHandler extends AbstractDiscoverableAnnotationHandler
37  {
38      private static final Logger LOG = Log.getLogger(WebServletAnnotationHandler.class);
39      
40      public WebServletAnnotationHandler (WebAppContext context)
41      {
42          super(context);
43      }
44      
45      public WebServletAnnotationHandler (WebAppContext context, List<DiscoveredAnnotation> list)
46      {
47          super(context, list);
48      }
49      
50      
51      /** 
52       * Handle discovering a WebServlet annotation.
53       * 
54       *  
55       * @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)
56       */
57      public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotationName,
58                              List<Value> values)
59      {
60          if (!"javax.servlet.annotation.WebServlet".equals(annotationName))
61              return;    
62         
63          WebServletAnnotation annotation = new WebServletAnnotation (_context, className, _resource);
64          addAnnotation(annotation);
65      }
66  
67      public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
68                              List<Value> values)
69      {
70          LOG.warn ("@WebServlet annotation not supported for fields");
71      }
72  
73      public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation,
74                               List<Value> values)
75      {
76          LOG.warn ("@WebServlet annotation not supported for methods");
77      }
78  
79  
80      @Override
81      public String getAnnotationName()
82      {
83          return "javax.servlet.annotation.WebServlet";
84      }    
85  }