/* This file implements the client */ import org.omg.CosNaming.* ; /* The naming service classes */ import org.omg.CORBA.* ; /* Required for ALL CORBA programs */ import stock_market.*; import stock_market.stock_serverPackage.*; /* Client stubs */ /* This is for other work */ import java.util.*; import java.lang.*; public class stock_market_client { static ORB orb; /* The orb we'll use */ static NamingContext ncRef; /* The namingContext */ static org.omg.CORBA.Object obj; /* The raw Object */ public static void main(String[] args) { int how_many; /* This many we want */ stock_market.stock_server stock_server_objref; /* We need this for Object Reference */ Properties props = new Properties(); props.put("org.omg.CORBA.ORBInitialHost", "144.16.67.42"); /* The ip address of the m/c */ props.put("org.omg.CORBA.ORBInitialPort", "4000"); /* Port on which nameservice runs */ String[] orbarg = {""}; try{ orb = ORB.init(orbarg, props); /* Initialise the ORB */ /* Resolve the initial reference */ org.omg.CORBA.Object objref = orb.resolve_initial_references("NameService"); /* Narrow the object to NamingContextHelper type */ ncRef = NamingContextHelper.narrow(objref); }catch(Exception e){ System.out.println("Exception at resolve"+e); e.printStackTrace(); } /* If we get here then we have resolved the server */ /* Now try to find the object we want to invoke the method on */ try{ /* Form the NameComponent */ NameComponent nc = new NameComponent("stock_server",""); NameComponent path[] = {nc}; /* Path from the root */ obj = ncRef.resolve(path); /* We got a raw object */ /* Now we'll narrow it down to the kind of object we want*/ stock_server_objref = stock_serverHelper.narrow(obj); /* Now we can invoke the methods on it */ how_many = 6; /* This many we want */ String[] return_script_params = new String[how_many]; /* Want to receive the name of the scripts here */ for(int i=0; i< how_many; i++){ /* Initialise every bit of it !! */ return_script_params[i] = ""; } /* For inout: We have to have a holder */ scriptNameArrayHolder namearray = new scriptNameArrayHolder(return_script_params); /* Invoke */ System.out.println("Going to invoke"); int ret = stock_server_objref.get_script_names(how_many, namearray); /* Now we will see what we've got */ for(int i=0; i< how_many; i++){ /* Initialise every bit of it !! */ System.out.println("Script_name["+i+"]="+ namearray.value[i]); } }catch(ex1 ex){ System.out.println("Caught exception in get_names: " +ex.reason); ex.printStackTrace(); } catch(Exception e){ System.out.println("Caught exception: " +e); e.printStackTrace(); } } }