2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.shale.clay.config;
22
23 import javax.servlet.ServletContextEvent;
24 import javax.servlet.ServletContextListener;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.shale.clay.config.beans.ComponentConfigBean;
29 import org.apache.shale.clay.config.beans.ConfigBean;
30 import org.apache.shale.clay.config.beans.ConfigBeanFactory;
31 import org.apache.shale.clay.config.beans.TemplateComponentConfigBean;
32 import org.apache.shale.clay.config.beans.TemplateConfigBean;
33 import org.apache.shale.util.Messages;
34
35 /***
36 * <p>This context listener is responsible for loading the clay
37 * configuration files on application startup. It is registered
38 * in our tag library descriptor, so no further registration is
39 * required. The configuration files are defined by a context
40 * initialization parameter named <code>Globals.CLAY_CONFIG_FILES</code>.
41 * </p>
42 *
43 * <p>After the data is loaded, it will be accessible using the factory class
44 * {@link org.apache.shale.clay.config.beans.ConfigBeanFactory}</p>
45 */
46
47 public class ClayConfigureListener implements ServletContextListener {
48
49 /***
50 * <p>Static instanc reference to the common logger utility class.</p>
51 */
52 private static Log log;
53 static {
54 log = LogFactory.getLog(ClayConfigureListener.class);
55 }
56
57 /***
58 * <p>Message resources for this class.</p>
59 */
60 private static Messages messages = new Messages("org.apache.shale.clay.Bundle",
61 ClayConfigureListener.class.getClassLoader());
62
63 /***
64 * <p>Loads the configuration files on startup into an instance of
65 * {@link org.apache.shale.clay.config.beans.ComponentConfigBean}.
66 * and registers it with the factory {@link ConfigBeanFactory}. The HTML template style of
67 * {@link org.apache.shale.clay.component.Clay} configuration bean
68 * {@link org.apache.shale.clay.config.beans.TemplateConfigBean} and the XML template style of configuration
69 * bean is {@link org.apache.shale.clay.config.beans.TemplateComponentConfigBean}. The are all registered
70 * with the factory {@link ConfigBeanFactory}. All configuration bean pools implement the
71 * {@link org.apache.shale.clay.config.beans.ConfigBean} interface.
72 * </p>
73 * @param event servlet context
74 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
75 */
76 public void contextInitialized(ServletContextEvent event) {
77 if (log.isInfoEnabled()) {
78 log.info(messages.getMessage("config.load.begin"));
79 }
80
81 try {
82
83
84 ConfigBean config = new ComponentConfigBean();
85 config.init(event.getServletContext());
86 ConfigBeanFactory.register(config);
87
88
89 config = new TemplateConfigBean();
90 config.init(event.getServletContext());
91 ConfigBeanFactory.register(config);
92
93
94 config = new TemplateComponentConfigBean();
95 config.init(event.getServletContext());
96 ConfigBeanFactory.register(config);
97
98
99
100 } catch (RuntimeException e) {
101 log.error(messages.getMessage("config.load.error"), e);
102 throw e;
103 }
104
105 if (log.isInfoEnabled()) {
106 log.info(messages.getMessage("config.load.done"));
107 }
108
109 }
110
111 /***
112 * <p>Tear down the factories and clean house.</p>
113 * @param event servlet context
114 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
115 */
116 public void contextDestroyed(ServletContextEvent event) {
117
118 if (log.isInfoEnabled()) {
119 log.debug(messages.getMessage("config.destroy"));
120 }
121
122 ConfigBeanFactory.destroy();
123 LogFactory.release(Thread.currentThread().getContextClassLoader());
124
125 }
126
127 }