Chinaunix首页 | 论坛 | 博客
  • 博客访问: 871695
  • 博文数量: 322
  • 博客积分: 6688
  • 博客等级: 准将
  • 技术积分: 3626
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-19 11:26
文章分类

全部博文(322)

文章存档

2013年(5)

2012年(66)

2011年(87)

2010年(164)

分类: Java

2010-11-04 18:17:09

先编一个idl文件,如:person.idl
  module person{
  interface hand{
  int add(int x,int y);
  }
  }
  然后用idl2java.exe文件编译person.idl文件
  idl2java person.idl
  产生一个目录person
  里面有一个文件hand.java,这里定义了一个接口interface hand
  应该编一个类去实现这个接口handImpl.java
  public class handImpl extends _handImplBase implements
  hand{
  int x,y;
  public handImpl(){
  x=0;
  y=0;
  }
  int add(int x,int y){
  this.x=x;
  this.y=y;
  return (x+y);
  }
  }
  总之在handImpl中实现各种功能。
  
  接下来讲端编程:Server.java
  package person;
  public class Server{
  public static void main(String[] argv){
  org.omg.CORBA.ORB
  orb=org.omg.CORBA.ORB.init(args,null);
  org.omg.CORBA.BOA boa=orb.BOA_init();
  person.hand p=new
  person.handImpl("Person.hand");
  boa.obj_is_ready(p);
  System.out.pritnln(p+ " is ready.");
  boa.impl_is_ready();
  }
  }
  如果路径设置对的话,用命令java Server就行了,不过要先运行smart
  agent
  
  public class Client{
  org.omg.CORBA.ORB orb;
  person.hand p;
  public static void main(String[] argv){
  Client app=new Client();
  orb=org.omg.CORBA.ORB.init(args,null);
  
  p=person.handHelper.bind(orb,"Person.hand");
  int result=p.add(20,30);
  System.our.pritnln(result);
  }
  }
  编译用命令javac person\*.java
阅读(641) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-11-05 14:41:14

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com