import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; public class undergradimpl extends student implements undergradOperations { public String major () { return "computer science"; } public void major (String newMajor) {} public undergradPOATie tie; // the tie objects that extends // undergradPOA. public org.omg.CORBA.Object tieobj; // can't have this here: who is "this"? must be the tie! public org.omg.CORBA.Object accept (studentvisitor visitor) { undergrad u = undergradHelper.narrow(tieobj); return visitor.visitu(new undergradHolder(u)); } // function to hide the process of creating a tie delegate. // the server consists now of two objects. This gets around the // problem of lack of multiple inheritance in java. // This version makes tie and delegate point to eachother public static undergradPOATie maketie(POA p) { undergradPOATie tie1; undergradimpl impl = new undergradimpl(); try { tie1 = new undergradPOATie(impl,p); // p? impl.tie = tie1; impl.tieobj = p.servant_to_reference(impl.tie); } catch (org.omg.CORBA.SystemException ee) {ee.printStackTrace();} catch (org.omg.PortableServer.POAPackage.ServantNotActive e2) {e2.printStackTrace();} catch (org.omg.PortableServer.POAPackage.WrongPolicy e3) {e3.printStackTrace();} return impl.tie; } // maketie public int f() { return 1; } 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 undergradPOATie student1 = maketie(rootpoa); undergradPOATie student2 = maketie(rootpoa); org.omg.CORBA.Object objref1 = rootpoa.servant_to_reference(student1); org.omg.CORBA.Object objref2 = rootpoa.servant_to_reference(student2); NameComponent[] path1 = { new NameComponent("student1","Object") }; NameComponent[] path2 = { new NameComponent("student2","Object") }; ncref.rebind(path1,objref1); // actual registration ncref.rebind(path2,objref2); // actual registration // now wait for client invocation System.out.println("waiting for client call..."); myorb.run(); } catch (Exception e) {e.printStackTrace();} } // main }