XDoclet in Action
Craig Walls and Norman Richards
  • November 2003
  • ISBN 9781932394054
  • 624 pages
  • printed in black & white

This is the first serious XDoclet book, and the authors got it right!

Michael Yuan, JavaWorld Author

Are you tired of writing the same Java code, over and over again? XDoclet will take the burden of repetitive development tasks off your shoulders by automating them. XDoclet is a metadata-driven, code generation engine for Java. Starting from simple JavaDoc-style comments, it generates deployment descriptors, interfaces, framework classes and other utility classes your project requires.

XDoclet in Action is an easy to read introduction to XDoclet and its uses. It is a resource on code generation with this popular open source tool. With many short code examples and a full-scale J2EE example, the book shows you how to use XDoclet with EJBs, Servlets, JMX, and other technologies. You'll also learn how to customize XDoclet beyond its out-of-the-box capabilities to generate code specific to your application.

With this book you will learn how to write less code, how to keep your application components in sync, and how to keep your deployment, interface, utility and other information all in one place.

Table of Contents detailed table of contents




about this book

about the title

about the cover illustration

Part 1 The basics

1. A gentle introduction to code generation

1.1. What is XDoclet?

1.2. Types of code generation

1.2.1. Passive style: one-time code generation

1.2.2. Active style: integrated code generation

1.3. Code generation input sources

1.3.1. Models as an input source

1.3.2. Data files as input

1.3.3. Source files as input

1.4. How XDoclet fits in

1.5. Deciding when to use XDoclet

1.5.1. Should you generate code?

1.5.2. Should you use a tool or build the generator yourself?

1.5.3. Should you choose XDoclet?

1.6. Code generation wisdom

1.6.1. Don’t generate what you don’t understand

1.6.2. Test the generated code

1.6.3. Don’t be afraid to change your design to accommodate generation

1.6.4. Generate layer by layer, piece by piece

1.6.5. Keep generated files out of the code repository

1.6.6. Look for repetition

1.7. Summary

2. Getting started with XDoclet

2.1. XDoclet in action

2.1.1. A common issue

2.1.2. Adding an XDoclet tag

2.1.3. Integrating with Ant

2.1.4. Generating a professional-looking todo list

2.2. Tasks and subtasks

2.2.1. XDoclet tasks

2.2.2. XDoclet subtasks

2.3. Invoking tasks from Ant

2.3.1. Declaring tasks

2.3.2. Using tasks

2.4. Tagging your code with attributes

2.4.1. The anatomy of an attribute

2.5. Code generation patterns

2.5.1. Template basics

2.5.2. Template tags

2.6. Customizing through merging

2.7. The big picture

2.8. Summary

Part 2 Using XDoclet with Enterprise Java

3. XDoclet and Enterprise JavaBeans

3.1. Building the web-log application

3.1.1. The web-log component model

3.1.2. Creating the EJB code generation build file

3.2. Defining the EJBs

3.3. Adding the subtasks for the EJB application

3.3.1. Letting XDoclet write deployment descriptors

3.3.2. Generating home and local home interfaces

3.3.3. Generating remote and local interfaces

3.3.4. Generating utility objects

3.3.5. Generating concrete EJB implementation classes

3.3.6. Including EJB references

3.3.7. Including container-managed persistent fields

3.3.8. Declaring relationships

3.3.9. Generating value objects

3.4. Managing EJB security

3.4.1. Container-managed authorization

3.4.2. Bean-managed authorization

3.4.3. Identity propagation

3.5. Using query methods with entity beans

3.5.1. Find methods

3.5.2. Select methods

3.6. How you’ve benefitted from XDoclet so far

3.7. Managing transactions

3.7.1. Container-managed transactions

3.7.2. Bean-managed transactions

3.8. Working with Data Access Objects

3.8.1. Generating DAO interfaces

3.8.2. Adding methods to the DAO interface

3.9. Working with message-driven beans

