/*
 * $Header: /home/cvs/struts/xdocs/struts1.1/documentation/ja/src/share/org/apache/struts/action/ActionForm.java,v 1.4 2003/12/16 16:46:16 skirnir Exp $
 * $Revision: 1.4 $
 * $Date: 2003/12/16 16:46:16 $
 *
 * ====================================================================
 *
 * 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.Serializable;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.upload.MultipartRequestHandler;


/**
 * <p><strong>ActionForm</strong>は1つ以上の<code>ActionMappings</code>
 * に関連づけることのできるJavaBeanです。
 * このBeanのプロパティは、対応するアクションの<code>execute</code>
 * メソッドが呼び出される前に、
 * 対応するリクエストパラメータで初期化されます。</p>
 * {@primary <p>An <strong>ActionForm</strong> is a JavaBean optionally associated with
 * one or more <code>ActionMappings</code>.  Such a bean will have had its
 * properties initialized from the corresponding request parameters before
 * the corresonding action's <code>execute</code> method is called.</p>}
 *
 * <p>Beanのプロパティが設定されると、
 * アクションの<code>execute</code>メソッドが呼び出される前にこのBeanの
 * <code>validate</code>メソッドが呼び出されます。
 * これはユーザから提示されたプロパティが正しくて妥当であるかを確かめる機会を
 * Beanに与えます。
 * このメソッドで問題が発見された場合、
 * 発生した問題をカプセル化したエラーメッセージオブジェクトを返し、
 * コントローラServletは対応する入力フォームにコントロールを返します。
 * また、全てのプロパティが条件に合っていて、
 * 対応するアクションの<code>execute</code>
 * メソッドが呼び出されるべきである場合は
 * <code>validate</code>メソッドは<code>null</code>を返します。</p>
 * {@primary <p>When the properties of this bean have been populated, but before the
 * <code>execute</code> method of the action is called, this bean's
 * <code>validate</code> method will be called, which gives the bean a chance
 * to verify that the properties submitted by the user are correct and valid.
 * If this method finds problems, it returns an error messages object that
 * encapsulates those problems, and the controller servlet will return control
 * to the corresponding input form.  Otherwise, the <code>validate</code>
 * method returns <code>null</code>, indicating that everything is acceptable
 * and the corresponding Action's <code>execute</code> method should be
 * called.</p>}
 *
 * <p>このクラスをインスタンス化するためにサブクラスを作成する必要があります。
 * サブクラスは公開したい全てのBeanプロパティのためのgetterメソッドと
 * setterメソッドを提供し、
 * さらににpublicメソッドや
 * protectedメソッドを機能の変更に応じてオーバライドすべきです。
 * </p>
 * {@primary <p>This class must be subclassed in order to be instantiated.  Subclasses
 * should provide property getter and setter methods for all of the bean
 * properties they wish to expose, plus override any of the public or
 * protected methods for which they wish to provide modified functionality.
 * </p>}
 *
 * <p>ActionFormsはJavaBeansですので、
 * JavaBean仕様を満たすようサブクラスも
 * <code>Serializable</code>を実装すべきです。
 * いくつかのコンテナでは、
 * ActionFormsが頼みにしているイントロスペクションAPIを用いるために、
 * オブジェクトがJavaBeanの全ての要件を満たすことが要求されます。</p>
 * {@primary <p>Because ActionForms are JavaBeans, subclasses should also implement
 * <code>Serializable</code>, as required by the JavaBean specification.
 * Some containers require that an object meet all JavaBean requirements
 * in order to use the introspection API upon which ActionForms rely.</p>}
 *
 * @author Craig R. McClanahan
 * @author Ted Husted
 * @version $Revision: 1.4 $ $Date: 2003/12/16 16:46:16 $
 * @translator 横田 健彦
 * @status firstdraft
 * @update 2003/12/15
 * @memo ブロックA
 */

public abstract class ActionForm implements Serializable {


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


    /**
     * 結びつけられているコントローラServletのインスタンスです。
     * {@primary The controller servlet instance to which we are attached.}
     */
    protected transient ActionServlet servlet = null;


