Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 4 of 5
.
.
.
public class BankClient
{
public static void main(String args[])
{
try
{
// Create and initialize the ORB
ORB orb = ORB.init(args, null);
// Get the root naming context using corbaloc
//org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
org.omg.CORBA.Object objRef =
orb.string_to_object("corbaloc:iiop:localhost:1050/NameService");
// Use NamingContextExt instead of NamingContext. This is
// part of the Interoperable naming Service.
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
// Resolve the object reference in Naming
String name = "BankServer";
System.out.println(args.length);
if(args.length == 5)
name = args[4];
// Use corbaname instead of resolve_str
// Bank theBank = BankHelper.narrow(ncRef.resolve_str(name));
Bank theBank = BankHelper.narrow(orb.string_to_object("corbaname::localhost:1050#" + name));
System.out.println("Obtained a handle on server object: " + theBank);
AccountInformation accInfo = new AccountInformation();
accInfo.accNum="";
accInfo.accType = AccountType.NIL;
Account[] accounts = theBank.findAccounts(accInfo);
for(int i=0; i<accounts.length; i++)
System.out.println("Account Number " + ((Account)accounts[i]).accountNumber());
accounts[0].deposit((float)1.1);
}
catch(bank.UnknownException e)
{
System.out.print(e.reason);
}
.
.
.
}
Most CORBA vendors include limited proprietary support for bootstrapping their ORB instances with services other than the
ones they provide and sometimes even the ability to replace those services with other implementations. The INS standardizes
both these abilities by defining standard ORB options for bootstrapping. To bootstrap a CORBA system, you must give it an
object reference, which can be a stringified IOR or a corbaloc: URL. You can configure the ORB to return a customized CORBA service's handle from resolve_initial_references using either the ORBInitRef and/or ORBDefaultInitRef properties.
For example:
-ORBInitRef TraderService=corbaloc::XYZ.com:1050/TraderService -ORBDefaultInitRef corbaloc:iiop:1.2:ABC.com:1050
The resolution order of when the ORB uses these options is as follows:
register_initial_references-ORBInitRef-ORBDefaultInitRefHere's an example of replacing the standard J2SE 1.4 naming service implementation with another one running on XYZ.com on port 4076:
-ORBInitRef NameService=corbaloc::XYZ.com:4076/NameService
The one tool that J2SE 1.4 does not offer is a naming service viewer to show what's in the naming service. So, as a going away present, I am providing you with such a tool: a naming service browser, shown in the figure below.

Naming service browser
You can download the browser code from Resources. Assuming that your naming service (ORBD/tnameserv) is running on localhost at port 1050, you use this command line:
java cosnaming.utils.NamingBrowser -ORBInitialPort 1050 -ORBInitialHost localhost
I've covered much ground in this four-part series on enterprise CORBA. I hope you feel confident enough to use J2SE's CORBA features in your own applications. The Java platform complements CORBA by providing Write Once, Run Anywhere portability, a highly productive implementation environment, and a robust platform. With J2SE 1.4's support for CORBA 2.3.1 and its associated enterprise features such as the POA, Portable Interceptors, and the INS, the reasons to use CORBA are even more compelling.