程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA編程入門知識 >> Java CORBA入門

Java CORBA入門

編輯:JAVA編程入門知識

  Below is a simple example of a CORBA program
  download the source file 
  
  <b>1. prodUCe a idl file like this</b>
     hello.idl
     module HelloApp {
       interface Hello    {         
           string sayHello();
      };
    };
  
  <b>2. produce stub and skeleton files through idltoJava.exe</b>
     idltojava hello.idl
     idltojava is now named as idlj.exe and is included in the JDK. 
  
  <b>3. write a server program like this </b>
  
  // 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);
  
       // bind the Object Reference in Naming
       NameComponent nc = new NameComponent("Hello", "");
 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved