Enterprise Beans and the EJB JAR File


Enterprise JavaBeans use the JAR file format to package enterprise beans. The EJB JAR file is used to package un-assembled enterprise beans and to package assembled beans. Un-assembled enterprise beans have only generic information created by the bean developer. Assembled enterprise beans have information for a particular environment stored in the deployment descriptor by the application assembler. Basically, there are different roles for building and deploying enterprise beans. In this book, we are both the bean provider and the application assembler (in addition to the deployer and the administrator). However, the techniques we present can be adapted to situations in which assembling and deploying are performed by separate organizations.

Like the Web application WAR file, the EJB JAR file has a deployment descriptor. It is stored in the META-INF directory in a file called ejb-jar.xml. This deployment descriptor contains the following information:

  • Structural information for an Enterprise Bean:

    • Name

    • Class type

    • Home interface

    • Remote interface

    • Bean type (session or entity)

    • Reentrancy indication

    • State management information (stateful session)

    • Persistence management information (container managed persistence [CMP] entity)

    • Primary key class (entity)

    • Container managed fields (CMP entity)

    • Environment entries (accessible via JNDI)

    • Resource manager connection factory references

    • References to other EJBs

    • Security role references

  • Application assembly information:

    • Binding of Enterprise bean references

    • Security roles

    • Method permissions

    • Linking of security roles

    • Transaction attributes for beans and methods

The following listing is an example of an EJB deployment descriptor; it s based on an example in chapter 6.

 <ejb-jar> <description> This ejb-jar file contains the Enterprise beans for the  Model 2 Hello World application. </description> <ejb-client-jar>client-greet-ejbs.jar</ejb-client-jar> <enterprise-beans>     <entity>         <description>             The GreetingEntityBean is a do nothing bean to demonstrate             how to deploy an Enterprise bean with Ant.         </description>         <ejb-name>GreetingEntityBean</ejb-name>         <home>xptoolkit.ejbs.GreetingEntityHome</home>         <remote>xptoolkit.ejbs.GreetingEntityRemote</remote>         <ejb-class>xptoolkit.ejbs.GreetingEntityBean</ejb-class>         <transaction-type>Container</transaction-type>         <reentrant>True</reentrant>         <prim-key-class>java.lang.Integer</prim-key-class>         <persistence-type>Bean</persistence-type>     </entity>     <session>         <description>             The GreetingSessionBean is a do nothing bean to demonstrate             how to deploy an Enterprise bean with Ant.         </description>         <ejb-name>GreetingSessionBean</ejb-name>         <home>xptoolkit.ejbs.GreetingSessionHome</home>         <remote>xptoolkit.ejbs.GreetingSessionRemote</remote>         <ejb-class>xptoolkit.ejbs.GreetingSessionBean</ejb-class>         <session-type>Stateful</session-type>         <transaction-type>Container</transaction-type>         <ejb-ref>             <description>                 This sets up a references from the Entity bean to the  session bean.                 Thus, the session bean can look up the Entity bean in                  its environment space.             </description>             <ejb-ref-name>ejb/GreetingEntityBean</ejb-ref-name>             <ejb-ref-type>Entity</ejb-ref-type>             <home>xptoolkit.ejbs.GreetingEntityHome</home>             <remote>xptoolkit.ejbs.GreetingEntityRemote</remote>             <ejb-link>GreetingEntityBean</ejb-link>         </ejb-ref>     </session> </enterprise-beans> <assembly-descriptor>     <container-transaction>         <method>             <ejb-name>GreetingSessionBean</ejb-name>             <method-name>*</method-name>         </method>         <trans-attribute>Supports</trans-attribute>     </container-transaction>     <container-transaction>         <method>             <ejb-name>GreetingEntityBean</ejb-name>             <method-name>*</method-name>         </method>         <trans-attribute>Supports</trans-attribute>     </container-transaction> </assembly-descriptor> </ejb-jar> 

This listing defines two enterprise beans: GreetingSessionBean and GreetingEntityBean. The session bean has a reference to the entity bean. We ll explain this example in more detail in chapter 6. Notice that the enterprise-bean element defines entity and session sub-elements. The entity and session elements contain references to the remote, home, and bean classes. These classes are defined in the root of the bean class just like classes of a regular JAR file. For example, the directory structure of the EJB file described in the previous listing may look like this:

 EJB Jar File root    client-greet-ejbs.jar +---META-INF        MANIFEST.MF        ejb-jar.xml \---xptoolkit          \---ejbs             GreetingEntityBean.class             GreetingEntityHome.class             GreetingEntityRemote.class             GreetingSessionBean.class             GreetingSessionRemote.class             GreetingSessionHome.class 

This example is based on one presented in chapter 6. For more information about EJB JAR files and EJB deployment descriptors, refer to the official EJB specifications online at http://java.sun.com/products/ejb/ .




Professional Java Tools for Extreme Programming
Professional Java Tools for Extreme Programming: Ant, XDoclet, JUnit, Cactus, and Maven (Programmer to Programmer)
ISBN: 0764556177
EAN: 2147483647
Year: 2003
Pages: 228

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net