エラー処理の実行の実装

実行時にエラー処理が必要なイベントには、関連するerrorBehaviorアクションが必要です。 RPTEventGenerator クラスを拡張して、イベント動作を指定します。

KAction オブジェクトは IRPTEventHandler メソッドを実装することによってイベントを処理します。 検査ポイントの失敗または接続の失敗などのイベントが発生した場合、イベントの親である KAction オブジェクトに対して以下の呼び出しを実行します。

KAction.registerEvent(eventType, eventBehavior);

上記の例で、eventType パラメーターは障害のタイプです。 eventBehavior パラメーターは、障害が発生したときに実行するアクションです。

KAction.finish() プロシージャー中に、登録済みのすべてのイベント動作が処理されます。 特定のイベントについて登録済みの動作が処理されます。 イベント階層の上位レベルで指定されている該当する動作が処理されます。

次のコードはRPTEventGeneratorクラスを実装します:

public abstract class RPTEventGenerator implements IRPTEventGenerator{
	RPTEvent behavior = null;
	boolean behaviorSet = false;
	IKAction act = null;
	RPTEvent eventType;
	

	public void setEventBehavior(IKAction act, RPTEvent eventType, RPTEvent behavior){
		behaviorSet = true;
		this.behavior = behavior;
		this.act = act;
		this.eventType = eventType;
	}
	
	public RPTEvent getEventBehavior(){
		return behavior;
	}
	
	public RPTEvent getEventType(){
		return eventType;
	}

	public KAction getAction(){
		return act;
	}
}

以下のコード例は、ServerConnection クラスについて実行時にエラー処理を実装する方法を示しています。

public class ServerConnection extends RPTEventGenerator implements IServerConnection {

public ServerConnection(String name, int port, ISSLInfo sslInfo,
			INtlmAuthenticationContext ntlmContext,
			IProxyServerInfo proxyServerInfo,
			boolean closeWhenTestCompletes, RPTEvent behav) {
		this.serverAddr = new InetAddressInfo(name, port);
		this.sslInfo = sslInfo;
		this.ntlmCxt = ntlmContext;
		this.proxyInfo = proxyServerInfo;
		this.inUse = true;
		this.closeWhenTestCompletes = closeWhenTestCompletes;
		setEventBehavior(null, new RPTConnectEvent(), behav);
	}
}

サーバー接続の失敗についての動作に、以下のコードが含まれるようになりました。

	registerEvent(((IRPTEventGenerator)m_Request.getServerConnection()).getEventType(), ((IRPTEventGenerator)m_Request.getServerConnection()).getEventBehavior());