1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mortbay.jetty.annotations;
17
18 import java.util.ArrayList;
19 import java.util.EventListener;
20 import java.util.Iterator;
21 import java.util.List;
22
23 import org.mortbay.jetty.servlet.FilterHolder;
24 import org.mortbay.jetty.servlet.FilterMapping;
25 import org.mortbay.jetty.servlet.ServletHolder;
26 import org.mortbay.jetty.servlet.ServletMapping;
27 import org.mortbay.log.Log;
28 import org.mortbay.util.LazyList;
29
30
31
32
33
34
35 public class Configuration extends org.mortbay.jetty.plus.webapp.Configuration
36 {
37 public static final String __web_inf_pattern = "org.mortbay.jetty.webapp.WebInfIncludeAnnotationJarPattern";
38 public static final String __container_pattern = "org.mortbay.jetty.webapp.ContainerIncludeAnnotationJarPattern";
39
40
41
42 public Configuration () throws ClassNotFoundException
43 {
44 super();
45 }
46
47
48
49
50 public void parseAnnotations() throws Exception
51 {
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 AnnotationFinder finder = new AnnotationFinder();
72
73
74 Log.debug("Scanning system jars");
75 finder.find(getWebAppContext().getClassLoader().getParent(), true, getWebAppContext().getInitParameter(__container_pattern), false,
76 new ClassNameResolver ()
77 {
78 public boolean isExcluded (String name)
79 {
80 if (getWebAppContext().isSystemClass(name)) return false;
81 if (getWebAppContext().isServerClass(name)) return true;
82 return false;
83 }
84
85 public boolean shouldOverride (String name)
86 {
87
88 if (getWebAppContext().isParentLoaderPriority())
89 return true;
90 return false;
91 }
92 });
93
94 Log.debug("Scanning WEB-INF/lib jars");
95
96 finder.find (getWebAppContext().getClassLoader(), false, getWebAppContext().getInitParameter(__web_inf_pattern), true,
97 new ClassNameResolver()
98 {
99 public boolean isExcluded (String name)
100 {
101 if (getWebAppContext().isSystemClass(name)) return true;
102 if (getWebAppContext().isServerClass(name)) return false;
103 return false;
104 }
105
106 public boolean shouldOverride (String name)
107 {
108
109 if (getWebAppContext().isParentLoaderPriority())
110 return false;
111 return true;
112 }
113 });
114
115 Log.debug("Scanning classes in WEB-INF/classes");
116 finder.find(_context.getWebInf().addPath("classes/"),
117 new ClassNameResolver()
118 {
119 public boolean isExcluded (String name)
120 {
121 if (getWebAppContext().isSystemClass(name)) return true;
122 if (getWebAppContext().isServerClass(name)) return false;
123 return false;
124 }
125
126 public boolean shouldOverride (String name)
127 {
128
129 if (getWebAppContext().isParentLoaderPriority())
130 return false;
131 return true;
132 }
133 });
134
135 AnnotationProcessor processor = new AnnotationProcessor(getWebAppContext(), finder, _runAsCollection, _injections, _callbacks,
136 LazyList.getList(_servlets), LazyList.getList(_filters), LazyList.getList(_listeners),
137 LazyList.getList(_servletMappings), LazyList.getList(_filterMappings));
138 processor.process();
139 _servlets = processor.getServlets();
140 _filters = processor.getFilters();
141 _servletMappings = processor.getServletMappings();
142 _filterMappings = processor.getFilterMappings();
143 _listeners = processor.getListeners();
144 _servletHandler.setFilters((FilterHolder[])LazyList.toArray(_filters,FilterHolder.class));
145 _servletHandler.setFilterMappings((FilterMapping[])LazyList.toArray(_filterMappings,FilterMapping.class));
146 _servletHandler.setServlets((ServletHolder[])LazyList.toArray(_servlets,ServletHolder.class));
147 _servletHandler.setServletMappings((ServletMapping[])LazyList.toArray(_servletMappings,ServletMapping.class));
148 getWebAppContext().setEventListeners((EventListener[])LazyList.toArray(_listeners,EventListener.class));
149 }
150 }