KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > web > YanLoaderServlet


1 package jfun.yan.web;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.ServletException JavaDoc;
6 import javax.servlet.http.HttpServlet JavaDoc;
7 import javax.servlet.http.HttpServletRequest JavaDoc;
8 import javax.servlet.http.HttpServletResponse JavaDoc;
9
10 /**
11  * Major portion of this class is copied from the Spring framework.
12  * <p>
13  * Bootstrap servlet to start up Yan's root container.
14  * Simply delegates to YanLoader.
15  *
16  * <p>This servlet should have a lower <code>load-on-startup</code> value
17  * in <code>web.xml</code> than any servlets that access the root web
18  * application context.
19  *
20  * <p><i>Note that this class has been deprecated for containers implementing
21  * Servlet API 2.4 or higher, in favor of YanLoaderListener.</i><br>
22  * According to Servlet 2.4, listeners must be initialized before load-on-startup
23  * servlets. Many Servlet 2.3 containers already enforce this behavior. If you
24  * use such a container, this servlet can be replaced with YanLoaderListener.
25  * Else or if working with a Servlet 2.2 container, stick with this servlet.
26  *
27  * <p>Servlet 2.3 containers known to work with bootstrap listeners are:
28  * <ul>
29  * <li>Apache Tomcat 4.x+
30  * <li>Jetty 4.x+
31  * <li>Resin 2.1.8+
32  * <li>Orion 2.0.2+
33  * <li>BEA WebLogic 8.1 SP3
34  * </ul>
35  * For working with any of them, YanLoaderListener is recommended.
36  *
37  * <p>Servlet 2.3 containers known <i>not</i> to work with bootstrap listeners are:
38  * <ul>
39  * <li>BEA WebLogic up to 8.1 SP2
40  * <li>IBM WebSphere 5.x
41  * <li>Oracle OC4J 9.0.3
42  * </ul>
43  * If you happen to work with such a server, this servlet has to be used.
44  *
45  * <p>So unfortunately, the only context initialization option that is compatible
46  * with <i>all</i> Servlet 2.3 containers is this servlet.
47  *
48  * <p>Note that a startup failure of this servlet will not stop the rest of the
49  * web application from starting, in contrast to a listener failure. This can
50  * lead to peculiar side effects if other servlets get started that depend on
51  * initialization of the root web application context.
52  *
53  * @author Ben Yu.
54  * @see YanLoader
55  * @see YanLoaderListener
56  */

57 public class YanLoaderServlet extends HttpServlet JavaDoc {
58
59   private YanLoader YanLoader;
60
61
62   /**
63    * Initialize the root web application context.
64    */

65   public void init() throws ServletException JavaDoc {
66     this.YanLoader = createYanLoader();
67     this.YanLoader.initContainer(getServletContext());
68   }
69
70   /**
71    * Create the YanLoader to use. Can be overridden in subclasses.
72    * @return the new YanLoader
73    */

74   protected YanLoader createYanLoader() {
75     return new YanLoader();
76   }
77
78   /**
79    * Return the YanLoader used by this servlet.
80    */

81   public YanLoader getYanLoader() {
82     return YanLoader;
83   }
84
85
86   /**
87    * Close the root web application context.
88    */

89   public void destroy() {
90     if (this.YanLoader != null) {
91       this.YanLoader.destroy(getServletContext());
92     }
93   }
94
95
96   /**
97    * This should never even be called since no mapping to this servlet should
98    * ever be created in web.xml. That's why a correctly invoked Servlet 2.3
99    * listener is much more appropriate for initialization work ;-)
100    */

101   public void service(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc {
102     getServletContext().log(
103         "Attempt to call service method on YanLoaderServlet as [" +
104         request.getRequestURI() + "] was ignored");
105     response.sendError(HttpServletResponse.SC_BAD_REQUEST);
106   }
107
108
109   public String JavaDoc getServletInfo() {
110     return "YanLoaderServlet for Servlet API 2.2/2.3 " +
111         "(deprecated in favor of YanLoaderListener for Servlet API 2.4)";
112   }
113
114 }
115
Popular Tags