【www.gdgbn.com--js教程】

Below is a simple example of a CORBA program
download the source file
1. produce a idl file like this
   hello.idl
   module HelloApp {
     interface Hello    {
         string sayHello();
    };
  };
2. produce stub and skeleton files through idltojava.exe
   idltojava hello.idl
   idltojava is not include in the jdk. But you can download it from idldojava.
3. write a server program like this
// HelloServer.java
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;
class HelloServant extends _HelloImplBase
{
    public String sayHello()
    {
       return " Hello world !! ";
    }
}
public class HelloServer {
    public static void main(String args[])
    {
    try{
        // create and initialize the ORB
        ORB orb = ORB.init(args, null);
        // create servant and register it with the ORB
        HelloServant helloRef = new HelloServant();
        orb.connect(helloRef);
        // get the root naming context
        org.omg.CORBA.Object objRef =
        orb.resolve_initial_references("NameService");
        NamingContext ncRef = NamingContextHelper.narrow(objRef);

本文来源:http://www.gdgbn.com/wangyezhizuo/5598/