Java Reference
In-Depth Information
As in the fi rst example, these classes will be placed inside the same fi le as our
server code.
4. Create the server.
Our server program will be called StockItemServer.java and will subsume the ser-
vants created in the last step. It will import package Sales and (as in the previous
example) the following three standard CORBA packages:
￿
org.omg.CosNaming ;
￿
org.omg.CosNaming.NamingContextPackage ;
￿
org.omg.CORBA .
The same basic sub-steps as were featured in the previous example will again be
required, of course. Rather than reiterate these steps formally in the text, they will be
indicated by comments within the code. The additional code involves the creation of
a StockItemFactoryServant object and the associated registration of this object with
the ORB, creation of an associated NameComponent object and so forth. Once again,
comments within the code indicate the meaning of individual program lines.
import Sales.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
public class StockItemServer
{
public static void main(String[] args)
{
try
{
//Create and initialise the ORB…
ORB orb = ORB.init(args,null);
//Create a StockItemServant object…
StockItemServant stockServant =
new StockItemServant("S0001", 100);
//Register the object with the ORB…
orb.connect(stockServant);
//Create a StockItemFactoryServant object…
StockItemFactoryServant factoryServant =
new StockItemFactoryServant();
//Register the object with the ORB…
orb.connect(factoryServant);
//Get a reference to the root naming context…
org.omg.CORBA.Object objectRef =
orb.resolve_initial_references("NameService");
Search WWH ::




Custom Search