3.9.1. Defining message selectors

3.9.2. Setting an acknowledge mode

3.9.3. Specifying destinations

3.9.4. Setting subscription durability

3.10. Summary

4. XDoclet and the web-layer

4.1. Adding web-layer generation to the build file

4.2. Working with servlets

4.2.1. Configuring servlets in web.xml

4.3. Referencing EJBs

4.4. Configuring servlet security

4.4.1. Declaring security roles

4.4.2. Programming security in servlets

4.4.3. Propagating security roles

4.5. Working with servlet filters

4.5.1. Configuring filters in web.xml

4.6. Applying XDoclet to listeners

4.7. Writing custom JSP tags

4.8. Summary

5. XDoclet and web frameworks

5.1. Merging framework servlets into web.xml

5.1.1. Merging ActionServlet for Struts

5.1.2. Merging ServletDispatcher for WebWork

5.2. Using XDoclet with Jakarta

5.2.1. Enabling Struts generation in the build files

5.2.2. Implementing an Action

5.2.3. Declaring the Struts Action

5.2.4. Defining ActionForms

5.3. Using XDoclet with WebWork

5.3.1. Configuring Actions in actions.xml

5.3.2. Configuring Actions in views.properties

5.3.3. Documenting actions

5.4. Summary

6. XDoclet and application servers

6.1. Why we need vendor-specific tasks

6.1.1. J2EE development roles

6.1.2. J2EE application deployment

6.1.3. Generating application server deployment descriptors

6.2. Deploying on JBoss

6.2.1. Deploying an EJB JAR on JBoss

6.2.2. Specifying database schema

6.2.3. Mapping foreign keys

6.2.4. Handling relation tables

6.2.5. Creating database tables

6.2.6. Specifying physical JNDI names

6.3. Deploying a WAR file on JBoss

6.3.1. Setting a default web context

6.3.2. Setting a security domain

6.3.3. Setting a virtual host

6.4. Deploying on WebLogic

6.4.1. Deploying an EJB JAR on WebLogic

6.4.2. Specifying database mapping

6.4.3. Managing tables

6.4.4. Using WebLogic-specific features

6.4.5. Deploying a WAR file on WebLogic

6.5. Working with multiple application servers

6.6. Working with multiple deployments

6.7. Summary

Part 3 Other XDoclet applications

7. XDoclet and data persistence

7.1. Hibernating data

7.1.1. Preparing the build for Hibernate

7.1.2. Tagging classes for Hibernation

7.1.3. Using the Hibernated classes

7.2. Persisting data with JDO

7.2.1. Adding JDO generation to the build

7.2.2. Tagging classes for JDO persistence

7.2.3. Using the JDO persistence-capable classes

7.2.4. Working with vendor extensions

7.3. Persisting data with Castor

7.3.1. Adding Castor generation to the build

7.3.2. Persisting objects using Castor JDO

7.3.3. Using objects persisted with Castor JDO

7.3.4. Working with Castor XML

7.4. Summary

8. XDoclet and web services

8.1. Generating deployment descriptors for Apache SOAP

8.1.1. Writing simple Java web services for Apache SOAP

8.1.2. Exposing EJBs as Apache SOAP web services

8.1.3. Mapping custom types

8.2. Generating deployment descriptors for Axis

8.2.1. Writing simple Java web services for Axis

8.2.2. Exposing EJBs as Axis web services

8.2.3. Mapping custom types

8.3. Summary

9. XDoclet and JMX

9.1. A quick JMX overview

9.2. Preparing the build for JMX generation

9.3. Generating MBean interfaces

9.4. Generating mlet files

9.4.1. Deploying the mlet using the mlet service

9.5. Working with MBean services in JBossMX

9.5.1. Creating JBossMX services

9.5.2. Generating XML for JBossMX model MBeans

9.6. Generating MBean description classes for MX4J

9.6.1. Preparing the build for MX4J

