design patterns - CORBA + IDL + Java: need help with writing servant -


i have defined idl file, looks 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 compile idlj. have defined bankservant, used client communicate server , have working program methods implemented. problem don't know how can implement account(in accountid accnr) method, in turn return proper account object. don't know corba , helping friend, ask kind of solutions / examples / tutorialis may me hack simple yet working class layout dealing kind of situations.

thank in advance.

it depends on policies you're using poa (the portable object adapter). assuming you're using rootpoa in server, have to:

  1. create implementation object account object. called accountimpl or accountservant see in name of bank servant.

    accountservant = new accountservant(accnr);

  2. you have register object in poa. this, again, has policies you've selected poa. using default root poa:

    org.omg.corba.object o = rootpoa.servant_to_reference( );

  3. narrow correct account type using idl compiler generated accounthelper:

    account acc = accounthelper.narrow(o);

  4. return it

    return acc;

this code assumes you've written constructor accountservant java object accepts account number first argument. have provide bankservant reference poa in want register newly created account objects.

there lots of tutorials. see this one example, set of options poa many require book explain them :).


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -