• 网站首页
  • 涉税提问
  • 财税法规
  • 税收筹划
  • 优惠政策
  • 案例解析
  • 培训中心
  • 财富工具
  • 房产专题
  • 会计范文
中财税帮助

去向导航

  • 常见问题
  • 费用核算
  • 负债核算
  • 会计报表
  • 利润核算
  • 收入核算
  • 外汇核算
  • 资本核算
  • 资产核算
  • 更多...

常用分类

  • 浏览器
  • Windows
  • 音乐/电影
  • 网站开发
  • 游戏
  • 办公自动化

中财税帮助系统

2008-11-21

欢迎您登陆并使用中国财税咨询中心为您免费提供的资料,交流,学习为一体的平台!

如果您在使用中遇到什么问题,请您不要吝啬,一定要写信给我们!!

Email:Shellapi@126.com 期待您的来信,或指导批语!

帮助内难免有收集的资料,如果侵犯了您的仅力,请您来信告知,我们马上删除或更新处理!

文章搜索--请输入关键词:

CORBA例子(转)————————我也不知道是什麽东东:-)

更多2008-11-21 日更新内容!
    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 "\nHello world !!\n";
        }   
      
    }

    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", "");
            NameComponent path[] = {nc};
            ncRef.rebind(path, helloRef);

            // wait for invocations from clients
                java.lang.Object sync = new java.lang.Object();
                synchronized (sync) {
                    sync.wait();
                }

        } catch (Exception e) {
            System.err.println("ERROR: " + e);
            e.printStackTrace(System.out);
        }
        }
    }    

    4. write a client program like this
    // HelloClient.java
    import HelloApp.*;
    import org.omg.CosNaming.*;
    import org.omg.CORBA.*;

    public class HelloClient
    {
        public static void main(String args[])
        {
        try{
            // create and initialize the ORB
            ORB orb = ORB.init(args, null);

                // get the root naming context
                org.omg.CORBA.Object objRef =
            orb.resolve_initial_references("NameService");
                NamingContext ncRef = NamingContextHelper.narrow(objRef);
                // test
                System.out.println("OK..");                
                // resolve the Object Reference in Naming
                NameComponent nc = new NameComponent("Hello", "");
                NameComponent path[] = {nc};
                Hello helloRef = HelloHelper.narrow(ncRef.resolve(path));

            // call the Hello server object and print results
               //String oldhello = helloRef.lastMessage();
               //System.out.println(oldhello);
            String Hello = helloRef.sayHello();
            System.out.println(Hello);

        } catch (Exception e) {
            System.out.println("ERROR : " + e) ;
            e.printStackTrace(System.out);
        }
        }
    }

    5. complie these files

       javac *.java HelloApp/*.java

    6. run the application
       
      a. first you've to run the Name Service prior to the others likethis
         c:\>tnameserv
      b. run server
         c:\>java HelloServer
      c. run client
         c:\>java HelloClient

    If you have problems with this example, do let me know!
Site designed by 中国财税咨询中心