View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2014 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 org.eclipse.jetty.servlet.ServletContextHandler.Decorator;
22  import org.eclipse.jetty.webapp.WebAppContext;
23  
24  /**
25   * AnnotationDecorator
26   *
27   *
28   */
29  public class AnnotationDecorator implements Decorator
30  {
31      protected AnnotationIntrospector _introspector = new AnnotationIntrospector();
32  
33      /**
34       * @param context
35       */
36      public AnnotationDecorator(WebAppContext context)
37      {
38         registerHandlers(context);
39      }
40      
41      public void registerHandlers (WebAppContext context)
42      {
43          _introspector.registerHandler(new ResourceAnnotationHandler(context));
44          _introspector.registerHandler(new ResourcesAnnotationHandler(context));
45          _introspector.registerHandler(new RunAsAnnotationHandler(context));
46          _introspector.registerHandler(new PostConstructAnnotationHandler(context));
47          _introspector.registerHandler(new PreDestroyAnnotationHandler(context));
48          _introspector.registerHandler(new DeclareRolesAnnotationHandler(context));
49          _introspector.registerHandler(new MultiPartConfigAnnotationHandler(context));
50          _introspector.registerHandler(new ServletSecurityAnnotationHandler(context));
51      }
52  
53      /**
54       * Look for annotations that can be discovered with introspection:
55       * <ul>
56       * <li> Resource
57       * <li> Resources
58       * <li> PostConstruct
59       * <li> PreDestroy
60       * <li> ServletSecurity?
61       * </ul>
62       * @param o
63       */
64      protected void introspect (Object o)
65      {
66          _introspector.introspect(o.getClass());
67      }
68  
69      @Override
70      public Object decorate(Object o)
71      {
72         introspect(o);
73         return o;
74      }
75  
76      @Override
77      public void destroy(Object o)
78      {
79          
80      }
81  }