1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.annotations;
15
16 import org.eclipse.jetty.util.log.Log;
17 import org.eclipse.jetty.webapp.WebAppContext;
18
19
20
21
22
23
24 public class AnnotationConfiguration extends AbstractConfiguration
25 {
26 public static final String CLASS_INHERITANCE_MAP = "org.eclipse.jetty.classInheritanceMap";
27
28 public void preConfigure(final WebAppContext context) throws Exception
29 {
30 }
31
32
33 public void configure(WebAppContext context) throws Exception
34 {
35 Boolean b = (Boolean)context.getAttribute(METADATA_COMPLETE);
36 boolean metadataComplete = (b != null && b.booleanValue());
37 Integer i = (Integer)context.getAttribute(WEBXML_VERSION);
38 int webxmlVersion = (i == null? 0 : i.intValue());
39
40 if (metadataComplete)
41 {
42
43 if (Log.isDebugEnabled()) Log.debug("Metadata-complete==true, not processing annotations for context "+context);
44 return;
45 }
46 else
47 {
48
49
50 if (Log.isDebugEnabled()) Log.debug("parsing annotations");
51
52 AnnotationParser parser = new AnnotationParser();
53
54 parser.registerAnnotationHandler("javax.annotation.Resource", new ResourceAnnotationHandler (context));
55 parser.registerAnnotationHandler("javax.annotation.Resources", new ResourcesAnnotationHandler (context));
56 parser.registerAnnotationHandler("javax.annotation.PostConstruct", new PostConstructAnnotationHandler(context));
57 parser.registerAnnotationHandler("javax.annotation.PreDestroy", new PreDestroyAnnotationHandler(context));
58 parser.registerAnnotationHandler("javax.annotation.security.RunAs", new RunAsAnnotationHandler(context));
59
60 ClassInheritanceHandler classHandler = new ClassInheritanceHandler();
61 parser.registerClassHandler(classHandler);
62
63
64 if (webxmlVersion >= 30 || context.isConfigurationDiscovered())
65 {
66 if (Log.isDebugEnabled()) Log.debug("Scanning all classes for annotations: webxmlVersion="+webxmlVersion+" configurationDiscovered="+context.isConfigurationDiscovered());
67 parseContainerPath(context, parser);
68 parseWebInfLib (context, parser);
69 parseWebInfClasses(context, parser);
70 }
71 else
72 {
73 if (Log.isDebugEnabled()) Log.debug("Scanning only classes in web.xml for annotations");
74 parse25Classes(context, parser);
75 }
76
77
78 context.setAttribute(CLASS_INHERITANCE_MAP, classHandler.getMap());
79 }
80 }
81
82
83
84 public void deconfigure(WebAppContext context) throws Exception
85 {
86
87 }
88
89
90
91
92 public void postConfigure(WebAppContext context) throws Exception
93 {
94 context.setAttribute(CLASS_INHERITANCE_MAP, null);
95 }
96
97 }