    /**
     * このフォームのMultipartRequestHandlerです。
     * <code>null</code>のこともあります。
     * {@primary The MultipartRequestHandler for this form, can be
     * <code>null</code>.}
     */
    protected transient MultipartRequestHandler multipartRequestHandler;


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


    /**
     * 結びつけられているコントローラServletのインスタンスを返します。
     * {@primary Return the controller servlet instance to which we are attached.}
     */
    protected ActionServlet getServlet() {

        return (this.servlet);

    }


    /**
     * 結びつけられているコントローラServletのインスタンスを
     * ActionServletWrapperとして返します。
     * {@primary Return the controller servlet instance to which we are attached.
     * as an ActionServletWrapper.}
     * @see org.apache.struts.action.ActionServletWrapper
     * @since Struts 1.0.1
     */
    public ActionServletWrapper getServletWrapper() {

        return new ActionServletWrapper(getServlet());

    }


    /**
     * このフォームのMultipartRequestHandlerを返します。
     * この背景にある理由は、
     * MultipartRequestHandlerのfinish()メソッドと
     * rollback()メソッドを使用することによって、
     * フォームBeanの開発者がマルチパートのリクエストのライフサイクルを操作できるようにするためです。
     * このフォームのenctypeが"multipart/request-data"
     * でない場合はこのメソッドは<code>null</code>を返します。
     * {@annotation "multipart/form-data"が正しいと思います。}
     * {@primary Return the MultipartRequestHandler for this form
     * The reasoning behind this is to give form bean developers
     * control over the lifecycle of their multipart requests
     * through the use of the finish() and/or rollback() methods
     * of MultipartRequestHandler.  This method will return
     * <code>null</code> if this form's enctype is not
     * "multipart/request-data".}
     * @see org.apache.struts.upload.MultipartRequestHandler
     */
    public MultipartRequestHandler getMultipartRequestHandler() {
        return multipartRequestHandler;
    }


    /**
     * 結びつけられているコントローラServletのインスタンスをセットします
     * （<code>servlet</code>がnullでない場合）。
     * また、割り当てられた全てのリソースを解放します
     * （<code>servlet</code>がnullである場合）。
     * {@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 もしあれば、新しいコントローラServlet
     * {@primary The new controller servlet, if any}
     */
    public void setServlet(ActionServlet servlet) {

        this.servlet = servlet;

    }

    /**
     * ファイルアップロードを扱う際に使用するために与えられたHandlerを設定します。
     * {@primary Set the Handler provides to use in dealing with file uploads.}
     * {@note providesはprovidedの間違いと考えて訳しています。}
     * @param multipartRequestHandler   ファイルアップロードに使用するHandler。
     * {@primary The Handler to use for fileuploads.}
     */
    public void setMultipartRequestHandler(MultipartRequestHandler multipartRequestHandler) {
        this.multipartRequestHandler = multipartRequestHandler;
    }

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


    /**
     * Beanの全てのプロパティをデフォルトの状態にリセットします。
     * このメソッドはコントローラServlet
     * がプロパティを設定する前に呼び出されます。
     * {@primary Reset all bean properties to their default state.  This method is
     * called before the properties are repopulated by the controller servlet.}
     * <p>
     * デフォルトの実装はこのメソッドのHTTPバージョンにフォワードします。
     * {@primary <p>
     * The default implementation attempts to forward to the HTTP
     * version of this method.}
     *
     * @param mapping このインスタンスを選択するために用いられたマッピング
     * {@primary The mapping used to select this instance}
     * @param request 処理しているServletリクエスト
     * {@primary The servlet request we are processing}
     */
    public void reset(ActionMapping mapping, ServletRequest request) {

        try {
            reset(mapping, (HttpServletRequest) request);
        } catch (ClassCastException e) {
            ;
        }

    }


