Hey
I was inspired by the latest JavaWorld article on code generation by
using javadoc Doclets, and decided to try it out.
I created a "simple" doclet that could read an EJB bean file and
generate the following:
* Remote interface (one can tag remote methods in bean. Only tagged
methods appear in remote interface)
* Home interface (one can tag create methods in bean. One can also
define finders in class-comments, e.g. "@ejb-finder Collection
findLargeAccounts(int balance)")
* If Entity CMP -> Data object class generated which holds CMP fields
* If Entity CMP -> Primary key consisting of all fields marked as
pk-fields (yes, hashCode and equals are automatically implemented
properly)
* If Entity CMP -> Generate EJB 2.0-ish layer, i.e. allow bean to have
abstract get/set methods and generate EJB 1.1-CMP bean on top. The layer
also keeps track of dirty flag, and allows bulk accessor setting from
data object
Kinda cool. There is a generated example available at
http://www.dreambean.com/download/rickard/bank.zip. AccountBean.java is
the *only*
hand-written code (it extends from a generic dummy Entity-impl. It is
trivial; ignore), and everything else is generated on the fly.
The version of Ant I had did not support doclets properly, but if the
latest
one does, this approach has huge potential. Simply create your bean
code,
run the doclet prior to compilation in the build script, and then
compile
it all. Presto. Nice and clean. It might even be possible to generate
ejb-jar.xml automatically! Talk about productivity booster!
I will submit the EJB doclet itself for public use once I've touched it
up a
bit.
Any comments?
regards,
Rickard
--
Rickard �berg
Email: [EMAIL PROTECTED]
http://www.telkel.com
http://www.jboss.org
http://www.dreambean.com