1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.plus.annotation;
20
21 import java.util.HashSet;
22 import java.util.Set;
23
24 import javax.servlet.ServletContainerInitializer;
25
26 import org.eclipse.jetty.util.Loader;
27 import org.eclipse.jetty.webapp.WebAppContext;
28
29 public class ContainerInitializer
30 {
31 protected ServletContainerInitializer _target;
32 protected Class[] _interestedTypes;
33 protected Set<String> _applicableTypeNames;
34 protected Set<String> _annotatedTypeNames;
35
36
37 public void setTarget (ServletContainerInitializer target)
38 {
39 _target = target;
40 }
41
42 public ServletContainerInitializer getTarget ()
43 {
44 return _target;
45 }
46
47 public Class[] getInterestedTypes ()
48 {
49 return _interestedTypes;
50 }
51
52 public void setInterestedTypes (Class[] interestedTypes)
53 {
54 _interestedTypes = interestedTypes;
55 }
56
57
58
59
60
61
62 public void addAnnotatedTypeName (String className)
63 {
64 if (_annotatedTypeNames == null)
65 _annotatedTypeNames = new HashSet<String>();
66 _annotatedTypeNames.add(className);
67 }
68
69 public Set<String> getAnnotatedTypeNames ()
70 {
71 return _annotatedTypeNames;
72 }
73
74 public void addApplicableTypeName (String className)
75 {
76 if (_applicableTypeNames == null)
77 _applicableTypeNames = new HashSet<String>();
78 _applicableTypeNames.add(className);
79 }
80
81 public Set<String> getApplicableTypeNames ()
82 {
83 return _applicableTypeNames;
84 }
85
86
87 public void callStartup(WebAppContext context)
88 throws Exception
89 {
90 if (_target != null)
91 {
92 Set<Class<?>> classes = new HashSet<Class<?>>();
93
94 ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
95 Thread.currentThread().setContextClassLoader(context.getClassLoader());
96
97 try
98 {
99 if (_applicableTypeNames != null)
100 {
101 for (String s : _applicableTypeNames)
102 classes.add(Loader.loadClass(context.getClass(), s));
103 }
104
105 _target.onStartup(classes, context.getServletContext());
106 }
107 finally
108 {
109 Thread.currentThread().setContextClassLoader(oldLoader);
110 }
111 }
112 }
113 }