import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; public class printer extends printvisitorPOA { public org.omg.CORBA.Object visitu (undergradHolder u) { undergrad ug = u.value; System.out.println(ug.name()+" is an undergrad"); // now, need to typecast "this" to a studentvisitor: // this is a printvisitorPOA, extends studentvisitorPOA, // which includes the _this() function if (ug.next() != null) ug.next().accept(this._this()); // this is it! return ug; } public org.omg.CORBA.Object visitg (gradHolder g) { System.out.println(g.value.name()+" is a graduate student"); if (g.value.next() !=null) g.value.next().accept(this._this()); return g.value; } public static void main(String[] args) { try { // initialize local ORB ORB myorb = ORB.init(args,null); // initialize portable Object Adapter, glue to ORB POA rootpoa = (POA)myorb.resolve_initial_references("RootPOA"); rootpoa.the_POAManager().activate(); // Register objref with name service (similar to registry) org.omg.CORBA.Object nsobjref = myorb.resolve_initial_references("NameService"); //narrowing = CORBA type casting: NamingContext ncref = NamingContextHelper.narrow(nsobjref); // create instance of server object, call POA to convert to objref printer server = new printer(); org.omg.CORBA.Object objref1 = rootpoa.servant_to_reference(server); NameComponent[] path1 = { new NameComponent("printer","Object") }; ncref.rebind(path1,objref1); // actual registration // now wait for client invocation System.out.println("waiting for client call..."); myorb.run(); } catch (Exception e) {e.printStackTrace();} } // main }