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

首頁 > 學院 > 開發設計 > 正文

JBoss技術支持文檔(二)

2019-11-18 11:09:42
字體:
來源:轉載
供稿:網友

  1、下載例子源程序

  所有例子的源代碼可以直接從 www.jboss.org進行下載。下載完后放在一個目錄下。下載網址:http://www.jboss.org/docs/manual/files/documentation-example.zip

  1.1 建立 BEAN

  此節主要是建立一個簡單的EJB,可以查看代碼,這個“Interest”例子,是一個簡單無狀態的會話EJB。它的目的是根據說明的利息率,來對借的所有錢計算利息。實際上在整個包代碼中只有一行功能。

  1.2 回顧EJBs

  在我們查看代碼之前,我們先對EJB進行復習一下。在EJB最小類型,也必須有三個類:remote interface, home interface和bean實現類。

  remote interface是會把EJB中方法提供給外邊世界,讓外邊的代碼來進行調用,在這個例子中類名稱是org.jboss.interest.Interrest。

  home interface是治理remote interface類的類。包括建立、刪除等操作。在這個例子中類名稱是org.jboss.interest.InterrestHome。

  bean實現類提供home interface和remote interface所有方法的實現。在這個例子中類名稱是org.jboss.interest.InterrestBean。

  當然一個Bean可能還包括其他類,甚至其他包。但是必須有此三個類,其他類是在此三個類之上建立的。所有類被打包進一個JAR文件,此文件是用一個目錄結構來反映出包的層次關系。在此例子中所有類都打包在org.jboss.interest包中,所以他們需要在目錄org/jboss/interest/下。

  在包含所有類的jar文件建立之前,必須有一個META-INF目錄。此目錄存放了部署描述符(通常叫“ejb-jar.xml”),和可選的其他XML文件。這些文件告訴服務器關于應用明確服務信息。對于JBoss 來講,文件名必須叫“jboss.xml”。

  創建jar文件后部署到JBoss Server上。在客戶端你需要一個jndi.PRoperties文件,此文件告訴你的客戶端程序從哪里初始化查找JNDI 命名服務。從這個服務,客戶端將查找到Interest bean,并且返回bean的home interface。home interface用來得到bean的一個remote interface。它可以用遠程接口來訪問bean提供的商業方法。

  1.3 EJB類

  我們需要三個類:remote interface, home interface 和bean實現類。remote interface遠程接口類,文件名Interest.java。代碼如下:

package org.jboss.docs.interest;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
/**
This interface defines the `Remote' interface for the `Interest' EJB. Its
single method is the only method eXPosed to the outside world. The class
InterestBean implements the method.
*/
public interface Interest extends EJBObject
{
/** Calulates the compound interest on the sum `principle', with interest rate per period `rate' over `periods' time periods. This method also prints a message to standard output; this is picked up by the EJB server and logged. In this way we can demonstrate that the method is actually being executed on the server, rather than the client. */

public double calculateCompoundInterest(double principle, double rate, double periods) throws RemoteException;

}
  遠程接口只有一個商業方法calculateCompoundInterest。Home interface 文件名InterestHome.java。代碼如下:

package org.jboss.docs.interest;
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;

/**
This interface defines the 'home' interface for the 'Interest' EJB.
*/
public interface InterestHome extends EJBHome
{
/** Creates an instance of the `InterestBean' class on the server, and returns a remote reference to an Interest interface on the client. */
Interest create() throws RemoteException, CreateException;
}
  最后我們給出bean實現類,文件名稱:InterestBean.java。代碼如下:



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上林县| 隆林| 涞源县| 西吉县| 永清县| 马关县| 邢台县| 京山县| 安龙县| 山丹县| 华阴市| 井陉县| 汤原县| 库尔勒市| 焉耆| 治多县| 京山县| 华宁县| 蚌埠市| 吴堡县| 额济纳旗| 鲁山县| 梓潼县| 搜索| 辽阳县| 灵宝市| 卫辉市| 宁城县| 梓潼县| 阿巴嘎旗| 西丰县| 渝北区| 罗江县| 博乐市| 万州区| 泸州市| 郴州市| 尤溪县| 东乌珠穆沁旗| 鞍山市| 额敏县|