/*
 * $Header: /home/cvs/struts/xdocs/struts1.1/documentation/ja/src/share/org/apache/struts/action/Action.java,v 1.5 2003/12/16 17:42:41 skirnir Exp $
 * $Revision: 1.5 $
 * $Date: 2003/12/16 17:42:41 $
 *
 * ====================================================================
 *
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowlegement:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowlegement may appear in the software itself,
 *    if and wherever such third-party acknowlegements normally appear.
 *
 * 4. The names "The Jakarta Project", "Struts", and "Apache Software
 *    Foundation" must not be used to endorse or promote products derived
 *    from this software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache"
 *    nor may "Apache" appear in their names without prior written
 *    permission of the Apache Group.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 */

package org.apache.struts.action;

import java.io.IOException;
import java.util.Locale;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;

import org.apache.struts.Globals;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.TokenProcessor;

/**
 * <strong>Action</strong>はHTTPリクエストの内容とそのリクエストを処理するために実行されるべきビジネスロジックとの間のアダプタクラスです。
 * コントローラ（ActionServlet）はリクエストに適切なActionを選択して（必要に応じて）インスタンスを生成し、<code>perform</code>メソッドを呼び出します。</p>
 * {@primary An <strong>Action</strong> is an adapter between the contents of an incoming
 * HTTP request and the corresponding business logic that should be executed to
 * process this request.  The controller (ActionServlet) will select an
 * appropriate Action for each request, create an instance (if necessary),
 * and call the <code>perform</code> method.</p>}
 *
 * <p>コントローラは同時に発生した複数のリクエストに対して同一のインスタンスを共有するため、Actionはスレッドセーフであるようにプログラムすべきです。
 * すなわち次の項目に従って設計すべきです。
 * </p>
 * {@primary <p>Actions must be programmed in a thread-safe manner, because the
 * controller will share the same instance for multiple simultaneous
 * requests.  This means you should design with the following items in mind:
 * </p>}
 * <ul>
 * <li>リクエストの状態に関連する情報を保持するためにインスタンス変数やスタティック変数を使用してはいけません。インスタンス変数やスタティック変数は同一のアクションに関してリクエストをまたがってグローバルなリソースを共有したい場合に使用します。</li>
 * <li>他のリソース（JavaBeans、セッション変数等）へのアクセスは、それらが保護を要求する場合は同期化しなくてはいけません（しかしながら、一般的にリソースクラスは必要に応じて自分自身を保護するように設計すべきです）。</li>
 * </ul>
 * {@primary <ul>
 * <li>Instance and static variables MUST NOT be used to store information
 *     related to the state of a particular request.  They MAY be used to
 *     share global resources across requests for the same action.</li>
 * <li>Access to other resources (JavaBeans, session variables, etc.) MUST
 *     be synchronized if those resources require protection.  (Generally,
 *     however, resource classes should be designed to provide their own
 *     protection where necessary.</li>
 * </ul>}
 *
 * <p><code>Action</code>インスタンスが最初に生成される時、コントローラServletはそのActionが結びつけられるコントローラServletインスタンスを識別するためにnullでない引数とともに<code>setServlet()</code>を呼び出します。
 * コントローラServletがシャットダウン（または再起動）する時、そのActionに割り当てられている使用中のリソースをクリーンアップするために<code>setServlet()</code>がnullの引数とともに呼び出されます。</p>
 * {@primary <p>When an <code>Action</code> instance is first created, the controller
 * servlet will call <code>setServlet()</code> with a non-null argument to
 * identify the controller servlet instance to which this Action is attached.
 * When the controller servlet is to be shut down (or restarted), the
 * <code>setServlet()</code> method will be called with a <code>null</code>
 * argument, which can be used to clean up any allocated resources in use
 * by this Action.</p>}
 *
 * @author Craig R. McClanahan
 * @author David Graham
 * @version $Revision: 1.5 $ $Date: 2003/12/16 17:42:41 $
 * @translator 横田 健彦
 * @status firstdraft
 * @update 2003/12/16
 * @memo ブロックA
 */
public class Action {


    // ----------------------------------------------------- Manifest Constants


    // NOTE - The definitions of manifest constant values have moved from
    // here to the org.apache.struts.Globals class, so that they can be
    // referenced without having to maintain a reference to the Action class
    // itself.  Any future new constant values should be defined there
    // instead of here.


    /**
     * <code>ActionServlet</code>インスタンスが格納されているコンテキスト属性のキーです。
     * {@primary The context attributes key under which our <code>ActionServlet</code>
     * instance will be stored.}
     * @deprecated 代わりにGlobals.ACTION_SERVLET_KEYを使用して下さい。
     * {@primary Use Globals.ACTION_SERVLET_KEY instead.}
     * @since Struts 1.1
     */
    public static final String ACTION_SERVLET_KEY = Globals.ACTION_SERVLET_KEY;


