corbaclient.java

来自「精通EJB3.0一书的全部随书实例的源代码。」· Java 代码 · 共 73 行

JAVA
73
字号
package examples;

import java.util.*;
import org.omg.CosNaming.*;

// if your ORB does not support CosTransactions, comment
// out this line:
import org.omg.CosTransactions.*;

public class CORBAClient 
{   
    public static void main(String[] args) 
        throws Exception 
    {
        /*
         * Initialize the ORB.
         */
        org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);

        /*
         * 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.  If your ORB does not support
         * CosTransactions, comment out the following line:
         */
        Current currentTX = CurrentHelper.narrow
            (orb.resolve_initial_references("TransactionCurrent"));

        /*
         * Begin the transaction.
         * If your ORB does not support CosTransactions, comment
         * out the following line:
         */
        currentTX.begin();

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

        /*
         * Call a business method. Note trailing '_' in the method name,
         * which was introduced by the Java-to-IDL mapping rules:
         */
        System.out.println(hello.hello_()); 

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

        /*
         * Commit the transaction
         * If your ORB does not support CosTransactions, comment
         * out the following line:
         */
        currentTX.commit(true);
    }
}

⌨️ 快捷键说明

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