package com.ngMAT.appl.genericservlet; import java.sql.SQLException; import java.util.Enumeration; import java.util.Vector; import com.ngMAT.HTML.HTMLComponent; import com.ngMAT.HTML.HTMLTemplate; import com.ngMAT.HTML.HTMLComponentVector; import com.ngMAT.HTML.form.Option; import com.ngMAT.servlet.EZServlet; import com.ngMAT.servlet.EZServletContext; import com.ngMAT.Common.LowLevelException; import com.ngMAT.appl.genericservlet.GenericServletConfig; import com.ngMAT.appl.genericservlet.GenericServletContext; import com.ngMAT.appl.GenericConstants; /** * EZServletベースのサーブレットフレームワーク。 * 以下のような典型的な処理フローを制御する。 *
  • セッション状態がこのページを使用可能状態を示しているかのチェック:isReadyToGo(..)の呼び出し。
  • *
  • アプリケーション処理の呼び出し:process (..)
  • *
  • エラーの場合のエラー処理
  • */ public abstract class GenericServlet extends EZServlet { private final static String TN_HostName = "HOSTNAME"; private final static String TN_DevLink = "DEV.LINK"; /** * 現在のセッション状態は、自サーブレットの処理を行ってよいかどうかを判定する。 */ public abstract boolean isReadyToGo (GenericServletContext context); /** * アプリケーション業務ロジック。 */ public abstract HTMLComponent process (GenericServletContext context); /** * EZServletから呼び出される、リクエストに対応する処理。 */ public final void processApplication(EZServletContext _context){ GenericServletContext context = (GenericServletContext)_context; GenericServletConfig config = (GenericServletConfig)context.getConfig(); try{ /* if ((config.login_required && ! context.isLoggedIn()) || (config.auth_required && ! context.isAuthorized())) { context.pushCallStack(); context.sendRedirect (config.login_url); } else if (! isReadyToGo (context)) */ if (! isReadyToGo (context)) { // context.pushCallStack(); context.sendRedirect (context.not_ready_page_url); } else if (context.userHasPowerToAccess()) { try{ if (config.use_database) context.assignConnection(); HTMLComponent output = process (context); if (config.use_database) context.releaseConnection(); setStandardTagValues (context, config, output); context.setOutput (output); } catch (com.ngMAT.servlet.EZSResponseWasRedirectedException e) { if (context.getConnection() != null ) context.releaseConnection(); throw e; }catch (Exception e){ context.getLog().printStackTrace (e); if (context.getConnection() != null ){ try{ context.getConnection().rollback(); }catch(SQLException e2){ getLog().println ("Failed to rollback while exception process : " + e2.getClass().getName() + " : " + e2.getMessage()); } context.releaseConnection(); } context.setOutput (context.getErrorHTML (e)); } } else { // 通るべき道に戻す。 context.sendRedirect (config.not_ready_page_url); } } catch (PageIsNotAvailableException ex){ // 使えませんページを表示 context.setOutput (config.not_available_template); } } private void setStandardTagValues (GenericServletContext context, GenericServletConfig config, HTMLComponent output) { if (output instanceof HTMLTemplate) { HTMLTemplate template = (HTMLTemplate)output; if (template.getInsertionTag (TN_HostName) != null) { template.setTagValue (TN_HostName, config.my_hostname); } } } }