    /**
     * <p><code>ModuleConfig</code>データ構造が格納されるコンテキスト属性のキーのベース部分です。
     * 実際の属性のキーを作成するために、この末尾に実際のモジュールプリフィクス（先頭の"/"文字を含みます）が付加されます。</p>
     * {@primary <p>The base of the context attributes key under which our
     * <code>ModuleConfig</code> data structure will be stored.  This
     * will be suffixed with the actual module prefix (including the
     * leading "/" character) to form the actual attributes key.</p>}
     *
     * <p>コントローラサーブレットによって処理される各リクエストについて、
     * 現在処理しているリクエストURIによって選択されたモジュールに関する
     * <code>ModuleConfig</code>オブジェクトはリクエスト属性としてもこのキーで公開されます。</p>
     * {@primary <p>For each request processed by the controller servlet, the
     * <code>ModuleConfig</code> object for the module selected by
     * the request URI currently being processed will also be exposed under
     * this key as a request attribute.</p>}
     *
     * @since Struts 1.1
     * @deprecated  {@link org.apache.struts.Globals#MODULE_KEY}に置き換えられました。
     * {@primary Replaced by {@link org.apache.struts.Globals#MODULE_KEY}}
     */
    public static final String APPLICATION_KEY = Globals.MODULE_KEY;


    /**
     * 現在のモジュールのために設定されている場合、
     * <strong>デフォルトの</strong>データソース（<code>javax.sql.DataSource</code>を実装している必要があります）が格納されているコンテキスト属性のキーです。
     * {@primary The context attributes key under which our <strong>default</strong>
     * configured data source (which must implement
     * <code>javax.sql.DataSource</code>) is stored,
     * if one is configured for this module.}
     * @deprecated  {@link org.apache.struts.Globals#DATA_SOURCE_KEY}に置き換えられました。
     * {Replaced by {@link org.apache.struts.Globals#DATA_SOURCE_KEY}}
     */
    public static final String DATA_SOURCE_KEY = Globals.DATA_SOURCE_KEY;


    /**
     * 対応するカスタムタグライブラリの要素を使用している場合、アクションが<code>org.apache.struts.action.ActionErrors</code>オブジェクトを格納すべきリクエスト属性のキーです。
     * {@primary The request attributes key under which your action should store an
     * <code>org.apache.struts.action.ActionErrors</code> object, if you
     * are using the corresponding custom tag library elements.}
     * @deprecated  {@link org.apache.struts.Globals#ERROR_KEY}に置き換えられました。
     * {@primary Replaced by {@link org.apache.struts.Globals#ERROR_KEY}}
     */
    public static final String ERROR_KEY = Globals.ERROR_KEY;


    /**
     * Strutsのカスタムタグの中で実行時に生じたJspExceptionを報告するために生成された<code>Throwable</code>を格納するリクエスト属性のキーです。この値は実際には何がうまくいかなかったのかということに関してより詳細な情報を提供するためにエラーページで使用できます。
     * {@primary The request attributes key under which Struts custom tags might store a
     * <code>Throwable</code> that caused them to report a JspException at
     * runtime.  This value can be used on an error page to provide more
     * detailed information about what really went wrong.}
     * @deprecated  {@link org.apache.struts.Globals#EXCEPTION_KEY}に置き換えられました。
     * {@primary Replaced by {@link org.apache.struts.Globals#EXCEPTION_KEY}}
     */
    public static final String EXCEPTION_KEY = Globals.EXCEPTION_KEY;


    /**
     * ActionServletの初期化により上書きされるまで、
     * <code>org.apache.struts.action.ActionFormBeans</code>コレクションが通常格納されているコンテキスト属性のキーです。
     * {@primary The context attributes key under which our
     * <code>org.apache.struts.action.ActionFormBeans</code> collection
     * is normally stored, unless overridden when initializing our
     * ActionServlet.}
     *
     * @deprecated ModuleConfigの中のコレクションに置き換えられました。
     * {@primary Replaced by collection in ModuleConfig}
     */
    public static final String FORM_BEANS_KEY = Globals.FORM_BEANS_KEY;


    /**
     * ActionServletの初期化により上書きされるまで、
     * <code>org.apache.struts.action.ActionForwards</code>コレクションが通常格納されているコンテキスト属性のキーです。
     * {@primary The context attributes key under which our
     * <code>org.apache.struts.action.ActionForwards</code> collection
     * is normally stored, unless overridden when initializing our
     * ActionServlet.}
     *
     * @deprecated ModuleConfigの中のコレクションに置き換えられました。
     * {@primary Replaced by collection in ModuleConfig.}
     */
    public static final String FORWARDS_KEY = Globals.FORWARDS_KEY;


