コード例 #1
0
  /**
   * Initialize and load our initial database from persistent storage.
   *
   * @param servlet The ActionServlet for this web application
   * @param config The ApplicationConfig for our owning module
   * @exception ServletException if we cannot configure ourselves correctly
   */
  public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {

    log.info("Initializing memory database plug in from '" + pathname + "'");

    // Remember our associated configuration and servlet
    this.servlet = servlet;

    // Construct a new database and make it available
    database = new MemoryUserDatabase();
    try {
      String path = calculatePath();
      if (log.isDebugEnabled()) {
        log.debug(" Loading database from '" + path + "'");
      }
      database.setPathname(path);
      database.open();
    } catch (Exception e) {
      log.error("Opening memory database", e);
      throw new ServletException("Cannot load database from '" + pathname + "'", e);
    }

    // Make the initialized database available
    servlet.getServletContext().setAttribute(Constants.DATABASE_KEY, database);
  }