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