    /**
     * ユーザが選択した<code>java.util.Locale</code>があればそれが格納されているセッション属性のキーです。
     * この属性が見つからない場合、国際化されたメッセージを検索する際にはシステムのデフォルトのロケールが使用されます。
     * この属性を利用する場合、典型的にはこの属性はユーザのログイン処理の際にセットされます。
     * {@primary The session attributes key under which the user's selected
     * <code>java.util.Locale</code> is stored, if any.  If no such
     * attribute is found, the system default locale
     * will be used when retrieving internationalized messages.  If used, this
     * attribute is typically set during user login processing.}
     * @deprecated  {@link org.apache.struts.Globals#LOCALE_KEY}に置き換えられました。
     * {@primary Replaced by {@link org.apache.struts.Globals#LOCALE_KEY}}
     */
    public static final String LOCALE_KEY = Globals.LOCALE_KEY;


    /**
     * <code>org.apache.struts.ActionMapping</code>のインスタンスが渡されるリクエスト属性のキーです。
     * {@primary The request attributes key under which our
     * <code>org.apache.struts.ActionMapping</code> instance
     * is passed.}
     * @deprecated  {@link org.apache.struts.Globals#MAPPING_KEY}に置き換えられました。
     * {@primary Replaced by {@link org.apache.struts.Globals#MAPPING_KEY}}
     */
    public static final String MAPPING_KEY = Globals.MAPPING_KEY;


    /**
     * ActionServletの初期化により上書きされるまで、
     * <code>org.apache.struts.action.ActionMappings</code>のコレクションが通常格納されているコンテキスト属性のキーです。
     * {@primary The context attributes key under which our
     * <code>org.apache.struts.action.ActionMappings</code> collection
     * is normally stored, unless overridden when initializing our
     * ActionServlet.}
     *
     * @deprecated ModuleConfigの中のコレクションに置き換えられました。
     * {@primary Replaced by collection in ModuleConfig}
     */
    public static final String MAPPINGS_KEY = Globals.MAPPINGS_KEY;


    /**
     * 対応するカスタムタグライブラリの要素を使用している場合、
     * アクションが<code>org.apache.struts.action.ActionMessages</code>オブジェクトを格納すべきリクエスト属性のキーです。
     * {@primary The request attributes key under which your action should store an
     * <code>org.apache.struts.action.ActionMessages</code> object, if you
     * are using the corresponding custom tag library elements.}
     *
     * @since Struts 1.1
     * @deprecated  {@link org.apache.struts.Globals#MESSAGE_KEY}に置き換えられました。
     * {@primary Replaced by {@link org.apache.struts.Globals#MESSAGE_KEY}}
     */
    public static final String MESSAGE_KEY = Globals.MESSAGE_KEY;


    /**
     * <p>モジュールの<code>MessageResources</code>が格納されるコンテキスト属性のキーのベース部分です。
     * 実際の属性のキーを作成するために、この末尾に実際のモジュールプリフィクス（先頭の"/"文字を含みます）が付加されます。</p>
     * {@primary <p>The base of the context attributes key under which our
     * module <code>MessageResources</code> will be stored.  This
     * will be suffixed with the actual module prefix (including the
     * leading "/" character) to form the actual resources key.</p>}
     *
     * <p>コントローラサーブレットによって処理される各リクエストについて、
     * 現在処理しているリクエストURIによって選択されたモジュールに関する
     * <code>ModuleConfig</code>オブジェクトはリクエスト属性としてもこのキーで公開されます。</p>
     * {@primary <p>For each request processed by the controller servlet, the
     * <code>MessageResources</code> object for the module selected by
     * the request URI currently being processed will also be exposed under
     * this key as a request attribute.</p>}
     * @deprecated 代わりにGlobals.MESSAGES_KEYを使用して下さい。
     * {@primary Use Globals.MESSAGES_KEY instead.}
     */
    public static final String MESSAGES_KEY = Globals.MESSAGES_KEY;


    /**
     * マルチパートのクラスが格納されているリクエスト属性のキーです。
     * {@primary The request attributes key under which our multipart class is stored.}
     * @deprecated 代わりにGlobals.MULTIPART_KEYを使用して下さい。
     * {@primary Use Globals.MULTIPART_KEY instead.}
     */
    public static final String MULTIPART_KEY = Globals.MULTIPART_KEY;


