<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 51, comments - 17, trackbacks - 0, articles - 9
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    簡單的EJB 及其部署文件

    Posted on 2007-02-27 22:51 chenweicai 閱讀(387) 評論(0)  編輯  收藏

    三個基本class
    EJB最少也需要三個class, remote interface, home interface, and bean implementation(bean行為).

    1. remote interface 用來揭示EJB對外的一些方法.在這個例子中,the remote interface 就是org.jboss.docs.interest.Interest.

    ackage 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
    {
      public double calculateCompoundInterest(double principle,
          double rate, double periods) throws RemoteException;
    }

    ?

    2.home interface 是用來規定怎樣創建一個實現remote interface的bean. 在本例中home interface 是 org.jboss.docs.InterestHome.

    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;
    }


    3.bean implementation 是提供方法的實現,這些方法在上述兩種interface中都有規定了,在本例中是兩個方法: calculateCompoundInterest和create().

    這個bean implementation 是 org.jboss.docs.interest.InterestBean.

    package org.jboss.docs.interest;

    import java.rmi.RemoteException;
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;

    /**
    This class contains the implementation for the `calculateCompoundInterest'
    method exposed by this Bean. It includes empty method bodies for the methods
    prescribe by the SessionBean interface; these don't need to do anything in this
    simple example.
    */
    public class InterestBean implements SessionBean
    {
      
      public double calculateCompoundInterest(double principle,
        double rate, double periods)
      {
        System.out.println("Someone called `calculateCompoundInterest!'");
        return principle * Math.pow(1+rate, periods) - principle;
      }

      /** Empty method body
      */
      public void ejbCreate()
      {}

      /** Every ejbCreate() method ALWAYS needs a corresponding
      ejbPostCreate() method with exactly the same parameter types.
      */
      public void ejbPostCreate()
      {}

       /** Empty method body
      */
      public void ejbRemove()
      {}
      /** Empty method body
      */
      public void ejbActivate()
      {}

      /** Empty method body
      */
      public void ejbPassivate()
      {}
      /** Empty method body
      */
      public void setSessionContext(SessionContext sc)
      {}
    }


    ?

    這些classes必須打包進一個JAR文件中,JAR文件中包含了目錄結構和包的層次.在本例中,這些classes是在包org.jboss.docs.interest, 這樣他們需要在目錄org/jboss/docs/interest/ 下.

    部署發布描述器ejb-jar.xml和jboss.xml
    在JAR文檔創建之前,還需要一個叫META-INF的目錄,這是存放部署發布描述器的(一般叫ejb-jar.xml).大部分商用EJB Server提供圖形化工具來編輯這個 描述器.在JBoss中需要手工:

    <?xml version="1.0" encoding="UTF-8"?>

    <ejb-jar>
      <description>JBoss Interest Sample Application</description>
      <display-name>Interest EJB</display-name>
      <enterprise-beans>
      <session>
        <ejb-name>Interest</ejb-name>

          <!-- home interface -->
          <home>org.jboss.docs.interest.InterestHome</home>

          <!-- remote interface -->
          <remote>org.jboss.docs.interest.Interest</remote>

          <!-- bean implementation -->
          <ejb-class>org.jboss.docs.interest.InterestBean</ejb-class>

          <!--bean 的類型 這里是Stateless -->
          <session-type>Stateless</session-type>
          <transaction-type>Bean</transaction-type>
      </session>
      </enterprise-beans>
    </ejb-jar>

    在本例中,一個包中只有一個EJB 這樣就不用描述多個EJB之間是怎樣交互的.

    盡管對于所有的EJB服務器,ejb-jar.xml部署描述器的格式是一樣的(更多精確的定義可以從sun得到DTD).它并沒有規定所有的必須的信息,比如如何將EJB-NAME和JNDI naming service聯系起來.

    缺省情況下,JNDI name將使用在ejb-jar.xml中<ejb-name>XXX</ejb-name>中的XXX來使用EJB的home interface.

    但是如果有多個EJB,在ejb-jar.xml中,在<ejb-name>XXX</ejb-name>中XXX就不能用同一個名字了,一般格式是"[application name]/[bean name]".

    那么如果再按照缺省情況,JNDI name就可能找不到你的應用程序的入口了,因此我們要特別規定一下.這就需要在jboss.xml中規定:

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss>
      <enterprise-beans>
        <session>
          <ejb-name>Interest</ejb-name>
          <jndi-name>interest/Interest</jndi-name>
        </session>
      </enterprise-beans>
    </jboss>

    這樣,你所有叫Interest文件都被梆定到JNDI name:interest/Interest下面

    jndi.properties
    雖然有了上面你的應用程序和JNDI name的梆定,但是一旦部署發布到JBoss服務器上,你還需要一個jndi.properties文件,以告訴調用你程序的客戶端請求到哪里去初始化JNDI naming service.

    ?

    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.provider.url=localhost:1099
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

    ?

    在本例中,客戶端請求將尋找Interest 這個bean, 然后得到這個bean的home interface. home interface是用來得到這個bean的remote interface.最后,客戶端請求將通過remote interface來使用由EJB提供的功能.


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 激情内射亚洲一区二区三区爱妻| 亚洲国产成人久久综合碰| 亚洲va中文字幕无码久久不卡| 国产亚洲精品美女| 免费又黄又硬又爽大片| 一区二区亚洲精品精华液| 毛片免费在线视频| 亚洲精品无码你懂的| 免费a在线观看播放| 一级全免费视频播放| 亚洲国产精品成人AV无码久久综合影院| 欧洲亚洲综合一区二区三区| 在线a亚洲v天堂网2018| eeuss免费影院| 亚洲AV无码一区二区乱子伦| 免费女人高潮流视频在线观看 | 亚洲AV午夜成人片| 一区国严二区亚洲三区| 一级特黄特色的免费大片视频| 亚洲日韩VA无码中文字幕| 免费萌白酱国产一区二区三区| 国产亚洲精品一品区99热| 亚洲国产精品免费在线观看| 亚洲 欧洲 视频 伦小说| 免费成人av电影| 免费无码又爽又刺激网站直播 | 最好2018中文免费视频| 自拍偷自拍亚洲精品第1页| 99视频在线看观免费| 亚洲AV无码专区在线观看成人| 亚洲国产精品激情在线观看| 鲁丝片一区二区三区免费| 亚洲人成网网址在线看| 亚洲国产91精品无码专区| 亚洲视频在线观看免费| 亚洲乱理伦片在线观看中字| 亚洲日韩乱码中文无码蜜桃臀网站 | 中文字幕免费播放| 亚洲国产视频一区| 亚洲成年人啊啊aa在线观看| 日韩免费电影网站|