import java.io.*; import org.omg.CORBA.*; import corbasem.gen.calcsimpl.*; public class SimpleCalcClient { public static void main(String [] args) throws IOException { // simple status of our server int svrStatus = 0; org.omg.CORBA.ORB orb = null; try { // Some of the Java ORBs will you various // system properties to ensure correct // java environement. java.util.Properties props = System.getProperties(); // Set some properties that will define which // class will act as our ORBClass and ORBSingleton. // This information could be pass as command // line arguments. // props.load(new FileInputStream("..\\ORBinit.properties")); props.put("org.omg.CORBA.ORBClass", "com.ooc.CORBA.ORB"); props.put("org.omg.CORBA.ORBSingletonClass", "com.ooc.CORBA.ORBSingleton"); // initialize the ORB orb = ORB.init(args, props); svrStatus = callsvr(orb); // Since the standard ORB.destroy() method is not present in // JDK 1.2.x, we must cast to com.ooc.CORBA.ORB so that this // will compile with all JDK versions. This will also // destroy our server portability. We could get around // this problem by using the -Xbootclasspath compile switch // or use JDK 1.3.x. ((com.ooc.CORBA.ORB)orb).destroy(); // orb.destroy(); } catch (Exception e) { System.err.println("main() ERROR: " + e); e.printStackTrace(System.out); svrStatus = 1; } System.out.println("SimpleCalcClient status = " + svrStatus); System.out.println("SimpleCalcClient shutdown!"); System.exit(svrStatus); } static int callsvr(org.omg.CORBA.ORB orb) { try { System.out.println("Getting reference from string..."); BufferedReader in = new BufferedReader( new FileReader("calcref.ior") ); String ior = in.readLine(); in.close(); calculator calc = calculatorHelper.narrow(orb.string_to_object(ior)); System.out.println("Calling into the server"); System.out.println( calc.add(2,3) ); return 0; } catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); return 1; } } }