package org.apache.commons.lang.exception;

/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2002 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", "Commons", 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 Software Foundation.
 *
 * 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/>.
 */

import java.io.PrintStream;
import java.io.PrintWriter;

/**
 * {@link java.lang.Throwable} の実装にルートとなる例外を
 * 内部にネストして持つことができるように拡張を行うインターフェイスです。
 * {@primary An interface to be implemented by {@link java.lang.Throwable}
 * extensions which would like to be able to nest root exceptions
 * inside themselves.}
 *
 * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
 * @author <a href="mailto:knielsen@apache.org">Kasper Nielsen</a>
 * @author <a href="mailto:steven@caswell.name">Steven Caswell</a>
 * @translator 日置 聡
 * @status firstdraft
 * @update 2003/08/06
 * @version $Id: Nestable.java,v 1.1.1.1 2004/02/13 10:02:04 hioki Exp $
 */
public interface Nestable
{
    /**
     * <code>Nestable</code> が実装された例外の原因となった例外またはエラーの参照を返します。
     * {@primary Returns the reference to the exception or error that caused the
     * exception implementing the <code>Nestable</code> to be thrown.}
     */
    public Throwable getCause();

    /**
     * この例外とネストされた <code>Throwable</code> のエラーメッセージを返します。
     * {@primary Returns the error message of this and any nested
     * <code>Throwable</code>.}
     *
     * @return エラーメッセージ
     * {@primary the error message}
     */
    public String getMessage();

    /**
     * 内部に保持されている <code>Throwable</code> のうち、0 から始まる指定されたインデックスに該当する
     * <code>Throwable</code> のメッセージを返します。
     * {@primary Returns the error message of the <code>Throwable</code> in the chain
     * of <code>Throwable</code>s at the specified index, numbererd from 0.}
     *
     * @param index 内部に保持されている <code>Throwable</code> のインデックス
     * {@primary the index of the <code>Throwable</code> in the chain of
     * <code>Throwable</code>s}
     * @return エラーメッセージ、インデックスで指定された <code>Throwable</code>
     * にメッセージが設定されていない場合には null
     * {@primary the error message, or null if the <code>Throwable</code> at the
     * specified index in the chain does not contain a message}
     * @throws IndexOutOfBoundsException <code>index</code> の値がマイナスまたは内部の <code>Throwable</code>
     * の数が指定された値よりも少ない場合
     * {@primary if the <code>index</code> argument is
     * negative or not less than the count of <code>Throwable</code>s in the
     * chain}
     */
    public String getMessage(int index);

    /**
     * この例外と内部にネストされる <code>Throwable</code> のエラーメッセージをStringの配列に格納して返します。
     * メッセージを持たない <code>Throwable</code> のメッセージは null で表現されます。
     * 返される配列の長さは原因の数を示す {@link #getThrowableCount()} の返す値と一致します。
     * {@primary Returns the error message of this and any nested <code>Throwable</code>s
     * in an array of Strings, one element for each message. Any
     * <code>Throwable</code> not containing a message is represented in the
     * array by a null. This has the effect of cause the length of the returned
     * array to be equal to the result of the {@link #getThrowableCount()}
     * operation.}
     *
     * @return エラーメッセージ
     * {@primary the error messages}
     */
    public String[] getMessages();

    /**
     * 内部に保持されている <code>Throwable</code> のうち、0 から始まる指定されたインデックスに該当する
     * <code>Throwable</code> を返します。
     * {@primary Returns the <code>Throwable</code> in the chain of
     * <code>Throwable</code>s at the specified index, numbererd from 0.}
     *
     * @param index 内部に保持される <code>Throwable</code> の 0 から始まるインデックス
     * {@primary the index, numbered from 0, of the <code>Throwable</code> in
     * the chain of <code>Throwable</code>s}
     * @return 該当する <code>Throwable</code>
     * {@primary the <code>Throwable</code>}
     * @throws IndexOutOfBoundsException <code>index</code> の値がマイナスまたは内部の <code>Throwable</code>
     * の数が指定された値よりも少ない場合
     * {@primary if the <code>index</code> argument is
     * negative or not less than the count of <code>Throwable</code>s in the
     * chain}
     */
    public Throwable getThrowable(int index);

    /**
     * この <code>Nestable</code> に含まれるネストされた <code>Throwable</code> の数を返します。
     * {@primary Returns the number of nested <code>Throwable</code>s represented by
     * this <code>Nestable</code>, including this <code>Nestable</code>.}
     *
     * @return スロー可能オブジェクト(throwable)の数
     * {@primary the throwable count}
     */
    public int getThrowableCount();
    
