Specifying Values for Initial References
The API associated with the initialization service tells you how an application can get hold of initial object references. It says nothing, however, about where these object references come from or how to specify their values to the ORB. This question is left as an implementation detail for the ORB vendor. Different ORBs will let you set initial references in different ways. Typically, the values are stored in a configuration file that is accessible to the application.
Irrespective of the approach used, the existence of a standard API for the initialization service means that application code remains independent of the ORB configuration mechanism.
In addition to an unspecified mechanism for setting default initial references, the initialization service provides a mechanism for overriding defaults. You may specify initial references using one of the command-line arguments -ORBInitRef or -ORBDefaultInitRef. These command-line arguments are described in the following sections.
Command-Line Argument -ORBInitRef
The command-line argument -ORBInitRef allows you to override default values of initial references. For example, consider a C++ server that is initialized using the code given in Listing 1, and suppose the name of the server executable is server. If you want to force the server to use a naming service other than the one specified by the default ORB configuration mechanism, you could run the server as follows:
$ server -ORBInitRef NameService=IOR:010000001600000049444c3a53746f...
Here, NameService is the ObjectId for the naming service and IOR:0100000016... is the stringified object reference of a specific CosNaming::NamingContext or CosNaming::NamingContextExt object. The specified object reference will be returned in place of the default when the application invokes resolve_initial_references("NameService").
In Listing 1, you can see that the command-line arguments held in the string array argv are passed to CORBA::ORB_init(). As the ORB initializes, it scans the supplied argument list looking for options of the form -ORBsuffix. In this case, it finds a single option, -ORBInitRef. This option, along with its associated parameter NameService= IOR:0100000016..., is removed from the argument list argv, and the value is used as the initial reference for the naming service.
Command-Line Argument -ORBDefaultInitRef
The command-line argument -ORBDefaultInitRef allows you to usurp the initialization service completely by specifying a location from which all initial references are retrieved. The format for this option is:
URLStem can be given either as a corbaloc:iiop: or as a corbaname:iiop: URL. When resolve_initial_references("ObjectId") is subsequently invoked, the initial reference to ObjectId is resolved as follows:
An object URL is constructed from URLStem by appending a / (forward slash) to ObjectId. This gives a URL string of the general form URLStem/ObjectId.
The resulting URL URLStem/ObjectId is resolved in the standard way and passed back as the return value of resolve_initial_references().
For example, if the following command-line argument is passed to ORB_init()
a call of the form resolve_initial_references("TradingService") will result in the construction of the URL corbaname::1.2@myhost:1234/xyz#Foo/Bar/TradingService. The ORB will then look for an object of type CosTrading::Lookup bound under the name Foo/Bar/TradingService in the naming service given by the address :1.2@myhost:1234/xyz.