<?xml version="1.0" encoding="Shift_JIS"?>

<!DOCTYPE document SYSTEM "./dtd/document-v10.dtd">

<document>
  <header>
    <title>コーディング規約/Coding Conventions</title>
    <authors>
      <person name="Vincent Massol" email="vmassol@apache.org"/>
			<person name="Nicholas Lesiecki" email="ndlesiecki@apache.org"/>
    </authors>
    <translators><person name="漆島賢二"/></translators>
  </header>

  <body>

    <s1 title="序文/Forewords">

      <p>
        This document describes a list of coding conventions that are
        required for code submissions to the project. By default, the coding
        conventions for most Open Source Projects should follow the existing
        coding conventions in the code that you are working on. For example,
        if the bracket is on the same line as the if statement, then you
        should write all your code to have that convention.
      </p>
      <p>
	本ドキュメントでは、コード提出に必要なコーディング規約の一覧について述べます。
	デフォルトでは、
	ほとんどのオープンソースプロジェクトのコーディング規約は
	自分が作業しているコードに既に存在するコーディング規約に従うべきです。
	例えば、if 文と同じ行に括弧を置かなければならない場合は、
	自分全てのコードがその規約に従うように記述しなければなりません。
      </p>
      <note>
        <strong>If you commit code that does not follow these conventions and
        you are caught, you are responsible for also fixing your own code.
        </strong>
      </note>
      <note>
        <strong>もし、これらの規約に従わないコードをコミットした場合には、
	見つけられ、自分のコードを修正する義務も負います。
        </strong>
      </note>
      <p>
         Below is a list of coding conventions that are specific to Cactus,
         everything else not specificially mentioned here should follow the
         official <link
         href="http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html">Sun
         Java Coding Conventions</link>.
      </p>
      <p>
	 Cactus 固有のコーディング規約の一覧を下に示します。
	 特にここで述べられていない全ての事柄は公式の
	 <link href="http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html">Sun Java コーディング規約</link>に従わなければなりません。
      </p>

    </s1>

    <s1 title="どのように適用するか/How to apply ?">

      <p>
        Having coding conventions is nice but having a way to ensure they are
        applied is even better ... :-)
      </p>
      <p>
	コーディング規約があることは、とてもいいことですが、
	それが適用されることを確認する方法があれば、もっといいです、、、:-)
      </p>
      <p>
        The Cactus Ant build file has a <code>checkstyle</code> target which
        performs coding conventions using the
        <link href="http://checkstyle.sf.net">Checkstyle</link> tool. Drop the
        Checkstyle jars in your <code>ANT_HOME/lib</code>, go in the
        <code>build/</code> directory and type <code>ant checkstyle</code>.
      </p>
      <p>
	Cactus Ant ビルドファイルには、
	<link href="http://checkstyle.sf.net">Checkstyle</link> ツールを用いて
	コーディング規約を実践する
	<code>checkstyle</code> ターゲットがあります。
	Checkstyle jar を <code>ANT_HOME/lib</code> に置き、
	<code>build/</code> ディレクトリに移動し、
	<code>ant checkstyle</code> と入力します。
      </p>
      <p>
        Please run this target before committing any code.
      </p>
      <p>
	どんなコードでもコミットする前に、
	このターゲットを実行してください。
      </p>
    </s1>

    <s1 title="Cactus に固有なコーディング規約/Cactus specific coding conventions">

      <s2 title="1. 括弧/1. Brackets">

        <p>
          For class and method declaration, brackets should begin and end on a
          <strong>new</strong> line. Example :
        </p>
        <p>
	  クラスやメソッドの宣言では、
	  括弧は<strong>新しい</strong>行で始まり、終らなければなりません。
	  例えば次のようになります :
        </p>

<source><![CDATA[
public class SomeClass
{
    public void someMethod()
    {
    }
}
]]></source>

        <p>
          Brackets for blocks of code inside methods should begin and end
          on the <strong>same</strong> line (this applies to <code>if</code>,
          <code>for</code>, <code>while</code>, <code>try/catch</code>, ...).
          Example :
        </p>
        <p>
	  メソッド中のコードブロックの括弧は、
	  <strong>同じ</strong>行で始まり、終らなければなりません。
	  (これは、<code>if</code>、<code>for</code>、<code>while</code>、
	  <code>try/catch</code>、などに対して適用されます)
          例えば次のようになります : 
        </p>

<source><![CDATA[
public void someMethod()
{
    if (expression) {
    } else if (other_expression) {
    }

    try {
    } catch (Exception e) {
    }
}
]]></source>

        <p>
          <strong>Brackets are mandatory even for single line statements !
          </strong>
        </p>
        <p>
          <strong>括弧をつけることは、一行の文に対しても義務付けられています。
          </strong>
        </p>

