]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
d9f857f5a36adfc1a0f894c813b3071fe079271b
[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             
25             svcMain.retrieveAllWorkspaceIds();
26             
27                 //
28                 // Invoke all post-initialization handlers, passing in a DataSource instance of the Nuxeo db.
29                 // Typically, these handlers modify column types and add indexes to the Nuxeo db schema.
30                 //
31                 svcMain.firePostInitHandlers();
32                         
33         } catch (Throwable e) {
34             e.printStackTrace();
35             //fail here
36             System.err.println("[ERROR] The CollectionSpace Services could not initialize.  Please see the log files for details.");
37             throw new RuntimeException(e);
38         }
39     }
40
41     @Override
42     public void contextDestroyed(ServletContextEvent event) {
43         //ServiceMain.getInstance().release();
44     }
45 }