import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; public class gradimpl extends student implements gradOperations { public String thesistopic () { return "middleware"; } public void thesistopic (String newThesistopic) {} public gradPOATie tie; // the tie objects that extends // can't have this here: who is "this"? must be the tie! public org.omg.CORBA.Object accept (studentvisitor visitor) { return visitor.visitg(new gradHolder(tie._this())); } // 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 gradPOATie maketie(POA p) { gradPOATie tie1; gradimpl impl = new gradimpl(); try { tie1 = new gradPOATie(impl,p); // p? impl.tie = tie1; } catch (org.omg.CORBA.SystemException ee) {ee.printStackTrace();} return impl.tie; } // maketie public int f() {return 2; } 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 gradPOATie student1 = maketie(rootpoa); org.omg.CORBA.Object objref1 = rootpoa.servant_to_reference(student1); NameComponent[] path1 = { new NameComponent("student3","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 }