    /**
     * <code>PlugIn</code>インスタンスの配列が格納されるコンテキスト属性のキーのベース部分です。
     * 実際の属性のキーを作成するために、この末尾に実際のモジュールプリフィクス（先頭の"/"文字を含みます）が付加されます。</p>
     * {@primary <p>The base of the context attributes key under which an array of
     * <code>PlugIn</code> instances will be stored.  This
     * will be suffixed with the actual module prefix (including the
     * leading "/" character) to form the actual attributes key.</p>}
     * @since Struts 1.1
     * @deprecated  {@link org.apache.struts.Globals#PLUG_INS_KEY}に置き換えられました。
     * {@primary Replaced by {@link org.apache.struts.Globals#PLUG_INS_KEY}}
     */
    public static final String PLUG_INS_KEY = Globals.PLUG_INS_KEY;


    /**
     * <p><code>RequestProcessor</code>インスタンスが格納されるコンテキスト属性のキーのベース部分です。
     * 実際の属性のキーを作成するために、この末尾に実際のモジュールプリフィクス（先頭の"/"文字を含みます）が付加されます。</p>
     * {@primary <p>The base of the context attributes key under which our
     * <code>RequestProcessor</code> instance will be stored.  This
     * will be suffixed with the actual module prefix (including the
     * leading "/" character) to form the actual attributes key.</p>}
     * @since Struts 1.1
     * @deprecated 代わりにGlobals.REQUEST_PROCESSOR_KEYを使用して下さい。
     * {@primary Use Globals.REQUEST_PROCESSOR_KEY instead.}
     */
    public static final String REQUEST_PROCESSOR_KEY =
        Globals.REQUEST_PROCESSOR_KEY;


    /**
     * コントローラサーブレットのために定義されているマッピングが格納されているコンテキスト属性のキーです。格納されているマッピングはパスマップ（path-mapped）パターン（<code>/action/*</code>）もしくは拡張子マップ（extension mapped）パターン（<code>*.do</code>）のどちらかです。
     * {@primary The context attributes key under which we store the mapping defined
     * for our controller serlet, which will be either a path-mapped pattern
     * (<code>/action/*</code>) or an extension mapped pattern
     * (<code>*.do</code>).}
     * @deprecated 代わりにGlobals.SERVLET_KEYを使用して下さい。
     * {@primary Use Globals.SERVLET_KEY instead.}
     */
    public static final String SERVLET_KEY = Globals.SERVLET_KEY;


    /**
     * トランザクショントークンが利用されている場合、
     * それが格納されているセッション属性のキーです。
     * {@primary The session attributes key under which our transaction token is
     * stored, if it is used.}
     * @deprecated 代わりに Globals.TRANSACTION_TOKEN_KEYを使用して下さい。
     * {@primary Use Globals.TRANSACTION_TOKEN_KEY instead.}
     */
    public static final String TRANSACTION_TOKEN_KEY =
        Globals.TRANSACTION_TOKEN_KEY;

    /**
     * トークン機能のために使用されるTokenProcessorのインスタンスです。
     * {@primary An instance of TokenProcessor to use for token functionality.}
     * @TODO この変数をprotectedにしてActionのトークン関連のメソッドを削除するか、
     * privateのままにしておいてトークン関連のメソッドが呼び出しを委譲するのを許可するか。
     * {@primary We can make this variable protected and remove Action's token methods
     * or leave it private and allow the token methods to delegate their calls.}
     */
    private static TokenProcessor token = TokenProcessor.getInstance();


    // ----------------------------------------------------- Instance Variables


    /**
     * システムのデフォルトのロケールです。
     * {@primary The system default Locale.}
     */
    protected static Locale defaultLocale = Locale.getDefault();


    /**
     * このActionに関連づけられているコントローラサーブレットです。
     * {@primary The controller servlet to which we are attached.}
     */
    protected ActionServlet servlet = null;


    // ------------------------------------------------------------- Properties


    /**
     * このActionに関連づけられているコントローラサーブレットのインスタンスを返します。
     * {@primary Return the controller servlet instance to which we are attached.}
     */
    public ActionServlet getServlet() {

        return (this.servlet);

    }


    /**
     * （<code>servlet</code>がnullでない場合）このActionに関連づけられているコントローラサーブレットのインスタンスをセットします。または（<code>servlet</code>がnullである場合）このActionに関連づけられているリソースを解放します。
     * {@primary Set the controller servlet instance to which we are attached (if
     * <code>servlet</code> is non-null), or release any allocated resources
     * (if <code>servlet</code> is null).}
     *
     * @param servlet もしあれば、新しいコントローラサーブレット
     * {@primary The new controller servlet, if any}
     */
    public void setServlet(ActionServlet servlet) {

        this.servlet = servlet;

    }


    // --------------------------------------------------------- Public Methods


