XDoclet with EJB

JRun provides integration with XDoclet, an open source tool that generates code and deployment descriptors for EJBs, web applications, and JSP tag libraries.

For EJBs specifically, you can use XDoclet to generate the following:

Using XDoclet with EJBs

You use a combination of jrun.xml attributes and JavaDoc-style comments in the bean implementation to control the processing performed by XDoclet.

To use XDoclet with an EJB:

  1. Create a bean implementation class that contains XDoclet comments. XDoclet comments start with the @ sign. If you want XDoclet to generate a descendant class that contains EJB callback methods (such as ejbPassivate), declare the class as abstract.
  2. Name the EJB using a naming convention supported by the ejbSourceFiles attribute in the XDocletService section of the JRun server's jrun.xml file or add an ejbSourceFiles attribute that covers your EJB's file name. The default naming convention is *Bean.java.
  3. Save the class in a directory that enables XDoclet support. You enable XDoclet support for EJBs by naming a directory in a watchedEJBDirectory attribute of the XDocletService section of the JRun server's jrun.xml file.

    The default directory is server_root/default-ear/default-ejb.

    This directory is commented out by default. You must uncomment the watchedEJBDirectory attribute in the jrun.xml file for XDoclet to watch it. You can also add an unlimited number of directories for JRun to watch.

When you save the source file, JRun generates a descendant bean implementation class, the associated interfaces, and a deployment descriptor. If the directory is an auto-deploy directory, JRun also deploys the EJB.

JRun supports basic XDoclet tags, which generate elements in the ejb-jar.xml file, and JRun-specific XDoclet tags, which generate elements in the jrun-ejb-jar.xml file.

Basic XDoclet tags

Basic XDoclet tags start with the @ejb: prefix. These tags are part of the basic XDoclet architecture. For more information, including a complete list of tags and their parameters, see the XDoclet website at http://xdoclet.sourceforge.net/.

The following table describes the basic XDoclet tags:
Tag
Description
Usage
@ejb:bean
Provides basic EJB information. Parameters include type, name, primkey-field, and cmp-version.
All, although not all parameters apply to all EJB types
Class-level tag
@ejb:home
Provides home interface information. Parameters include extends and remote-class.
Entity and session beans
Class-level tag
@ejb:interface
Provides component interface (remote or local) information. Parameters include extends, remote-class, and local-class.
Entity and session beans
Class-level tag
@ejb:finder
Provides information to define finder methods for the home interface. Parameters include signature and role-name.
Entity beans
Class-level tag
@ejb:select
Provides information to define a select method for the home interface. Parameters include signature and query.
Entity beans (CMP 2.0 only)
Class-level tag
@ejb:pk
Provides information to define a primary key. Parameters include class, package, and extends.
Entity beans
Class-level tag
@ejb:env-entry
Provides information to define an environment entry. Parameters include name, type, and value.
All
Class-level tag
@ejb:resource-ref
Defines a resource reference. Parameters include res-name, res-type, and res-auth.
All
Class-level tag
@ejb:resource-env-ref
Provides a resource environment reference. Parameters include name and type.
All
Class-level tag
@ejb:security-role-ref
Provides a security role reference. Parameters include role-name and role-link.
Entity and session beans
Class-level tag
@ejb:transaction
Specifies transactional behavior. Takes a type parameter that accepts the following values:
  • NotSupported
  • Supports
  • Required
  • RequiresNew
  • Mandatory
  • Never
All
Class-level tag
@ejb:permission
Specifies access to methods in remote and home interfaces.
Entity and session beans
Class-level tag
@ejb:security-identity
Defines whether to use the caller's security identity or whether to use a specific run-as identity. Parameters include descriptions, run-as, and use-caller-identity.
All
Class-level tag
@ejb:interface-method
Specifies whether a method appears in the local or remote interface. Takes a view-type parameter.
Session and entity beans
Method-level tag
@ejb:home-method
Identifies a home method and the interfaces in which it appears.
Session and entity beans
Method-level tag
@ejb:create-method
Identifies an ejbCreate method.
Session and entity beans
Method-level tag
@ejb:transaction
Specifies transactional behavior for a method.
Session and entity beans
Method-level tag
@ejb:permission
Specifies access to a specific method.
Session and entity beans
Method-level tag

JRun-specific XDoclet tags

