]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b2ae6814c4175b70c1ea03bb4ae7ff2962c77aa2
[tmp/jakarta-migration.git] /
1 /**
2  * Copyright 2009 University of California at Berkeley
3  */
4 package org.collectionspace.services.common;
5
6 import javax.servlet.ServletContext;
7 import javax.servlet.ServletContextEvent;
8 import javax.servlet.ServletContextListener;
9
10 /**
11  * CollectionSpaceServiceContextListener is a ServletContextListener that helps initialize
12  * the services layer at deployment and undeployment times
13  */
14 public class CollectionSpaceServiceContextListener implements ServletContextListener {
15
16     @Override
17     public void contextInitialized(ServletContextEvent event) {
18         try {
19                 //
20                 // Initialize/start the Nuxeo EP server instance and create/retrieve the service workspaces
21                 //
22                 ServletContext servletContext = event.getServletContext();
23             ServiceMain svcMain = ServiceMain.getInstance(servletContext);
24             svcMain.retrieveAllWorkspaceIds();
25
26                 //
27                 // Invoke all post-initialization handlers, passing in a DataSource instance of the Nuxeo db.
28                 // Typically, these handlers modify column types and add indexes to the Nuxeo db schema.
29                 //
30                 svcMain.firePostInitHandlers();
31             
32         } catch (Exception e) {
33             e.printStackTrace();
34             //fail here
35             System.err.println("[ERROR] The CollectionSpace Services could not initialize.  Please see the log files for details.");
36             throw new RuntimeException(e);
37         }
38     }
39
40     @Override
41     public void contextDestroyed(ServletContextEvent event) {
42         ServiceMain.getInstance().release();
43     }
44 }