国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Beans入門必讀之經(jīng)典EJB例子代碼

2019-11-18 12:34:29
字體:
供稿:網(wǎng)友

  rmi-iiop ejb客戶端例子
  
  A java RMI-IIOP client with a PRoprietary EJB server.
  
  package com.wiley.compBooks.roman.corba.helloworld;
  import javax.ejb.*;
  import javax.naming.*;
  import javax.rmi.*;
  import java.util.Properties;
  import javax.transaction.UserTransaction;
  /**
  * This class is an example of client code that invokes
  * methods on a simple stateless session bean.
  */
  public class RMIClient {
  public static void main(String[] args) {
  try {
  /*
  * Get System properties for JNDI initialization
  */
  Properties props = System.getProperties();
  /*
  * Use JNDI to look up the home object
  */
  Context ctx = new InitialContext(props);
  HelloHome home = (HelloHome)
  javax.rmi.PortableRemoteObject.narrow(
  ctx.lookup("HelloHome"),
  HelloHome.class);
  /*
  * Use JNDI to look up the JTA
  * UserTransaction interface
  */
  UserTransaction userTran = (UserTransaction)
  ctx.lookup("javax.transaction.UserTransaction");
  /*
  * Start the transaction
  */
  userTran.begin();
  /*
  * Use the home object to create the Hello EJB Object
  */
  Hello hello = home.create();
  /*
  * Call the hello() method, and print it
  */
  System.out.println(hello.hello());
  /*
  * Done with EJB Object, so remove it
  */
  hello.remove();
  /*
  * Commit the transaction
  */
  userTran.commit();
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
  }
  Example RMI-IIOP EJB client
  
  
  A CORBA client with a CORBA-based EJB server.
  package com.wiley.compBooks.roman.corba.helloworld;
  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.
  *
  * A more portable way to do this is:
  *
  * Properties p = new Properties();
  * p.put("org.omg.CORBA.ORBClass", <..ORB class..>);
  * org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, p);
  */
  org.omg.CORBA.ORB orb = com.inprise.ejb.Global.orb();
  /*
  * 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);
  }
  }

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 株洲县| 麦盖提县| 吴桥县| 三门县| 呈贡县| 乐山市| 桑植县| 东辽县| 简阳市| 滨海县| 彭山县| 临湘市| 比如县| 孟村| 阳谷县| 东乡族自治县| 资中县| 大同市| 石景山区| 蒲江县| 大厂| 光山县| 东莞市| 太康县| 镇安县| 锦屏县| 建瓯市| 白河县| 秦皇岛市| 海城市| 布拖县| 玉山县| 犍为县| 无棣县| 长乐市| 嘉荫县| 新竹县| 湖南省| 文登市| 黄浦区| 兴安县|