1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.annotations;
20
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Set;
24
25 import org.eclipse.jetty.annotations.AnnotationConfiguration;
26 import org.eclipse.jetty.plus.annotation.ContainerInitializer;
27 import org.eclipse.jetty.util.MultiMap;
28 import org.eclipse.jetty.util.component.AbstractLifeCycle;
29 import org.eclipse.jetty.util.log.Log;
30 import org.eclipse.jetty.util.log.Logger;
31 import org.eclipse.jetty.webapp.WebAppContext;
32
33
34
35
36
37
38 public class ServletContainerInitializerListener extends AbstractLifeCycle
39 {
40 private static final Logger LOG = Log.getLogger(ServletContainerInitializerListener.class);
41 protected WebAppContext _context = null;
42
43
44 public void setWebAppContext (WebAppContext context)
45 {
46 _context = context;
47 }
48
49
50
51
52
53
54 public void doStart()
55 {
56 List<ContainerInitializer> initializers = (List<ContainerInitializer>)_context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS);
57 MultiMap classMap = (MultiMap)_context.getAttribute(AnnotationConfiguration.CLASS_INHERITANCE_MAP);
58
59 if (initializers != null)
60 {
61 for (ContainerInitializer i : initializers)
62 {
63
64
65
66 if (i.getAnnotatedTypeNames() != null)
67 {
68 Set<String> annotatedClassNames = new HashSet<String>(i.getAnnotatedTypeNames());
69 for (String name : annotatedClassNames)
70 {
71
72 i.addApplicableTypeName(name);
73
74 if (classMap != null)
75 {
76 List<String> implementsOrExtends = (List<String>)classMap.getValues(name);
77 if (implementsOrExtends != null && !implementsOrExtends.isEmpty())
78 addInheritedTypes(classMap, i, implementsOrExtends);
79 }
80 }
81 }
82
83
84
85
86 if (i.getInterestedTypes() != null)
87 {
88 for (Class c : i.getInterestedTypes())
89 {
90 if (!c.isAnnotation())
91 {
92
93
94 if (classMap != null)
95 {
96 List<String> implementsOrExtends = (List<String>)classMap.getValues(c.getName());
97 if (implementsOrExtends != null && !implementsOrExtends.isEmpty())
98 addInheritedTypes(classMap, i, implementsOrExtends);
99 }
100 }
101 }
102 }
103
104
105 try
106 {
107 i.callStartup(_context);
108 }
109 catch (Exception e)
110 {
111 LOG.warn(e);
112 throw new RuntimeException(e);
113 }
114 }
115 }
116
117 }
118
119
120 void addInheritedTypes (MultiMap classMap, ContainerInitializer initializer, List<String> applicableTypes)
121 {
122 for (String s : applicableTypes)
123 {
124
125 initializer.addApplicableTypeName(s);
126
127
128 List<String> implementsOrExtends = (List<String>)classMap.getValues(s);
129 if (implementsOrExtends != null && !implementsOrExtends.isEmpty())
130 addInheritedTypes (classMap, initializer, implementsOrExtends);
131 }
132 }
133
134
135
136
137
138
139
140 public void doStop()
141 {
142
143 }
144
145 }