corbaclient.java

来自「一本关于EJB的书」· Java 代码 · 共 63 行

JAVA
63
字号
import java.util.*;
import org.omg.CosNaming.*;
import org.omg.CosTransactions.*;

public class CORBAClient {

  public static void main(String[] args) throws Exception {

    /*
     * Initialize the ORB.
     */
    Properties p = new Properties();
    p.put("org.omg.CORBA.ORBClass", <..Your ORB class..>);
    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, p);

    /*
     * Get a reference to a naming context
     */
    NamingContext context = NamingContextHelper.narrow
        (orb.resolve_initial_references("NameService"));

    /*
     * Look up the home object using COS Naming
     */
    NameComponent[] names = { new NameComponent("HelloHome", "") };
    HelloHome helloHome = HelloHomeHelper.narrow
        (context.resolve(names));

    /*
     * Get the CORBA OTS Current interface for
     * controlling transactions
     */
    Current currentTX = CurrentHelper.narrow
        (orb.resolve_initial_references("TransactionCurrent"));

    /*
     * Begin the transaction
     */
    currentTX.begin();

    /*
     * Use the home object to create an EJB object
     */
    Hello hello = helloHome.create();

    /*
     * Call a business method
     */
    System.out.println(hello.hello());

    /*
     * Remove the EJB object
     */
    hello.remove();

    /*
     * Commit the transaction
     */
    currentTX.commit(true);
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?