public final class ApplicationListener extends Object implements javax.servlet.ServletContextListener
ServletContextListener that initializes and finalizes the
persistent storage of User and Subscription information for the Struts
Demonstration Application, using an in-memory database backed by an XML
file.
IMPLEMENTATION WARNING - If this web application is run from a WAR file, or in another environment where reading and writing of the web application resource is impossible, the initial contents will be copied to a file in the web application temporary directory provided by the container. This is for demonstration purposes only - you should NOT assume that files written here will survive a restart of your servlet container.
This class was borrowed from the Shale Mailreader. Changes were:
DEVELOPMENT NOTE - Another approach would be to instantiate the database via Spring.
| Modifier and Type | Field and Description |
|---|---|
static String |
DATABASE_KEY
Appication scope attribute key under which the in-memory version of
our database is stored.
|
static String |
PROTOCOLS_KEY
Application scope attribute key under which the valid selection
items for the protocol property is stored.
|
| Constructor and Description |
|---|
ApplicationListener() |
| Modifier and Type | Method and Description |
|---|---|
void |
contextDestroyed(javax.servlet.ServletContextEvent event)
Gracefully shut down this database, releasing any resources that
were allocated at initialization.
|
void |
contextInitialized(javax.servlet.ServletContextEvent event)
Initialize and load our initial database from persistent
storage.
|
String |
getPathname()
Return the application resource path to the database.
|
void |
setPathname(String pathname)
Set the application resource path to the database.
|
public static final String DATABASE_KEY
Appication scope attribute key under which the in-memory version of our database is stored.
public static final String PROTOCOLS_KEY
Application scope attribute key under which the valid selection items for the protocol property is stored.
public String getPathname()
Return the application resource path to the database.
public void setPathname(String pathname)
Set the application resource path to the database.
pathname - to the databasepublic void contextDestroyed(javax.servlet.ServletContextEvent event)
Gracefully shut down this database, releasing any resources that were allocated at initialization.
contextDestroyed in interface javax.servlet.ServletContextListenerevent - ServletContextEvent to processpublic void contextInitialized(javax.servlet.ServletContextEvent event)
Initialize and load our initial database from persistent storage.
contextInitialized in interface javax.servlet.ServletContextListenerevent - The context initialization eventCopyright © 2000-2013 Apache Software Foundation. All Rights Reserved.