    /**
     * この <code>Nestable</code> と、内部にネストされた <code>Throwable</code>
     * を <code>Throwable</code> の配列に格納して返します。
     * {@primary Returns this <code>Nestable</code> and any nested <code>Throwable</code>s
     * in an array of <code>Throwable</code>s, one element for each
     * <code>Throwable</code>.}
     *
     * @return <code>Throwable</code> の配列
     * {@primary the <code>Throwable</code>s}
     */
    public Throwable[] getThrowables();

    /**
     * 内部にネストされた <code>Throwable</code> の中から、最初に見つかった指定された型の 0 から始まるインデックスを返します。
     * 該当するものが見つからなかった場合には -1 を返します。
     * {@primary Returns the index, numbered from 0, of the first occurrence of the
     * specified type in the chain of <code>Throwable</code> <code>Throwable</code>s, or -1 if the
     * specified type is not found in the chain.}
     *
     * @param type 検索対象となる <code>Class</code>
     * {@primary type <code>Class</code> to be found}
     * @return 指定された型が最初に見つかったインデックス、見つからなかった場合には -1
     * {@primary index of the first occurrence of the type in the chain, or -1 if
     * the type is not found}
     */
    public int indexOfThrowable(Class type);

    /**
     * 内部にネストされた <code>Throwable</code> から、最初に見つかった指定された型の、検索開始位置より後ろの
     * 0 から始まるインデックスを返します。
     * 該当するものが見つからなかった場合には -1 を返します。
     * {@primary Returns the index, numbered from 0, of the first <code>Throwable</code>
     * that matches the specified type in the chain of <code>Throwable</code>s
     * with an index greater than or equal to the specified index, or -1 if
     * the type is not found.}
     *
     * @param type 検索対象となる <code>Class</code>
     * {@primary type <code>Class</code> to be found}
     * @param fromIndex 検索の開始位置となる 0 から始まるインデックス
     * {@primary the index, numbered from 0, of the starting position in
     * the chain to be searched}
     * @return 指定された型が最初に見つかったインデックス、見つからなかった場合には -1
     * {@primary index of the first occurrence of the type in the chain, or -1 if
     * the type is not found}
     * @throws IndexOutOfBoundsException <code>fromIndex</code>の値がマイナスまたは内部の
     * <code>Throwable</code> の数が指定された値よりも少ない場合
     * {@primary if the <code>fromIndex</code> argument
     * is negative or not less than the count of <code>Throwable</code>s in the
     * chain}
     */
    public int indexOfThrowable(Class type, int fromIndex);
    
    /**
     * 指定された print writer に対してこの例外のスタックトレースを出力します。
     * この例外の原因(となる例外)がある場合にはその情報も出力されます。
     * {@primary Prints the stack trace of this exception to the specified print
     * writer.  Includes inforamation from the exception--if
     * any--which caused this exception.}
     *
     * @param out 出力に使用される <code>PrintWriter</code>
     * {@primary <code>PrintWriter</code> to use for output.}
     */
    public void printStackTrace(PrintWriter out);

    /**
     * 指定された print stream に対してこの例外のスタックトレースを出力します。
     * この例外の原因(となる例外)がある場合にはその情報も出力されます。
     * {@primary Prints the stack trace of this exception to the specified print
     * stream.  Includes inforamation from the exception--if
     * any--which caused this exception.}
     *
     * @param out 出力に使用される <code>PrintStream</code>
     * {@primary <code>PrintStream</code> to use for output.}
     */
    public void printStackTrace(PrintStream out);

    /**
     * 指定された writer に対してルートとなる(ネストされたものを含まない)例外のスタックトレースを出力します。
     * {@link org.apache.commons.lang.exception.NestableDelegate}
     * から、個々のスタックトレースをバッファに出力するために使用されます。
     * このメソッドの実装は大体の場合 <code>super.printStackTrace(out);</code> を呼ぶべきです。
     * {@primary Prints the stack trace for this exception only--root cause not
     * included--using the provided writer.  Used by {@link
     * org.apache.commons.lang.exception.NestableDelegate} to write
     * individual stack traces to a buffer.  The implementation of
     * this method should call
     * <code>super.printStackTrace(out);</code> in most cases.}
     *
     * @param out 使用される writer
     * {@primary The writer to use.}
     */
    public void printPartialStackTrace(PrintWriter out);
}

