| Interstage Application Server アプリケーション作成ガイド (CORBAサービス編) |
目次
索引
![]()
|
| 第6章 アプリケーションの開発(Java言語) |
以下にIDL言語でユーザ例外が定義されていた場合について、サーバアプリケーションプログラムの例を示します。
【IDL言語】
module ODsample {
interface exptest{
exception testException { string reason; };
void op1() raises( testException );
};
};
これをJava言語で記述すると以下のようになります。
【Java言語】
<インタフェース>
package ODsample;
public interface exptestOperations{
public void op1()
throws ODsample.exptestPackage.testException;
}
<ユーザ例外クラス>
package ODsample.exptestPackage;
public final class testException
extends org.omg.CORBA.UserException
{
public java.lang.String reason;
public testException(){}
public testException( java.lang.String _reason ){
reason = _reason;
}
}
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import ODsample.*;
public class expServer {
public static void main( String args[] ) {
try {
// ORBの前処理
:
// POAオブジェクトの生成
:
// Servantの生成とそのPOAへの登録
:
// POAManagerの活性化
:
}
catch ( java.lang.Exception e ) {
//エラー処理
:
}
}
}
// Servantクラス
// サーバアプリケーションのメソッド
class expServant extends exptestPOA{
public void op1() throws ODsample.exptestPackage.testException {
throw new ODsample.exptestPackage.testException(
"Test of UserException" );
}
}
サーバアプリケーションで例外を獲得する方法は、クライアントアプリケーションの例外処理と同様です。詳細については、“クライアントアプリケーションの例外処理”を参照してください。
目次
索引
![]()
|