This appendix does not contain general information on creating or using XML; for more information on XML, consult a commercially available book.
An XML file, which is a standard ASCII file, can be created manually or by using the graphical user interface (GUI) of the jetace tool. Once created, the XML file can be used to create an EJB JAR file from the command line by using the jetace tool. For more information, see Creating an EJB JAR file for an enterprise bean.
An XML-based deployment descriptor must contain the following major components:
Every XML-based deployment descriptor must have the standard header tag, which defines the XML version and the standalone status of the XML file. For enterprise beans, these properties must be set to the values shown in Figure 121. Except for the header tag, which must be the first tag in the file, the remaining content of the XML file must be enclosed in opening and closing EJB JAR tags.
Figure 121. Code example: The standard header and EJB JAR tags
<?xml version='1.0' standalone='yes' ?> <ejb-JAR> <!-- Content of the XML file --> ... </ejb-JAR> |
The input file tag identifies the JAR or ZIP file or the directory containing the required components of one or more enterprise beans. The output file tag identifies the EJB JAR file to be created; by default a JAR file is created, but you can force the creation of a ZIP file by adding a .zip extension to the output file name. The input and output files for the example Account bean are shown in Figure 122.
Figure 122. Code example: The input file and output file tags
<?xml version='1.0' standalone='yes' ?> <ejb-JAR> <input-file>AccountIn.jar</input-file> <output-file>Account.jar</output-file> ... </ejb-JAR> |
If you are creating a deployment descriptor for an entity bean, you must use an entity bean tag. The entity bean open tag must contain a dname attribute, which must be set to the fully qualified name of the deployment descriptor associated with the entity bean.
Between the open and close entity bean tags, you must create the following entity bean-specific attribute tags:
In addition to the entity bean-specific tags, you must create the tags required by all enterprise beans described in Creating tags used by all enterprise beans.
Figure 123 shows the entity bean-specific tags for the example Account bean.
Figure 123. Code example: The entity bean-specific tags
<?xml version='1.0' standalone='yes' ?> <ejb-JAR> <input-file>AccountIn.jar</input-file> <output-file>Account.jar</output-file> ... <entity-bean dname="com/ibm/ejs/doc/account/Account.ser"> <primary-key>com.ibm.ejs.doc.account.AccountKey</primary-key> <re-entrant value=false/> <container-managed>accountId</container-managed> <container-managed>type</container-managed> <container-managed>balance</container-managed> <!--Other tags used by all enterprise beans--!> ... </entity-bean> ... </ejb-JAR> |
If you are creating a deployment descriptor for an session bean, you must use a session bean tag. The session bean open tag must contain a dname attribute, which must be set to the fully qualified name of the deployment descriptor associated with the session bean. Between the open and close session bean tags, you must also create the following session bean attribute tags:
In addition to the session bean-specific tags, you must create the tags required by all enterprise beans described in Creating tags used by all enterprise beans.
Figure 124 shows the session bean tags for the example Transfer bean.
Figure 124. Code example: The session bean-specific tags
<?xml version='1.0' standalone='yes' ?> <ejb-JAR> <input-file>TransferIn.jar</input-file> <output-file>Transfer.jar</output-file> ... <session-bean dname="com/ibm/ejs/doc/transfer/Transfer.ser"> <session-timeout>0<\session-timeout> <state-management>STATELESS_SESSION<\state-management> <!--Other tags used by all enterprise beans--!> ... </session-bean> ... </ejb-JAR> |
The following tags are used by all types of enterprise beans. These tags must be placed between the appropriate set of opening and closing session or entity bean tags in addition to the tags that are specific to those types of beans.
Figure 125 shows the enterprise bean tags for the example Transfer bean. A similar set is required by the Account bean.
Figure 125. Code example: The tags used for all enterprise beans
<?xml version='1.0' standalone='yes' ?> <ejb-JAR> <input-file>TransferIn.jar</input-file> <output-file>Transfer.jar</output-file> ... <session-bean dname="com/ibm/ejs/doc/transfer/Transfer.ser"> <!--Session bean-specific tags --!> ... <remote-interface>com.ibm.ejs.doc.transfer.Transfer</remote-interface> <enterprise-bean>com.ibm.ejs.doc.transfer.TransferBean</enterprise-bean> <JNDI-name>Transfer </JNDI-name> <transaction-attr value="TX_REQUIRED"/> <isolation-level value="SERIALIZABLE"/> <run-as-mode value="CLIENT_IDENTITY"/> <dependency>com/ibm/ejs/doc/account/InsufficientFundsException.class</dependency> ... <env-setting name="ACCOUNT_NAME">Account<env-setting> ... </session-bean> ... </ejb-JAR> |
If you want to override the enterprise bean-wide transaction or security attribute for particular method in that bean, you must use the <method-control> tag. Between the open and close tags, you must identify the method with the <method-name> tag and the method's parameter types by using the <parameter> tag. In addition, the following tags can used to identify those attribute values that are different in the method from the enterprise bean as a whole: <transaction-attr>, <isolation-level>, <run-as-mode>, and <run-as-id>.
For example, the XML shown in Figure 126 is required to override the transaction attribute of the Transfer bean (TX_REQUIRED) in the getBalance method to TX_SUPPORTED. Because only the transaction attribute is overridden, the method automatically inherits the values of the <isolation-level> and <run-as-mode> tags from the Transfer bean.
Figure 126. Code example: Method-specific tags
<?xml version='1.0' standalone='yes' ?> <ejb-JAR> <input-file>TransferIn.jar</input-file> <output-file>Transfer.jar</output-file> ... <session-bean dname="com/ibm/ejs/doc/transfer/Transfer.ser"> <!--Session bean-specific tags --!> ... <transaction-attr value="TX_REQUIRED"/> <isolation-level value="SERIALIZABLE"/> <run-as-mode value="CLIENT_IDENTITY"/> ... <method-control> <method-name>getBalance</method-name> <parameter>long</parameter> <transaction-attr value="TX_SUPPORTED"/> </method-control> </session-bean> ... </ejb-JAR> |