9.6.2. Tagging MBeans for MX4J

9.6.3. Running the build

9.6.4. Deploying the MBean into MX4J

9.7. Summary

10. XDoclet and mock objects

10.1. What are mock objects?

10.1.1. Knowing when to mock

10.1.2. Testing from the inside out

10.2. Generating mock objects with XDoclet

10.2.1. Adding mock-object generation to the build

10.2.2. Tagging interfaces to generate mock implementations

10.2.3. Testing FullServiceStation.java with mock objects

10.3. Summary

11. XDoclet and portlets

11.1. Introducing JSR-168 (the portlet API)

11.1.1. Writing a simple portlet

11.1.2. Deploying a portlet

11.2. Adding portlet.xml generation to the build file

11.3. Writing a portlet

11.3.1. Defining portlet basics

11.3.2. Initializing portlets

11.3.3. Supporting multiple display options

11.3.4. Defining preferences

11.3.5. Validating preferences

11.4. Running the build

11.5. Summary

Part 4 Extending XDoclet

12. Custom code generation with XDoclet

12.1. When should you bother with custom code generation?

12.1.1. The risks of custom generation

12.1.2. The rewards of custom generation

12.1.3. Making the leap

12.2. Using XDoclet templates

12.2.1. Using aggregate generation

12.2.2. Using transformation generation

12.3. Exploring design alternatives

12.3.1. Registering commands

12.3.2. Generating the command processor

12.3.3. Generating a configuration file

12.3.4. Choosing a generation method

12.4. Template tag concepts

12.4.1. Block and content tags

12.4.2. Tag namespaces

12.4.3. Types of tags

12.4.4. Using some basic template tags

12.5. Creating custom template tags

12.5.1. Creating a content tag

12.5.2. Creating a body tag

12.5.3. Refactoring common functionality into a tag

12.6. Creating custom tasks

12.6.1. Creating the Ant task

12.6.2. Creating the subtask

12.6.3. Distributing custom tasks

12.6.4. Registering custom tasks in Ant

12.7. Summary

13. XDoclet extensions and tools

13.1. The role of tools in XDoclet

13.2. IntelliJ IDEA

13.2.1. Helping IDEA find your generated classes

13.2.2. Configuring IDEA to accept XDoclet tags

13.2.3. Using IDEA’s live templates to generate XDoclet tags

13.3. Eclipse

13.3.1. Using JBoss IDE

13.3.2. Generating an XDoclet build file

13.4. AndroMDA

13.5. Middlegen

13.6. Summary


Appendix A: Installing XDoclet

Appendix B: XDoclet task/subtask quick reference

Appendix C: XDoclet tag quick reference

Appendix D: XDt template language tags

Appendix E: The future of XDoclet


What's inside

  • Introduction to XDoclet
  • Best practices and techniques
  • How to customize XDoclet
  • Generate code for
    • EJB
    • Servlets
    • Struts and WebWork
    • JDO
    • Hibernate

About the authors

Craig Walls, an XDoclet project committer, has been a software developer since 1994 and a Java fanatic since 1996. He lives in Dallas, Texas. Norman Richards has ten years' software development experience, and has worked with code generation for much of that time. He is an avid XDoclet user and evangelist. Norman lives in Austin, Texas.

eBook $35.99 PDF only

FREE domestic shipping on three or more pBooks

XDoclet is the missing link for complex code generation ... This book will quickly teach you how to build and deploy J2EE projects with just a click.

Daniel Brookshier, author of "JXTA: Java P2P Programming"

I learned a lot reading it ... I was immediately filled with new ideas on how to use XDoclet. It’s perfect.

Rickard Öberg, inventor of EJBdoclet

The patterns described make a lot of sense to me ... I've done things the hard way in the past.

Nathan Egge, Argon Engineering

...a fantastic job ... written clearly and effectively, with humor too.

Erik Hatcher, co-author of "Java Development with Ant"