"vDoclet/EJB" is a set of vDoclet templates that can be used to generate EJB-related files. It's sometimes a hassle to maintain hand-coded remote and local-interfaces and deployment-descriptors, so we generate these things from your EJB implementation class.
Specifically, vDoclet/EJB is able to generate:
The first step is to add vDoclet/EJB tags to your raw EJB implementation classes. Once you know what tags to use, it's pretty easy.
Add a class-level Javadoc tag that identifies what type of EJB this
class defines, e.g. @ejb-entity
,
@ejb-session
.
/** * @ejb-entity */ public abstract class StoryBean {
If you want this EJB to be accessible thru a remote-interface,
add a class-level @ejb-remote
tag.
/** * @ejb-entity * @ejb-remote */ public abstract class StoryBean {
Then, add @ejb-remote
tags to the Javadoc for all the
methods you wish to make available via the remote-view.
/** * @ejb-remote */ public abstract String getAuthor();
For session-beans, and bean-managed entities, that's pretty much it.
For container-managed entities, you need to give the container a add a little more detail. vDoclet/EJB assumes that you've written your CMP entities in the EJB-2.0 style, with abstract set- and get-methods for the your persistent-fields. If necessary, we'll generate a subclass that can be deployed in an EJB-1.1 container.
Start by mapping the bean to a database table using the
@ejb-cmp-table
tag:
/** * @ejb-entity * @ejb-remote * @ejb-cmp-table STORY */ public abstract class StoryBean {
Next, map persistent fields to database columns, by adding
@ejb-cmp-column
tags to the get-methods:
/** * @ejb-remote * @ejb-cmp-column AUTHOR */ public abstract String getAuthor();
vDoclet/EJB will generate a primary-key class for your entity if
you add a @ejb-key-generate
tag:
/** * @ejb-entity * @ejb-remote * @ejb-cmp-table STORY * @ejb-key-generate */ public abstract class StoryBean {
Tell it which persistent-fields to include in the key by marking
them with @ejb-key-field
:
/** * @ejb-remote * @ejb-key-field * @ejb-cmp-column ID */ public abstract long getId();
See the Tag Reference section below for details of all the tags supported.
When you run vDoclet/EJB on your code-base, it identify a number of source-files that define EJBs. In vDoclet-speak, we call the resulting collection of EJBs an "EJB bundle". The bundle represents a deployment-unit (EJB-JAR file).
Most of the information that vDoclet/EJB uses to do it's job comes
from Javadoc tags in your source-code. However, some information
applies to the entire deployment-unit, rather than specific beans;
we get this info from the "bundle properties" file. The
bundle-properties file is called
"vdoclet-ejb.properties
", and lives in the root
directory of your code-base.
Information that we get from the bundle-properties file includes:
If you have container-managed entity-beans, you'll need to set
the datasource
property in
vdoclet-ejb.properties
:
datasource = java:/newsDataSource
Run vDoclet/EJB from Ant as follows:
<target name="ejb/generate"> <vdoclet srcDir="ejb/java" destDir="build/ejb/java" template="vdoclet/ejb/generate.vm"> <classpath> <path refid="j2ee.classpath" /> <pathelement location="lib/vdoclet.jar" /> </classpath> </vdoclet> </target>
As an example, consider an EJB from the "newstest"
example included with vDoclet. "StoryBean" is a CMP entity-bean,
representing a news-story. From the implementation-class, StoryBean.java
,
vDoclet/EJB generates:
Remote-view: |
Story.java
StoryHome.java
|
Primary-key: |
StoryKey.java
|
CMP-1.1 subclass: |
StoryBeanSub.java
|
EJB deployment-descriptor: |
ejb-jar.xml
|
JBoss deployment-descriptors: |
jboss.xml
jaws.xml
|
WebLogic deployment-descriptors: |
weblogic-ejb-jar.xml
weblogic-rdbms11-persistence-600.xml
|
The following is a partial list of the tags supported by vDoclet/EJB.
@ejb-base-name name
@ejb-name name
{@ejb-base-name}
")
@ejb-session
@ejb-session-type type
type
=
Stateless
| Stateful
@ejb-entity
@ejb-persistence-type type
type
=
Container
| Bean
@ejb-cmp-table table
@ejb-cmp-column column
@ejb-key-generate
@ejb-key-field
@ejb-isModified-generate
datasource = dataSourceUrl
@ejb-abstract
@ejb-remote
@ejb-remote
@ejb-remote-class className
{@ejb-base-name}
")
@ejb-remote-extends className
@ejb-remote-home-class className
{@ejb-remote-class}Home
")
@ejb-remote-home-jndi jndiName
{@ejb-remote-home-class}
")
@ejb-transaction-type type
type
=
Container
| Bean
@ejb-transaction attribute
attribute
=
NotSupported
| Required
| Supports
| RequiresNew
| Mandatory
| Never
@ejb-transaction attribute
attribute
=
NotSupported
| Required
| Supports
| RequiresNew
| Mandatory
| Never
@ejb-permission role
@ejb-permission role