Java CORBA入门

王朝java/jsp·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

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", "");

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航