JRun-specific XDoclet tags start with the @jrun: prefix. The following table describes the JRun-specific XDoclet tags:
Tag
Description
Usage
@jrun:always-dirty
Forces synchronization with the data source at the ends of transactions, even when there has been no change to the entity bean's fields. Specify true or false.
Entity beans
Class-level tag
@jrun:cluster-home
Indicates whether to cluster home objects. The default is True. Use this element to override the default behavior for a specific bean. Specify true or false.
Session and entity beans
Class-level tag
@jrun:cluster-object
Indicates whether to cluster EJB objects. The default is true. Use this element to override the default behavior for a specific bean. Specify true or false.
Session and entity beans
Class-level tag
@jrun:commit-option
Specifies the commit option from Section 10.5.9 and 12.1.9 of the EJB 2.0 specification. Valid values are A, B, and C.
Entity beans
Class-level tag
@jrun:ejb-local-ref
Specifies a mapping between the ejb-ref-name that the bean developer provides and its JNDI name. The deployer provides the actual JNDI name. Parameters include ejb-ref-name and jndi-name.
All
Class-level tag
@jrun:ejb-ref
Specifies a mapping between the ejb-ref-name that the bean developer provides and its JNDI name. The deployer provides the actual JNDI name. Parameters include ejb-ref-name and jndi-name.
All
Class-level tag
@jrun:instance-pool
Specifies the maximum and minimum size parameters for StatelessSessionBean instance pools. This tag requires the maximum-size and minimum-size parameters.
Stateless session beans
Class-level tag
@jrun:jdbc-mappings
Specifies persistence information specific to JRun and not declared in the ejb-jar.xml file. Used to specify the SQL for create, load, store, find and remove methods.
Entity beans
(CMP 1.1 only)
Class-level tag
@jrun:jndi-name
Specifies the JNDI name to which the bean or resource will be bound.
All
Class-level tag
@jrun:message-driven-
destination
Specifies the topic or queue name for an MDB. Takes a name parameter.
Message-driven beans
Class-level tag
@jrun:message-
driven-subscription
Specifies the user ID that JRun uses for durable subscription handling. Takes a client-id parameter.
Message-driven beans
Class-level tag
@jrun:resource- env-ref
Specifies a mapping between the resource-env-name that the bean developer provides and its JNDI name. The deployer provides the actual JNDI name. Parameters include resource-env-ref-name, jndi-name, and mdb-destination.
All
Class-level tag
@jrun:resource-ref
Specifies a mapping between the resource name that the bean developer provides and its JNDI name. The deployer provides the actual JNDI name. Parameters include resource-ref-name, jndi-name, user, and password.
All
Class-level tag
@jrun:timeout
Specifies the number of seconds a stateful session bean can remain idle before it is passivated.
Stateful session beans
Class-level tag
@jrun:tx-domain
Specifies the transaction domain name in which a bean's transactions will take place. Parameters include name, action, and source.
All
Class-level tag
@jrun:jdbc-mapping
Specifies information for a CMP 1.1 operation, such as create, load, and so on. Parameters include name, action, and source.
Entity beans
(CMP 1.1 only)
Method-level tag
@jrun:jdbc-mapping-field
Specifies an EJB variable field corresponding to a column returned by a SELECT statement.
Entity beans
(CMP 1.1 only)
Method-level tag
@jrun:jdbc-mapping-param
Specifies the parameter name and type corresponding to a question mark (?) in the prepared statement. Parameters include name and type.
Entity beans
(CMP 1.1 only)
Method-level tag

Many JRun-specific XDoclet tags map to elements in the jrun-ejb-jar.xml file. For more information on this file, see the online descriptor documentation, available from the JRun documentation home page. For online examples of EJBs that use XDoclet, see the samples JRun server.

XDoclet EJB example

The following example shows a CMP 1.1 entity bean that enables XDoclet support:

package samples.cmp11.xdoclet;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import javax.ejb.FinderException;
import java.util.Collection;
import java.rmi.RemoteException;

/**
 * @ejb:bean type="CMP"
 *           name="Employee"
 *     primkey-field="employeeId"
 *           cmp-version="1.x"
 * @ejb:home remote-class="samples.cmp11.xdoclet.EmployeeHome"
 * @ejb:interface remote-class="samples.cmp11.xdoclet.Employee"
 * @ejb:finder signature="java.util.Collection findAll()"
 * @ejb:finder signature="java.util.Collection findByLastName(String lastName)"
 * @ejb:pk class="java.lang.String"
 * @ejb:transaction type="Required"
 *
 * @jrun:jndi-name Employee
 * @jrun:jdbc-mappings
 */
