RemoteDictionaryImpl.java



/** RemoteDictionaryの実装のクラスの例 */
import java.util.*;
public class RemoteDictionaryImpl extends _RemoteDictionaryImplBase {

  /** 辞書のデータベース */
    private Hashtable dictionary;

  /** コンストラクタ */
    public RemoteDictionaryImpl() {
        super();
        dictionary = new Hashtable();
        dictionary.put( "maruyama", "Maruyama Fujio" );
        dictionary.put( "tatsuo", "Ueda Tatsuo" );
        dictionary.put( "himemiya", "Himemiya Tosiaki" );
        dictionary.put( "fujiki", "Fujiki Fumihiko" );
        dictionary.put( "sakamoto", "Sakamoto Kan" );
        dictionary.put( "kanayama", "Kanayama Noriyo" );
        dictionary.put( "momma", "Momma George" );
        dictionary.put( "saga", "Saga Takahiro" );
        dictionary.put( "oosawa", "Oosawa Hiroki" );
    }

  /** クライアントに返答を返すメソッド */
    public String answer( String key ) {

        return dictionary.get( key ).toString();
    }

  /** クライアントにキーの一覧を返すメソッド */
    public String[] keys() {

        Enumeration enum = dictionary.keys();
        Vector vector = new Vector();
        while( enum.hasMoreElements() )
            vector.addElement( enum.nextElement() );
        String[] keys = new String[ vector.size() ];
        for( int i=0; i<vector.size(); i++ )
            keys[i] = (String)vector.elementAt(i);

        return keys;
    }
}