/*
 * $Id: configure.java,v 1.2 2005/07/04 16:25:16 rampil Exp $
 * LOGICAL-PARADOX.ORG
 * Copyright (C)2005 satoshi akabane(akabane@logical-paradox.org)
 *
 */
package org.logical_paradox.gdrn.shell.command;

import java.io.OutputStream;

import org.logical_paradox.rss.lookup.LookupFactory;
import org.logical_paradox.shell.Argument;
import org.logical_paradox.shell.Command;
import org.logical_paradox.shell.ResultCode;
import org.logical_paradox.shell.ShellEnv;
import org.logical_paradox.shell.exception.CommandExecutionException;
import org.logical_paradox.shell.exception.TerminationException;

/**
 * <pre>
 * ■configure
 * 
 * 【動作仕様】
 * 指定のDSRに対して、ルーティングテーブルの更新を通知します。
 * 更新の通知のみ行なうため、実際にDSRが更新を行なうかどうかはDSRの実行状態に依存します。
 * 
 * 【書式】
 * configure [<dsr-uri>]
 * </pre>
 * 
 * @author satoshi akabane@logical-paradox.org
 * @version $Revision: 1.2 $
 */
public class configure implements Command {
	public static final String USAGE = "connect <dsr-uri>";
	public String usage() {
		return USAGE;
	}
	public ResultCode execute(OutputStream o, ShellEnv env, Argument a) throws CommandExecutionException, TerminationException {
		String[] arguments = a != null ? a.getArguments() : new String[0];
		String dsruri = env.getProperty("DEFAULT_DSR_URI");
		String serviceType = null;

		if(arguments != null && arguments.length >= 1) {
			// 対象DSR
			dsruri = arguments[0];
		}

		// DSRのスタブを取得する
		try {
			LookupFactory.getLookup(dsruri).configure();
		} catch (Exception e) {
			throw new CommandExecutionException("fail on lookup '" + dsruri + "'.");
		}

		return new ResultCode(ResultCode.STATUS_OK);
	}

}
