Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/webapp/admin/ApplicationServlet.java


1   /*
2    * Copyright 2001,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  
18  package org.apache.webapp.admin;
19  
20  import java.text.DateFormat;
21  import java.util.HashSet;
22  import java.util.Locale;
23  import java.util.ResourceBundle;
24  import javax.management.MBeanServer;
25  import javax.servlet.ServletException;
26  import javax.servlet.UnavailableException;
27  import org.apache.commons.modeler.Registry;
28  import org.apache.struts.action.ActionServlet;
29  import org.apache.struts.util.MessageResources;
30  
31  
32  /**
33   * Subclass of ActionServlet that adds caching of the supported locales in the
34   * ApplicationLocales class.
35   *
36   * @author Patrick Luby
37   * @version $Revision: 302726 $ $Date: 2004-02-27 09:59:07 -0500 (Fri, 27 Feb 2004) $
38   */
39  
40  public class ApplicationServlet extends ActionServlet {
41  
42  
43      // ----------------------------------------------------- Manifest Constants
44  
45  
46      /**
47       * The application scope key under which we store our
48       * <code>ApplicationLocales</code> instance.
49       */
50      public static final String LOCALES_KEY = "applicationLocales";
51  
52  
53      // ----------------------------------------------------- Instance Variables
54  
55  
56      /**
57       * The managed beans Registry used to look up metadata.
58       */
59      protected Registry registry = null;
60  
61  
62      /**
63       * The JMX MBeanServer we will use to look up management beans.
64       */
65      protected MBeanServer server = null;
66  
67  
68      // --------------------------------------------------------- Public Methods
69  
70  
71      /**
72       * Convenience method to make the managed beans Registry available.
73       *
74       * @exception ServletException if the Registry is not available
75       */
76      public Registry getRegistry() throws ServletException {
77  
78          if (registry == null)
79              initRegistry();
80          return (this.registry);
81  
82      }
83  
84  
85      /**
86       * Convenience method to make the JMX MBeanServer available.
87       *
88       * @exception ServletException if the MBeanServer is not available
89       */
90      public MBeanServer getServer() throws ServletException {
91  
92          if (server == null)
93              initServer();
94          return (this.server);
95  
96      }
97  
98  
99      /**
100      * Initialize this servlet.
101      *
102      * @exception ServletException if an initialization error occurs.
103      */
104     public void init() throws javax.servlet.ServletException {
105         super.init();
106         initApplicationLocales();
107     }
108 
109 
110     // ---------------------------------------------------- Protected Methods
111 
112 
113     /**
114      * Create and initialize the ApplicationLocales object, and make it
115      * available as a servlet context attribute.
116      */
117     protected void initApplicationLocales() {
118 
119         ApplicationLocales locales = new ApplicationLocales(this);
120         getServletContext().setAttribute(LOCALES_KEY, locales);
121 
122     }
123 
124 
125     /**
126      * Validate the existence of the Registry that should have been
127      * provided to us by an instance of
128      * <code>org.apache.catalina.mbean.ServerLifecycleListener</code>
129      * enabled at startup time.
130      *
131      * @exception ServletException if we cannot find the Registry
132      */
133     protected void initRegistry() throws ServletException {
134 
135         registry = Registry.getRegistry();
136         //(Registry) getServletContext().getAttribute
137         //    ("org.apache.catalina.Registry");
138         if (registry == null)
139             throw new UnavailableException("Registry is not available");
140 
141     }
142 
143 
144     /**
145      * Validate the existence of the MBeanServer that should have been
146      * provided to us by an instance of
147      * <code>org.apache.catalina.mbean.ServerLifecycleListener</code>
148      * enabled at startup time.
149      *
150      * @exception ServletException if we cannot find the MBeanServer
151      */
152     protected void initServer() throws ServletException {
153 
154         server = Registry.getRegistry().getMBeanServer();
155         //(MBeanServer) getServletContext().getAttribute
156         //    ("org.apache.catalina.MBeanServer");
157         if (server == null)
158             throw new UnavailableException("MBeanServer is not available");
159 
160     }
161 
162 
163 }