Resources
Web SitesBook Reviews

Book Review: XDoclet in Action

Title: XDoclet in Action
Authors: Craig Walls, Norman Richards
Publisher: Manning Publications Co.
Publish Date: December 2003
Pages: 591
ISBN: 1932394052

Review Date: April 2004

Mike Worford

XDoclet is a Java language metadata facility to generate the more mundane, boilerplate code in Java applications. For example, XDoclet can generate many EJB artifacts from a bean's implementation class: the home and remote interfaces, the local home and local interfaces, primary key classes, value objects, Data Access Object interfaces, the ejb-jar.xml and vendor-specific deployment descriptors, and more. In a web application, many of the XML mappings can be generated, and XDoclet provides extensive help for Struts and WebWork. XDoclet provides data persistence with Hibernate, JDO and Castor.

This book is for someone curious about the various technologies that XDoclet enables. If you want to use Hibernate, you could probably get by working with just the Hibernate documentation. But, if you'd like to know more about how XDoclet works, and see what else XDoclet can do, then this is the book to get.

XDoclet uses metadata you embed in your source code with javadoc @ tags. XDoclet mixes the information in the tags with pre-written, provided templates to generate the resulting code. Much of the code generated by XDoclet is boilerplate code that, for the most part, just needs to be kept in sync with the code. Keeping that metadata in the code is an efficient, easy way to keep it in sync with the code.

The book begins with an introduction to generated code. It briefly covers the topic of passive (one-time) versus active generated code. Later, "merge points" are briefly covered. Merge points allow you to insert code you manually write into the generated code. Near the end of the book, there is a chapter on creating your own custom code-generation templates and tags.

The next section of the book covers Apache Ant. XDoclet does all of its work through Ant tasks and subtasks. Appendix B contains a quick reference for XDoclet's Ant tasks. A later chapter on custom code generation has a section about adding custom Ant tasks to call the custom generation you have added.

The next several chapters each take a specific area of technology for which XDoclet can generate code. There are nine chapters that focus on EJBs, web-layer, web frameworks, application servers, data persistence, web services, JMX, mock objects and portlets (this is not an exhaustive list of technologies that XDoclet has tags for). Each of these chapters has examples in the book, which are also available for downloading from the publisher. Be warned that the sample projects do not come with all the required jars. External jars needed for each project are listed in the readme file, and if you were to set up all nine chapter/projects, you'll need to download tens of jars.

The next chapter is about custom code generation -- writing custom templates, custom tags, and custom Ant tasks. Writing custom code-generation templates and tags is a little like writing a JSP page using JSP tags.

The book ends with several appendices that take up nearly half of the book. One covers the XDoclet Ant tasks. Another covers the XDoclet tags used for specific technologies -- there are 54 tables, each for a distinct application. The third major appendix covers the Wdt language tags that you use for custom code generation.

If you'd like an overview of several of the technologies implemented by XDoclet, and find out more about how it works, then this is the book to get. Chances are, there is more than one XDoclet technology you can use.