package com.sptci.echo2demo;

import java.util.logging.Logger;
import nextapp.echo2.app.ApplicationInstance;
import nextapp.echo2.webcontainer.WebContainerServlet;

import javax.jdo.PersistenceManager;
import com.sptci.jdo.PersistenceManagerFactory;

/**
 * The <code>WebContainerServlet</code> implementation required for
 * the <b>Echo2</b> event-driven web development framework.
 *
 * <p>Copyright 2006 Sans Pareil Technologies, Inc.</p>
 * @author Rakesh Vidyadharan 2006-01-21
 * @version $Id: Servlet.java,v 1.3 2006/02/14 22:39:17 rakesh Exp $
 */
public class Servlet extends WebContainerServlet
{
  /**
   * The mandatory method that is to be implemented.  Returns a new
   * instance of {@link Application}.
   *
   * @return ApplicationInstance The appropriate implementation of
   *   <code>ApplicationInstance</code> for this web application.
   */
  public ApplicationInstance newApplicationInstance()
  {
    return new Application();
  }

  /**
   * Close the <code>JDO PersistenceManager</code> upon web application
   * de-installation.
   */
  public void destroy()
  {
    Logger.getLogger( "com.sptci.echo2demo.Servlet" ).info( 
        "Closing persistence manager." );
    try
    {
      PersistenceManager pm = 
        PersistenceManagerFactory.getPersistenceManager();
      pm.close();
    }
    catch ( Throwable t )
    {
      t.printStackTrace();
    }
  }
}
