I want to build an object hierarchy over the CORBA namespace and I tried this tutorial
http://docs.oracle.com/javase/7/docs/technotes/guides/idl/jidlNaming.html
I successfully compiled NameClient.java, started orbd on localhost then ran the test. It failed with the following exception:
java.lang.ClassCastException: org.omg.CosNaming._NamingContextStub cannot be cast to org.omg.CosNaming.NamingContextExt
at NameClient.main(NameClient.java:24)
The source code for the NameClient class:
import java.util.Properties;
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
public class NameClient
{
public static void main(String args[])
{
try {
Properties props = new Properties();
props.put("org.omg.CORBA.ORBInitialPort", "1050");
props.put("org.omg.CORBA.ORBInitialHost", "localhost");
ORB orb = ORB.init(args, props);
NamingContextExt ctx =
NamingContextExtHelper.narrow(orb.resolve_initial_references(
"NameService"));
org.omg.CORBA.Object objref = ctx;
NameComponent name1[] = ctx.to_name("plans");
ctx.rebind(name1, objref);
System.out.println("plans rebind successful!");
NameComponent name2[] = ctx.to_name("Personal");
NamingContextExt ctx2 = (NamingContextExt)ctx.bind_new_context(name2);
System.out.println("New naming context, Personal, added!");
NameComponent name3[] = ctx.to_name("schedule");
ctx2.rebind(name3, objref);
System.out.println("schedule rebind successful!");
NameComponent name4[] = ctx.to_name("calendar");
ctx2.rebind(name4, objref);
System.out.println("calendar rebind successful!");
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
Isn't this example suppose to work ? Any idea how to get passed this error ?
Thank you for helping.