Q:

CORBA + IDL + Java: need help with writing servant

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.

A:

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 or AccountServant 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 generated AccountHelper:
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 the BankServant also with a reference to the POA in which you want to register the newly created Account 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 :).