<source><![CDATA[
// Incorrect
// 誤り
if (式/expression)
    // 何かのコード/some code

// Correct
// 正しい
if (式/expression) {
    // 何かのコード/some code
}
]]></source>

      </s2>

      <s2 title="2. 空白/2. Blank Spaces">

        <p>
           keywords followed by a parenthesis should be separated by a space.
           Example :
        </p>
        <p>
	   括弧のついたキーワードはスペースで区切られなければなりません。
	   例 : 
        </p>

<source><![CDATA[
while (true) {
    // 何かのコード/some code
}
]]></source>

        <p>
          Blank space should appear after commas in argument lists. Binary
          operators should be separated from their operands by spaces :
        </p>
        <p>
	  引数リスト中のカンマの後には空白がなければなりません。
	  二項演算子はその演算記号をスペースで区切らなければなりません : 
        </p>

<source><![CDATA[
a += c + d;
a = (a + b) / (c * d);

while (d++ = s++) {
    n++;
}

printSize("size is " + foo + "\n");
]]></source>

      </s2>

      <s2 title="3. インデント/3. Indentations">

        <p>
          <strong>4 spaces. NO tabs</strong>. Period. We understand that a lot
          of you like to
          use tabs, but the fact of the matter is that in a distributed
          development environment, when the cvs commit messages get sent to a
          mailing list, they are almost impossible to read if you use tabs.
        </p>
        <p>
          <strong>4 つの空白記号で、タブは無し</strong>。以上です。
	  皆さんの多くがタブを使いがちなのは知っていますが、
	  実際問題、分散開発環境においては、
	  cvs コミットメッセージがメーリングリストに送られるとき、
	  タブを使った場合、ほとんど読めないという事があるのです。
        </p>

      </s2>

      <s2 title="4. コメント/4. Comments">

        <p>
          Javadoc SHOULD exist on all your class members (methods + class
          variables), including the private ones. Also, if you are working on
          existing code and there currently isn't a javadoc for that
          method/class/variable or whatever, then you should contribute and
          add it. This will improve the project as a whole.
        </p>
        <p>
	  自分の全てのクラスのメンバー(メソッド + クラス変数)には、
	  プライベートなものも含めて、
	  javadoc が<strong>なければ</strong>なりません。
	  また、既存のコードで作業していて、
	  現状ではそのメソッド/クラス/変数に javadoc が無いなどの問題があったとき、
	  貢献して加えてください。
 	  この事がプロジェクト全体を推進させるのです。
        </p>
        <p>
          Also add code comments when you think it's necessary (like
          assumptions), especially when the code is not obvious.
        </p>
        <p>
	  また、(仮定のように)必要だと感じた場合、
	  特にコードが明瞭でない場合には、
	  コードにコメントを加えてください。
        </p>

      </s2>

      <s2 title="5. ライセンス/5. License">

        <p>
          The Jakarta Apache/Cactus License MUST be placed at the top of each
          and every file.
        </p>
        <p>
          Jakarta Apache/Cactus ライセンスは
	  個々の全てのファイルの先頭に<strong>置かなければなりません</strong>。
        </p>

      </s2>

      <s2 title="6. 作者参照/6. Author references">

        <p>
          If you contribute to a file (code or documentation), add yourself to
          the top of the file (below the existing authors). For java files the
          preferred Javadoc format is:
        </p>
        <p>
	  ファイル(コードやドキュメント)に対して貢献した場合、
	  ファイルの先頭に(既存の作者の下に)自分の名前を加えることができます。
	  java ファイルの場合、
	  推奨される javadoc フォーマットは次の通りです: 
        </p>

<source><![CDATA[
@author <a href="mailto:user@domain.com">John Doe</a>
]]></source>

      </s2>

      <s2 title="7. クラス変数/7. Class variables">

        <p>
          Class variables should not have any prefix and <strong>must</strong>
          be referenced using the <code>this</code> object. Example :
        </p>
        <p>
          Class variables should not have any prefix
	  クラス変数は何も前にあってはならず、
	  <code>this</code> オブジェクトを使って
	  <strong>参照されなければなりません</strong>。例えば次のようになります : 
        </p>

<source><![CDATA[
public class SomeClass
{
    private String someString;
[...]
    public void someMethod()
    {
        logger.debug("Value = " + this.someString);
    }
}
]]></source>

      </s2>

      <s2 title="8. 引数名/8. Parameter names">

        <p>
          Method parameters should be prefixed by "<code>the</code>" (for
          differentiating them from inner variables). For example :
        </p>
        <p>
	  メソッド引数名は必ず "<code>the</code>" で始らなければなりません。
	  (内部変数と区別するためにです。)
	  例えば次のようになります :
        </p>

