1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.webapp; |
17 | |
|
18 | |
import javax.faces.FactoryFinder; |
19 | |
import javax.servlet.ServletContext; |
20 | |
import javax.servlet.ServletContextEvent; |
21 | |
|
22 | |
import org.seasar.framework.container.servlet.S2ContainerListener; |
23 | |
import org.seasar.framework.log.Logger; |
24 | |
import org.seasar.teeda.core.ProductInfo; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 0 | public class TeedaConfigureListener extends S2ContainerListener { |
31 | |
|
32 | 0 | private static final String FACES_INIT_DONE = TeedaConfigureListener.class |
33 | |
.getName() + |
34 | |
".FACES_INIT_DONE"; |
35 | |
|
36 | 0 | private static Logger logger = Logger |
37 | |
.getLogger(TeedaConfigureListener.class); |
38 | |
|
39 | |
public void contextInitialized(ServletContextEvent event) { |
40 | 0 | super.contextInitialized(event); |
41 | 0 | printVersion(); |
42 | 0 | logger.debug("JSF initialize start"); |
43 | |
try { |
44 | 0 | initializeFaces(event.getServletContext()); |
45 | 0 | } catch (RuntimeException e) { |
46 | 0 | logger.log(e); |
47 | 0 | throw e; |
48 | 0 | } catch (Error e) { |
49 | 0 | logger.log(e); |
50 | 0 | throw e; |
51 | 0 | } |
52 | 0 | logger.debug("JSF initialize end"); |
53 | 0 | } |
54 | |
|
55 | |
public void contextDestroyed(ServletContextEvent event) { |
56 | 0 | super.contextDestroyed(event); |
57 | 0 | FactoryFinder.releaseFactories(); |
58 | 0 | } |
59 | |
|
60 | |
protected void initializeFaces(ServletContext servletContext) { |
61 | 0 | Boolean b = (Boolean) servletContext.getAttribute(FACES_INIT_DONE); |
62 | 0 | boolean isAlreadyInitialized = (b != null) ? b.booleanValue() : false; |
63 | 0 | if (!isAlreadyInitialized) { |
64 | 0 | TeedaInitializer initializer = new TeedaInitializer(); |
65 | 0 | initializer.setServletContext(servletContext); |
66 | 0 | initializer.initializeFaces(); |
67 | 0 | servletContext.setAttribute(FACES_INIT_DONE, Boolean.TRUE); |
68 | |
} |
69 | |
|
70 | 0 | } |
71 | |
|
72 | |
private void printVersion() { |
73 | 0 | logger.debug("Teeda version :" + ProductInfo.getVersion()); |
74 | 0 | } |
75 | |
} |