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