import corbasem.gen.calcsimpl.*; import java.io.*; import org.omg.CORBA.*; // the interface implementation // also know as the 'servant' class SimpleCalcServant extends calculatorPOA { public int add(int x, int y) { return x + y; } } public class SimpleCalcSvr { public static void main(String args[]) { // 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 = runsvr(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("runsvr() ERROR: " + e); e.printStackTrace(System.out); } System.out.println("SimpleCalcSvr status = " + svrStatus); System.out.println("SimpleCalcSvr shutdown!"); System.exit(svrStatus); } static int runsvr(org.omg.CORBA.ORB orb) throws org.omg.CORBA.UserException { try { // setup the Portable Object Adapter // from the always present rootPOA org.omg.PortableServer.POA rootPOA = org.omg.PortableServer.POAHelper.narrow( orb.resolve_initial_references("RootPOA")); org.omg.PortableServer.POAManager manager = rootPOA.the_POAManager(); // create servant SimpleCalcServant calcSvt = new SimpleCalcServant(); calculator calc = calcSvt._this(orb); // write the object reference to a file PrintWriter refstr = new PrintWriter( new FileWriter("calcref.ior")); refstr.println(orb.object_to_string(calc)); refstr.close(); // make the implementation available manager.activate(); System.out.println("SimpleCalcSvr is running!"); orb.run(); return 0; } catch (Exception e) { System.err.println("runsvr() ERROR: " + e); e.printStackTrace(System.out); return 1; } } }