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