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