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:
You use a combination of jrun.xml attributes and JavaDoc-style comments in the bean implementation to control the processing performed by XDoclet.
ejbPassivate), declare the class as abstract.
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.
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 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:
JRun-specific XDoclet tags start with the @jrun: prefix. The following table describes the JRun-specific XDoclet tags:
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.
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