To initialize the ORB and retrieve a reference to the CosTransactions::Current interface, specify the TransactionCurrent ObjectId, which identifies the CosTransactions::Current interface, to the resolve_initial_references method, and narrow it (using the _narrow method) to the CosTransactions::Current interface. Use the is_nil method to verify that the reference to the CosTransactions::Current interface is valid.
The following code fragment shows how to initialize the ORB from a client. ORB_init must take the argumentList array that specifies the ORBNameServiceURL parameter. You can also set the ORBNameServiceURL using the JAG_NAMESERVICEURL environment variable.
int argumentCnt = 1;
char *argumentList[] = {
{ "-ORBNameServiceURL iiop://<hostnamehere>:9000" },
{ "" }
};
try {
CORBA::ORB_var orb = CORBA::ORB_init(argumentCnt, argumentList, 0);
cerr << "Orb init" << endl;
CORBA::Object_var crntObj =
orb->resolve_initial_references
("TransactionCurrent");
CosTransactions::Current_var CurrentIntf =
CosTransactions::Current::_narrow(crntObj);
if( CORBA::is_nil(CurrentIntf) )
{
cerr << "Error getting Current" << endl;
exit(-1);
}
cerr << "Got Current" << endl;
The following code fragment shows how to initialize the ORB from a component. ORB_init does not need to take any parameters.
orb = CORBA::ORB_init(argumentCnt, NULL, 0);
cerr << "Orb init" << endl;
CORBA::Object_var crntObj =
orb->resolve_initial_references
("TransactionCurrent");
CurrentIntf = CosTransactions::Current::_narrow(crntObj);
if( CORBA::is_nil(CurrentIntf) )
{
cerr << "Error getting Current" << endl;
/* could be due to:
** 1. Component not BeanManaged/OTS Style
** 2. Already in a Txn
** 3. not running under OTS
*/
return CS_FAIL;
}
cerr << "Got Current" << endl;