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:
create implementation object account object. called
accountimpl
oraccountservant
see in name of bank servant.accountservant = new accountservant(accnr);
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( );
narrow correct
account
type using idl compiler generatedaccounthelper
:account acc = accounthelper.narrow(o);
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
Post a Comment