<source><![CDATA[
public void someMethod(String theClassName)
{
    String className; // 内部変数/inner variable
}
]]></source>

      </s2>

      <s2 title="9. 行の長さ/9. Line length">

        <p>
          Avoid lines longer than 80 characters for Code, comments, ...
        </p>
        <p>
	  コードやコメントで一行が 80 文字以上になるのを避けてください。
        </p>

      </s2>

      <s2 title="10. バージョン/10. Versioning">

        <p>
          All .java files should have a <code>@version</code> tag like the one
          below.
        </p>
        <p>
	  全ての .java ファイルには下に示すような <code>@version</code> タグが無ければなりません : 
        </p>

<source><![CDATA[
@version $Id: coding_conventions.xml,v 1.1 2002/03/10 14:10:25 vmassol Exp $
]]></source>

      </s2>

      <s2 title="11. ログ/11. Logging">

        <p>
          Do <strong>not</strong> use <code>System.out</code> to log. Instead,
          use the Cactus logging classes which are a facade to Log4j. Use the
          name of your class as the Log4j <code>Category</code>. For
          example :
        </p>
        <p>
	  決してログ出力するのに <code>System.out</code> を
	  <strong>使わないでください</strong>。
	  代りに、Log4j を<suspect>使った</suspect> Cactus のロギングクラスを使ってください。
	  Log4j <code>Category</code> として自分のクラス名を使ってください。		 例は次の通りです : 
        </p>

<source><![CDATA[
private static Log logger =
		LogService.getInstance().getLog(MyClass.class.getName());

public void someMethod()
{
		logger.debug("some debug text");
}
]]></source>

        <note>
          As of Cactus 1.3, LogAspect autmatically logs all method entries and
					exits.
        </note>
        <note>
	  Cactus 1.3 では LogAspect は自動的に全てのメソッドの開始と終了がログ出力されます。
        </note>
      </s2>

      <s2 title="12. 例外処理/12. Exception handling">

        <p>
          Managing exceptions correctly requires experience. This is not
          supposed to be a guide on managing exceptions, simply a few best
          practices.
        </p>
        <p>
	  例外処理を正しく扱うには経験が必要です。
	  これは、例外処理を扱うガイドとして書かれたのではなく、
	  単に幾つかの最良の実例を示しただけです。
        </p>
        <ul>
          <li>
            <strong>Rule 1</strong> : Try to catch exceptions as much as
            possible and rethrow higher level exceptions (meaning hiding the
            low level detailed and putting a message that is more related to
            the function of your code).
          </li>
          <li>
            <strong>ルール 1</strong> : 
	    できる限り多くの例外をキャッチして、上のレベルの例外にスローしようとしてみてください。(これは、<suspect>低いレベルの詳細を隠蔽し</suspect>
	    自分のコードの関数により関係するメッセージを出力することを意味します)
          </li>
          <li>
            <strong>Rule 2</strong> : It is important not to loose the stack
            trace which contains important information. Use chained exceptions
            for that. Cactus provides a <code>ChainedRuntimeException</code>
            for chaining runtime exceptions.
          </li>
          <li>
            <strong>ルール 2</strong> : 
	    重要な情報が含まれているスタックトレースを無くさないことが大切です。
	    連鎖となったランタイムの例外のために、
	    Cactus では <code>ChainedRuntimeException</code> を提供しています。
          </li>
          <li>
            <strong>Rule 3</strong> : Always log the exception at the higher
            level (ie. where it is handled and not rethrown).
          </li>
          <li>
            <strong>ルール 3</strong> : 
	    常に上のレベルで例外のログを取ってください。
	    (即ち、そこで処理され再スローされない所で)
          </li>
          <li>
            <strong>Rule 4</strong> : Try to avoid catching
            <code>Throwable</code> or <code>Exception</code> and catch
            specific exceptions instead.
          </li>
          <li>
            <strong>ルール 4</strong> : 
	    <code>Throwable</code> あるいは <code>Exception</code> を
	    キャッチせず、代りに特定の例外をキャッチするように心がけてください。
          </li>
        </ul>
        <p>
          An example :
        </p>
        <p>
          例 :
        </p>

<source><![CDATA[
public void getTestClass()
{
    try {
        Class responseClass =
            Class.forName("some.package.MyClass");
    } catch (ClassNotFoundException cnfe) {
        String message = "Cannot instantiate test class";
        logger.error(message);
        throw new ChainedRuntimeException(message, e);
    }
}
]]></source>

      </s2>

      <s2 title="13. 限定されたインポート/13. Qualified imports">

        <p>
          All <code>import</code> statements should containing the full class
          name of classes to import and should not use the <code>"*"</code>
          notation :
        </p>
        <p>
	  全ての <code>import</code> 宣言には、
	  インポートするクラスのクラス名全体を入れるようにし、
	  <code>"*"</code> による表記を使わないようにしてください : 
        </p>
        <p>
          An example :
        </p>
        <p>
          例 :
        </p>

<source><![CDATA[
// 正しい/Correct
import java.util.Date;
import java.net.HttpURLConnection;

// 誤り/Not correct
import java.util.*;
import java.net.*;
]]></source>


      </s2>

    </s1>

  </body>
</document>
