1 |
package dk.daoas.daoadresseservice;
|
2 |
|
3 |
import javax.servlet.ServletContext;
|
4 |
import javax.servlet.ServletContextEvent;
|
5 |
import javax.servlet.ServletContextListener;
|
6 |
import javax.servlet.ServletRegistration;
|
7 |
import javax.servlet.annotation.WebListener;
|
8 |
|
9 |
import dk.daoas.daoadresseservice.admin.ServiceConfig;
|
10 |
import dk.thoerup.webconfig.ConfigServlet;
|
11 |
import dk.thoerup.webconfig.ContextConfigLoader;
|
12 |
|
13 |
/**
|
14 |
* Application Lifecycle Listener implementation class ContextListener
|
15 |
*
|
16 |
*/
|
17 |
@WebListener
|
18 |
public class ContextListener implements ServletContextListener {
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
public ContextListener() {
|
24 |
// TODO Auto-generated constructor stub
|
25 |
}
|
26 |
|
27 |
public void contextDestroyed(ServletContextEvent ctxtEvt) {
|
28 |
// TODO Auto-generated method stub
|
29 |
}
|
30 |
|
31 |
@Override
|
32 |
public void contextInitialized(ServletContextEvent ctxtEvt) {
|
33 |
System.out.println("Starting DAO Context");
|
34 |
|
35 |
ServletContext ctxt = ctxtEvt.getServletContext();
|
36 |
|
37 |
initDataLoader(ctxt);
|
38 |
initConfig(ctxt);
|
39 |
|
40 |
System.out.println("DAO Context done");
|
41 |
}
|
42 |
|
43 |
private void initDataLoader(ServletContext ctxt) {
|
44 |
DataLoader load = new DataLoader(ctxt);
|
45 |
ctxt.setAttribute("dataloader", load);
|
46 |
load.doLoad();
|
47 |
}
|
48 |
|
49 |
|
50 |
private void initConfig(ServletContext ctxt) {
|
51 |
ServiceConfig conf = new ServiceConfig();
|
52 |
|
53 |
new ContextConfigLoader(ctxt).loadConfig(conf);
|
54 |
|
55 |
ctxt.setAttribute("config", conf);
|
56 |
|
57 |
// /////////////////////////////////////
|
58 |
ConfigServlet servlet = new ConfigServlet();
|
59 |
servlet.setConfigObject( conf );
|
60 |
ServletRegistration.Dynamic dynconf = ctxt.addServlet("webconfig", servlet );
|
61 |
dynconf.addMapping("/ConfigServlet");
|
62 |
|
63 |
|
64 |
|
65 |
}
|
66 |
|
67 |
|
68 |
}
|