    /**
     * Beanの全てのプロパティをデフォルトの状態にリセットします。
     * このメソッドはコントローラServlet
     * がプロパティを設定する前に呼び出されます。
     * {@primary Reset all bean properties to their default state.  This method is
     * called before the properties are repopulated by the controller servlet.}
     * <p>
     * デフォルトの実装は何もしません。
     * サブクラスは全てのBeanプロパティをデフォルトの値にリセットするためにこのメソッドをオーバライドすべきです。
     * </p>
     * {@primary <p>
     * The default implementation does nothing.  Subclasses should override
     * this method to reset all bean properties to default values.
     * </p>}
     * <p>
     * 「更新」タイプのページに関しては、
     * このメソッドはフォームの値を初期化する場所としてはふさわし<strong>くありません</strong>
     * （値の初期化はセットアップ用のActionの中で行なうべきです）。
     * チェックボックスの値をfalseに設定することについて主に気にする必要がありますが、
     * ほとんどの場合はこのメソッドを実装しないでおいて構いません。
     * </p>
     * {@primary <p>
     * This method is <strong>not</strong> the appropriate place to initialize form values
     * for an "update" type page (this should be done in a setup Action).  You mainly
     * need to worry about setting checkbox values to false; most of the time you
     * can leave this method unimplemented.
     * </p>}
     *
     * @param mapping このインスタンスを選択するために用いられたマッピング
     * {@primary The mapping used to select this instance}
     * @param request 処理しているServletリクエスト
     * {@primary The servlet request we are processing}
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {

        ;       // Default implementation does nothing

    }


    /**
     * 非HTTPリクエストにセットされているプロパティの妥当性を検証して、
     * 見つかった全ての検証エラーをカプセル化した
     * <code>ActionErrors</code>オブジェクトを返します。
     * エラーが見つからなかった場合は<code>null</code>
     * もしくはエラーメッセージが何も記録されていない
     * <code>ActionErrors</code>オブジェクトを返します。
     * {@primary Validate the properties that have been set for this non-HTTP request,
     * and return an <code>ActionErrors</code> object that encapsulates any
     * validation errors that have been found.  If no errors are found, return
     * <code>null</code> or an <code>ActionErrors</code> object with no
     * recorded error messages.}
     * <p>
     * デフォルトの実装はこのメソッドのHTTPバージョンにフォワードします。
     * {@primary <p>
     * The default implementation attempts to forward to the HTTP version of
     * this method.}
     *
     * @param mapping このインスタンスを選択するために用いられたマッピング
     * {@primary The mapping used to select this instance}
     * @param request 処理しているServletリクエスト
     * {@primary The servlet request we are processing}
     */
    public ActionErrors validate(ActionMapping mapping,
                                 ServletRequest request) {

        try {
            return (validate(mapping, (HttpServletRequest) request));
        } catch (ClassCastException e) {
            return (null);
        }

    }


    /**
     * HTTPリクエストにセットされているプロパティの妥当性を検証して、
     * 見つかった全ての検証エラーをカプセル化した
     * <code>ActionErrors</code>オブジェクトを返します。
     * エラーが見つからなかった場合は<code>null</code>
     * もしくはエラーメッセージが何も記録されていない
     * <code>ActionErrors</code>オブジェクトを返します。
     * {@primary Validate the properties that have been set for this HTTP request,
     * and return an <code>ActionErrors</code> object that encapsulates any
     * validation errors that have been found.  If no errors are found,
     * return <code>null</code> or an <code>ActionErrors</code> object with
     * no recorded error messages.}
     * <p>
     * デフォルトの実装は何の検証も行なわずに<code>null</code>を返します。
     * サブクラスは独自の妥当性の検証を行なうためにこのメソッドをオーバライドしなくてはいけません。
     * {@primary <p>
     * The default ipmlementation performs no validation and returns
     * <code>null</code>.  Subclasses must override this method to provide
     * any validation they wish to perform.}
     *
     * @param mapping このインスタンスを選択するために用いられたマッピング
     * {@primary The mapping used to select this instance}
     * @param request 処理しているServletリクエスト
     * {@primary The servlet request we are processing}
     */
    public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {

        return (null);

    }


}
