CORBA + IDL + Java:需要编写servant的帮助
我有一个定义的 idl 文件,如下所示:
module Banking {
typedef string Transactions[5];
typedef long AccountId;
interface Account {
exception InsufficientFunds {};
readonly attribute double balance;
long lodge(in double amount);
long withdraw(in double amount) raises (InsufficientFunds);
readonly attribute Transactions transactions;
};
interface Bank {
long accountCount();
double totalMoney();
Account account(in AccountId accNr);
};
};
我用 idlj 编译该文件。我定义了一个 BankServant,客户端使用它与服务器进行通信,并且我有一个工作程序,几乎实现了所有方法。我唯一的问题是我不知道如何实现 account(in AccountId accNr) 方法,该方法又会返回正确的 Account 对象。由于我不了解 CORBA 并且我只是在帮助朋友,我想请求某种解决方案/示例/教程,这可能会帮助我破解一个简单但有效的类布局来处理这种情况。
先感谢您。
I have a defined idl file, which looks like this:
module Banking {
typedef string Transactions[5];
typedef long AccountId;
interface Account {
exception InsufficientFunds {};
readonly attribute double balance;
long lodge(in double amount);
long withdraw(in double amount) raises (InsufficientFunds);
readonly attribute Transactions transactions;
};
interface Bank {
long accountCount();
double totalMoney();
Account account(in AccountId accNr);
};
};
which I compile with idlj. I have defined a BankServant, used by the client to communicate with the server and I have a working program with almost all methods implemented. My only problem is that I don't know how can I implement account(in AccountId accNr)
method, which in turn will return the proper Account object. As I don't know CORBA and I am just helping a friend, I would like to ask for some kind of solutions / examples / tutorialis which may help me to hack a simple yet working class layout for dealing with that kind of situations.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上取决于您为 POA(可移植对象适配器)使用的策略。假设您在服务器中使用 RootPOA,则必须:
为 Account 对象创建一个实现对象。正如我在银行仆人的名称中看到的那样,这通常称为
AccountImpl
或AccountServant
。AccountServant as = new AccountServant(accNr);
您必须在 POA 中注册该对象。这又与您为 POA 选择的政策有关。使用默认的根 POA:
org.omg.CORBA.Object o = rootPOA.servant_to_reference( as );
使用 IDL 编译器将其缩小到正确的
Account
类型生成的AccountHelper:Account acc = AccountHelper.narrow(o);
返回
return acc;
此代码假定您已为
AccountServant
java 对象编写了构造函数接受帐号作为其第一个参数。您还必须向BankServant
提供对要在其中注册新创建的Account
对象的 POA 的引用。有很多教程。例如,请参阅这个,因为 POA 的选项集非常多这需要一本书来解释它们:)。
It really depends on the policies you're using for the POA (the Portable Object Adapter). Assuming you're using the RootPOA in the server, you have to:
Create an implementation object for the Account object. This is usually called
AccountImpl
orAccountServant
as I see in the name of the bank servant.AccountServant as = new AccountServant(accNr);
You have to register the object in the POA. This, again, has to do with the policies you've selected for your POA. using the default Root POA:
org.omg.CORBA.Object o = rootPOA.servant_to_reference( as );
Narrow it to the correct
Account
type using the IDL compiler generatedAccountHelper
:Account acc = AccountHelper.narrow(o);
Return it
return acc;
This code assumes you've written a constructor for the
AccountServant
java object that accepts the account number as its first argument. You have to provide theBankServant
also with a reference to the POA in which you want to register the newly createdAccount
objects.There are lots of tutorials. See this one for example, as the set of options for the POA are so many that require a book to explain them all :).