public class EmployeeBean implements javax.ejb.EntityBean {

    private EntityContext context;
����public String employeeId;
    public String firstName;
    public String lastName;
    public String phone;

    /**
     * @ejb:create-method
     * @jrun:jdbc-mapping name="create"
     *                    source="samples"
     *                 action="INSERT INTO employees (employee_id , first_name ,
                   last_name, phone) VALUES ( ? , ? , ? , ?)"
     * @jrun:jdbc-mapping-param name="employeeId" type="VARCHAR"
     * @jrun:jdbc-mapping-param name="firstName" type="VARCHAR"
     * @jrun:jdbc-mapping-param name="lastName" type="VARCHAR"
     * @jrun:jdbc-mapping-param name="phone" type="VARCHAR"
     */
    public String ejbCreate(String employeeId, String firstName, String lastName, 
String phone) {
        this.employeeId = employeeId;
        this.firstName = firstName;
        this.lastName = lastName;
        this.phone = phone;
        return null;
    }

    public void ejbPostCreate(String employeeId, String firstName, String lastName,
String phone) {
    }

    /**
     * @ejb:interface-method
     * @ejb:persistent-field
     * @ejb:pk-field
     */
    public String getEmployeeId() {
        return employeeId;
    }

    /**
     * @ejb:interface-method
     */
    public void setEmployeeId(String employeeId) {
        this.employeeId = employeeId;
    }

    /**
     * @ejb:interface-method
     * @ejb:persistent-field
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * @ejb:interface-method
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * @ejb:interface-method
     * @ejb:persistent-field
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * @ejb:interface-method
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * @ejb:interface-method
     * @ejb:persistent-field
     */
    public String getPhone() {
        return phone;
    }

    /**
     * @ejb:interface-method
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void setEntityContext(EntityContext context) {
        this.context = context;
    }

    public void unsetEntityContext() {
        this.context = null;
    }

    public void ejbActivate() {��}

    public void ejbPassivate() {��}

    /**
     * @jrun:jdbc-mapping name="load" source="samples"
     *                 action="SELECT employee_id, first_name, last_name, phone
                      FROM employees WHERE employee_id=?"
     * @jrun:jdbc-mapping-param name="employeeId" type="VARCHAR"
     * @jrun:jdbc-mapping-field employeeId
     * @jrun:jdbc-mapping-field firstName
     * @jrun:jdbc-mapping-field lastName
     * @jrun:jdbc-mapping-field phone
     */
    public void ejbLoad() {��}

    /**
     * @jrun:jdbc-mapping name="store" source="samples"
     *                 action="UPDATE employees SET first_name=?, last_name=?,
                      phone=? WHERE employee_id=?"
     * @jrun:jdbc-mapping-param name="firstName" type="VARCHAR"
     * @jrun:jdbc-mapping-param name="lastName" type="VARCHAR"
     * @jrun:jdbc-mapping-param name="phone" type="VARCHAR"
     * @jrun:jdbc-mapping-param name="employeeId" type="VARCHAR"
     */
    public void ejbStore() {��}

    /**
     * @jrun:jdbc-mapping name="remove"
     *                    source="samples"
     *                    action="DELETE FROM employees WHERE employee_id=?"
     * @jrun:jdbc-mapping-param name="employeeId" type="VARCHAR"
     */
    public void ejbRemove() throws RemoveException {
    }

    /**
     * @jrun:jdbc-mapping name="findByPrimaryKey" source="samples"
     *                 action="SELECT employee_id FROM employees WHERE
                       employee_id=?"
     * @jrun:jdbc-mapping-param name="employeeId" type="VARCHAR"
     * @jrun:jdbc-mapping-field employeeId
     */
    public void findByPrimaryKey(String pk) {
    }

    /**
     * @jrun:jdbc-mapping name="findAll" source="samples"
     *                    action="SELECT employee_id FROM employees"
     * @jrun:jdbc-mapping-field employeeId
     */
    public Collection findAll() {
        return null;
    }

    /**
     * @jrun:jdbc-mapping name="findByLastName" source="samples"
     *                 action="SELECT employee_id FROM employees WHERE 
                       last_name=?1"
     * @jrun:jdbc-mapping-param name="lastName" type="VARCHAR"
     * @jrun:jdbc-mapping-field employeeId
     */
    public Collection findByLastName(String lastName) {
    this.lastName = lastName;
        return null;
    }
}

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/jrun/4/Programmers_Guide/techniques_ejb11.htm