    /**
     * 指定された非HTTPリクエストを処理して、
     * 対応する非HTTPレスポンスを生成します
     * （またはレスポンスを生成する他のWebコンポーネントにリクエストをフォワードします）。
     * 併せてビジネスロジックがスローする例外のハンドリングも提供します。
     * コントロールをどこにどうやってフォワードすべきかが記述された
     * {@link ActionForward}インスタンスもしくは、
     * レスポンスが既に完成している場合は<code>null</code>を返します。
     * {@primary Process the specified non-HTTP request, and create the
     * corresponding non-HTTP response (or forward to another web
     * component that will create it), with provision for handling
     * exceptions thrown by the business logic.
     * Return an {@link ActionForward} instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.}
     * <p>
     * デフォルトの実装では、このメソッドのHTTPバージョンにフォワードします。
     * {@primary <p>
     * The default implementation attempts to forward to the HTTP
     * version of this method.}
     *
     * @param mapping このインスタンスを選択するために使用したActionMapping
     * {@primary The ActionMapping used to select this instance}
     * @param form 存在するならば、このリクエストのためのActionForm Bean
     * {@primary The optional ActionForm bean for this request (if any)}
     * @param request 処理している非HTTPリクエスト
     * {@primary The non-HTTP request we are processing}
     * @param response 処理している非HTTPレスポンス
     * {@primary The non-HTTP response we are creating}
     *
     * @exception Exception アプリケーションのビジネスロジックが例外をスローした場合
     * {@primary if the application business logic throws
     *  an exception}
     * @since Struts 1.1
     */
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 ServletRequest request,
                                 ServletResponse response)
        throws Exception {

        // Call the deprecated method for backwards compatibility
        return (perform(mapping, form, request, response));

    }


    /**
     * 指定されたHTTPリクエストを処理して、
     * 対応するHTTPレスポンスを生成します
     * （またはレスポンスを生成する他のWebコンポーネントにリクエストをフォワードします）。
     * 併せてビジネスロジックがスローする例外のハンドリングも提供します。
     * コントロールをどこにどうやってフォワードすべきかが記述された
     * {@link ActionForward}インスタンスもしくは、
     * レスポンスが既に完成している場合は<code>null</code>を返します。
     * {@primary Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it),
     * with provision for handling exceptions thrown by the business logic.
     * Return an {@link ActionForward} instance describing where and how
     * control should be forwarded, or <code>null</code> if the response
     * has already been completed.}
     *
     * @param mapping このインスタンスを選択するために使用したActionMapping
     * {@primary The ActionMapping used to select this instance}
     * @param form 存在するならば、このリクエストのためのActionForm Bean
     * {@primary The optional ActionForm bean for this request (if any)}
     * @param request 処理しているHTTPリクエスト
     * {@primary The HTTP request we are processing}
     * @param response 処理しているHTTPレスポンス
     * {@primary The HTTP response we are creating}
     *
     * @exception Exception アプリケーションのビジネスロジックが例外をスローした場合
     * {@primary if the application business logic throws
     *  an exception}
     * @since Struts 1.1
     */
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {

        // Call the deprecated method for backwards compatibility
        return (perform(mapping, form, request, response));

    }


    /**
     * 指定された非HTTPリクエストを処理して、
     * 対応する非HTTPレスポンスを生成します
     * （またはレスポンスを生成する他のWebコンポーネントにリクエストをフォワードします）。
     * コントロールをどこにどうやってフォワードすべきかが記述された
     * {@link ActionForward}インスタンスもしくは、
     * レスポンスが既に完成している場合は<code>null</code>を返します。
     * {@primary Process the specified non-HTTP request, and create the corresponding
     * non-HTTP response (or forward to another web component that will create
     * it).  Return an <code>ActionForward</code> instance describing where
     * and how control should be forwarded, or <code>null</code> if the
     * response has already been completed.}
     * <p>
     * デフォルトの実装では、このメソッドのHTTPバージョンにフォワードします。
     * {@primary <p>
     * The default implementation attempts to forward to the HTTP version of
     * this method.}
     *
     * @param mapping このインスタンスを選択するために使用したActionMapping
     * {@primary The ActionMapping used to select this instance}
     * @param form 存在するならば、このリクエストのためのActionForm Bean
     * {@primary The optional ActionForm bean for this request (if any)}
     * @param request 処理している非HTTPリクエスト
     * {@primary The non-HTTP request we are processing}
     * @param response 処理している非HTTPレスポンス
     * {@primary The non-HTTP response we are creating}
     *
     * @exception IOException 入出力エラーが発生した
     * @exception ServletException Servlet例外が発生した
     * {@primary if an input/output error occurs}
     * {@primary if a servlet exception occurs}
     *
     * @deprecated 代わりに<code>execute()</code>メソッドを使用して下さい。
     * {@primary Use the <code>execute()</code> method instead}
     */
    public ActionForward perform(ActionMapping mapping,
                                 ActionForm form,
                                 ServletRequest request,
                                 ServletResponse response)
        throws IOException, ServletException {

        try {
            return (perform(mapping, form,
                            (HttpServletRequest) request,
                            (HttpServletResponse) response));
        } catch (ClassCastException e) {
            return (null);
        }

    }


    /**
     * 指定されたHTTPリクエストを処理して、
     * 対応するHTTPレスポンスを生成します
     * （もしくはレスポンスを生成する他のWebコンポーネントにリクエストをフォワードします）。
     * コントロールをどこにどうやってフォワードするかが記述された
     * <code>ActionForward</code>インスタンスもしくは、
     * レスポンスが既に完成している場合は<code>null</code>を返します。
     * {@primary Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.}
     *
     * @param mapping このインスタンスを選択するために使用したアクションマッピング
     * {@primary The ActionMapping used to select this instance}
     * @param form 存在するならば、このリクエストのためのアクションフォームBean
     * {@primary The optional ActionForm bean for this request (if any)}
     * @param request 処理しているHTTPリクエスト
     * {@primary The HTTP request we are processing}
     * @param response 生成中のHTTPレスポンス
     * {@primary The HTTP response we are creating}
     *
     * @exception IOException 入出力エラーが発生した
     * {@primary if an input/output error occurs}
     * @exception ServletException Servlet例外が発生した
     * {@primary if a servlet exception occurs}
     *
     * @deprecated 代わりに<code>execute()</code>メソッドを使用して下さい。
     * {@primary Use the <code>execute()</code> method instead}
     */
    public ActionForward perform(ActionMapping mapping,
                 ActionForm form,
                 HttpServletRequest request,
                 HttpServletResponse response)
    throws IOException, ServletException {

        return (null);  // Override this method to provide functionality

    }


    // ---------------------------------------------------- Protected Methods


    /**
     * 1つのトランザクションに対してリクエストが1つだけであるようにするために使用する、
     * 新しいトランザクショントークンを生成します。
     * {@primary Generate a new transaction token, to be used for enforcing a single
     * request for a particular transaction.}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The request we are processing}
     */
    protected String generateToken(HttpServletRequest request) {
        return token.generateToken(request);
    }


    /**
     * 現在のモジュールのデフォルトのデータソースを返します。
     * {@primary Return the default data source for the current module.}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The servlet request we are processing}
     *
     * @since Struts 1.1
     */
    protected DataSource getDataSource(HttpServletRequest request) {

        return (getDataSource(request, Globals.DATA_SOURCE_KEY));

    }



    /**
     * 現在のモジュールの指定されたデータソースを返します。
     * {@primary Return the specified data source for the current module.}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The servlet request we are processing}
     * @param key 要求されているまとまりに対応する、
     *  <code>&lt;message-resources&gt;</code>要素の中で指定されているキー
     * {@annotation このコメントはおかしいです。おそらくgetMessageResourcesからコメントをCopy&amp;Pasteしてきたものと思われます。}
     * {@primary The key specified in the
     *  <code>&lt;message-resources&gt;</code> element for the
     *  requested bundle}
     *
     * @since Struts 1.1
     */
    protected DataSource getDataSource(HttpServletRequest request, String key) {

        // Identify the current module
        ServletContext context = getServlet().getServletContext();
        ModuleConfig moduleConfig = RequestUtils.getModuleConfig(request,context);

        // Return the requested data source instance
        return ((DataSource) context.getAttribute(key + moduleConfig.getPrefix()));

    }


    /**
     * ユーザの現在選択されているロケールを返します。
     * {@primary Return the user's currently selected Locale.}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The request we are processing}
     */
    protected Locale getLocale(HttpServletRequest request) {

        HttpSession session = request.getSession();
        Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY);
        if (locale == null) {
            locale = defaultLocale;
        }
        return (locale);

    }


    /**
     * デフォルトモジュールのメッセージリソースを返します。
     * {@primary Return the message resources for the default module.}
     *
     * @deprecated このメソッドはデフォルトモジュールのリソースを返すだけです。
     * 現在のモジュールのリソースを取得するには
     * getResources(HttpServletRequest)を使用して下さい。
     * {@primary This method can only return the resources for the default
     *  module.  Use getResources(HttpServletRequest) to get the
     *  resources for the current module.}
     */
    protected MessageResources getResources() {

        return ((MessageResources)
                servlet.getServletContext().getAttribute(Globals.MESSAGES_KEY));

    }


    /**
     * 現在のモジュールのメッセージリソースを返します。
     * {@primary Return the default message resources for the current module.}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The servlet request we are processing}
     * @since Struts 1.1
     */
    protected MessageResources getResources(HttpServletRequest request) {

        return ((MessageResources) request.getAttribute(Globals.MESSAGES_KEY));

    }



    /**
     * 現在のモジュールの指定されたメッセージリソースを返します。
     * {@primary Return the specified message resources for the current module.}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The servlet request we are processing}
     * @param key 要求されているメッセージのまとまりに対応する、
     *  <code>&lt;message-resources&gt;</code>要素の中で指定されているキー
     * {@primary The key specified in the
     *  <code>&lt;message-resources&gt;</code> element for the
     *  requested bundle}
     *
     * @since Struts 1.1
     */
    protected MessageResources getResources(HttpServletRequest request,
                                            String key) {

        // Identify the current module
        ServletContext context = getServlet().getServletContext();
        ModuleConfig moduleConfig = RequestUtils.getModuleConfig(request,context);

        // Return the requested message resources instance
        return ((MessageResources) context.getAttribute
                (key + moduleConfig.getPrefix()));

    }


    /**
     * <p>現在のフォームのキャンセルボタンが押されていれば
     * <code>true</code>を返します。
     * このメソッドは
     * リクエスト属性<code>Globals.CANCEL_KEY</code>
     * が設定されているかどうかをチェックします。
     * この属性は通常、
     * 現在のリクエストにおいて
     * <strong>CancelTag</strong>
     * が生成したキャンセルボタンをユーザが押した時に設定されます。
     * <code>true</code>の場合、コントローラサーブレットは
     * <strong>ActionForm</strong>の<code>validate()</code>
     * メソッドによるバリデーションをスキップします。</p>
     * {@primary <p>Returns <code>true</code> if the current form's cancel button was
     * pressed.  This method will check if the <code>Globals.CANCEL_KEY</code>
     * request attribute has been set, which normally occurs if the cancel
     * button generated by <strong>CancelTag</strong> was pressed by the user
     * in the current request.  If <code>true</code>, validation performed
     * by an <strong>ActionForm</strong>'s <code>validate()</code> method
     * will have been skipped by the controller servlet.</p>}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The servlet request we are processing}
     * @see org.apache.struts.taglib.html.CancelTag
     */
    protected boolean isCancelled(HttpServletRequest request) {

        return (request.getAttribute(Globals.CANCEL_KEY) != null);

    }


    /**
     * ユーザの現在のセッションにトランザクショントークンが保持されていて、
     * かつこのアクションのリクエストパラメータとして送信された値がそのトークンとマッチする場合に
     * <code>true</code>を返します。
     * 次のいずれかの場合は<code>false</code>を返します：
     * <ul>
     * <li>このリクエストにセッションが関連づけられていない</li>
     * <li>セッションにトランザクショントークンが保存されていない</li>
     * <li>リクエストパラメータとしてトランザクショントークンが含まれていない</li>
     * <li>含まれているトランザクショントークンの値がユーザのセッション中のトランザクショントークンの値とマッチしない</li>
     * </ul>
     * {@primary Return <code>true</code> if there is a transaction token stored in
     * the user's current session, and the value submitted as a request
     * parameter with this action matches it.  Returns <code>false</code>
     * under any of the following circumstances:
     * <ul>
     * <li>No session associated with this request</li>
     * <li>No transaction token saved in the session</li>
     * <li>No transaction token included as a request parameter</li>
     * <li>The included transaction token value does not match the
     *     transaction token in the user's session</li>
     * </ul>}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The servlet request we are processing}
     */
    protected boolean isTokenValid(HttpServletRequest request) {

        return token.isTokenValid(request, false);

    }


    /**
     * ユーザの現在のセッションにトランザクショントークンが保持されていて、
     * かつこのアクションのリクエストパラメータとして送信された値がそのトークンとマッチする場合に
     * <code>true</code>を返します。
     * 次のいずれかの場合は<code>false</code>を返します：
     * <ul>
     * <li>このリクエストにセッションが関連づけられていない</li>
     * <li>セッションにトランザクショントークンが保存されていない</li>
     * <li>リクエストパラメータとしてトランザクショントークンが含まれていない</li>
     * <li>含まれているトランザクショントークンの値がユーザのセッション中のトランザクショントークンの値とマッチしない</li>
     * </ul>
     * {@note 原文はisTokenValid(HttpServletRequest)とほぼ一緒なのですが1行だけ不自然に落ちています。おそらくミスと思われますので、その部分を補完して翻訳してあります。}
     * {@primary Return <code>true</code> if there is a transaction token stored in
     * the user's current session, and the value submitted as a request
     * parameter with this action matches it.  Returns <code>false</code>
     * <ul>
     * <li>No session associated with this request</li>
     * <li>No transaction token saved in the session</li>
     * <li>No transaction token included as a request parameter</li>
     * <li>The included transaction token value does not match the
     *     transaction token in the user's session</li>
     * </ul>}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The servlet request we are processing}
     * @param reset チェックの後にトークンをリセットするべきか？
     * {@primary Should we reset the token after checking it?}
     */
    protected boolean isTokenValid(
        HttpServletRequest request,
        boolean reset) {

        return token.isTokenValid(request, reset);
    }


    /**
     * ユーザのセッションに保存されているトランザクショントークンをリセットします。
     * これは送信される次のリクエストに関してはトランザクショントークンをチェックする必要がないということです。
     * {@primary Reset the saved transaction token in the user's session.  This
     * indicates that transactional token checking will not be needed
     * on the next request that is submitted.}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The servlet request we are processing}
     */
    protected void resetToken(HttpServletRequest request) {
        token.resetToken(request);
    }


    /**
     * なんらかのエラーメッセージが必要な場合、
     * &lt;html:errors&gt;タグが利用できるように、
     * 指定されたエラーメッセージキーを適切なリクエスト属性に保存します。
     * そうでない場合はリクエスト属性が生成されないようにします。
     * {@primary Save the specified error messages keys into the appropriate request
     * attribute for use by the &lt;html:errors&gt; tag, if any messages
     * are required.  Otherwise, ensure that the request attribute is not
     * created.}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The servlet request we are processing}
     * @param errors エラーメッセージオブジェクト
     * {@primary Error messages object}
     */
    protected void saveErrors(HttpServletRequest request,
                  ActionErrors errors) {

        // Remove any error messages attribute if none are required
        if ((errors == null) || errors.isEmpty()) {
            request.removeAttribute(Globals.ERROR_KEY);
            return;
        }

        // Save the error messages we need
        request.setAttribute(Globals.ERROR_KEY, errors);

    }


    /**
     * なんらかのメッセージが必要な場合、
     * （messages="true"が設定されていれば）
     * &lt;html:errors&gt;タグが利用できるように、
     * 指定されたメッセージキーを適切なリクエスト属性に保存します。
     * そうでない場合はリクエスト属性が生成されないようにします。
     * {@primary Save the specified messages keys into the appropriate request
     * attribute for use by the &lt;html:messages&gt; tag (if
     * messages="true" is set), if any messages are required.  Otherwise,
     * ensure that the request attribute is not created.}
     *
     * @param request 処理しているサーブレットリクエスト
     * {The servlet request we are processing}
     * @param messages メッセージオブジェクト
     * {Messages object}
     * @since Struts 1.1
     */
    protected void saveMessages(HttpServletRequest request,
                    ActionMessages messages) {

        // Remove any messages attribute if none are required
        if ((messages == null) || messages.isEmpty()) {
            request.removeAttribute(Globals.MESSAGE_KEY);
            return;
        }

        // Save the messages we need
        request.setAttribute(Globals.MESSAGE_KEY, messages);

    }


    /**
     * ユーザの現在のセッションに新しいトランザクショントークンを保存します。
     * 必要に応じてセッションが新しく生成されます。
     * {@primary Save a new transaction token in the user's current session, creating
     * a new session if necessary.}
     *
     * @param request 処理しているサーブレットリクエスト
     * {@primary The servlet request we are processing}
     */
    protected void saveToken(HttpServletRequest request) {
        token.saveToken(request);
    }


    /**
     * ユーザの現在選択されているロケールを設定します。
     * {@primary Set the user's currently selected Locale.}
     *
     * @param request 処理しているリクエスト
     * {@primary The request we are processing}
     * @param locale 設定される、ユーザの現在選択されているロケール。
     * サーバのデフォルトのロケールを選択する場合はnull
     * {@primary The user's selected Locale to be set, or null
     *  to select the server's default Locale}
     */
    protected void setLocale(HttpServletRequest request, Locale locale) {

        HttpSession session = request.getSession();
        if (locale == null) {
            locale = defaultLocale;
        }
        session.setAttribute(Globals.LOCALE_KEY, locale);

    }


    /**
     * byteの配列を16進数の文字列に変換して返します。
     * {@primary Convert a byte array to a String of hexadecimal digits and return it.}
     *
     * @param buffer 変換するbyteの配列
     * {@primary The byte array to be converted}
     * @deprecated このメソッドはStruts1.1以降のリリースでは削除されるでしょう。
     * {@primary This method will be removed in a release after Struts 1.1.}
     */
    protected String toHex(byte buffer[]) {
        return token.toHex(buffer);
    }


}
