jax-doclets

JavaDoc doclets for Java Extension APIs

Stéphane Épardaud

0.7

Abstract

jax-doclets is a set of JavaDoc doclets for the Java Extension APIs.


Table of Contents

Preface
1. Overview
1.1. Information
1.2. Example
2. Running the jax-doclets
2.1. Running jax-doclets in standalone
JAXB doclet
JAX-RS doclet
2.2. Running jax-doclets in ant
JAXB doclet
JAX-RS doclet
2.3. Doclet parameters
Generic parameters
JAX-RS doclet parameters
3. JAX-RS doclet documentation
3.1. Where should you write JavaDoc
3.2. Supported standard JavaDoc tags
3.3. Supported specific JavaDoc tags
3.4. Supported JAX-RS annotations
3.5. Supported RESTEasy JAX-RS extension annotations
4. JAXB doclet documentation
4.1. Where should we write JavaDoc
4.2. Supported standard JavaDoc tags
4.3. Supported specific JavaDoc tags
4.4. Supported JAXB annotations
4.5. Mapping Java types to XML tpes
5. License

Preface

This is pre-release software, please bear with it.

1. Overview

jax-doclets allows you to generate JavaDoc documentation for specific Java annotation-based extensions such as:

  • JAX-RS: the RESTful API for Java

  • JAXB: the XML binding API for Java

The goal of jax-doclets is to let you write documentation for your JAX-RS API and JAXB structures in JavaDoc, where it belongs, where it is maintainable, and produce a quality JavaDoc-style documentation.

1.2 Example

Here is an example of documented JAX-RS and JAXB code:

Figure 1.1. Example of documented JAX-RS and JAXB code

package com.lunatech.doclets.jax.test;

import javax.ws.rs.*;
import javax.xml.bind.annotation.*;

/**
 * An example JAX-RS resource
 */
@Path("/example")
@Produces( { "application/xml", "application/*+xml" })
public class JAXRSExample {

  /**
   * An example resource
   */
  @XmlRootElement
  public static class JAXBExample {

    /**
     * The resource ID
     */
    @XmlID
    @XmlElement
    String id;

    /**
     * The example contents
     */
    @XmlValue
    String contents;

    /**
     * An optional attribute
     */
    @XmlAttribute
    String type;
  }

  /**
   * Gets an example resource
   * 
   * @param id
   *          the example id
   * @param type
   *          the type of resource we prefer
   * @param startIndex
   *          the start index
   * @return an example resource suitable for the given parameters
   * @HTTP 404 if there is no such example resource
   * @RequestHeader X-Example-Auth the authentication header
   * @ResponseHeader Location a pointer to the example details
   */
  @Path("{id}")
  @GET
  public JAXBExample getExample(@PathParam("id") String id, 
                                @MatrixParam("type") String type, 
                                @QueryParam("start") int startIndex) {
    return new JAXBExample();
  }
}
  

Figure 1.2. Result of documented JAX-RS code

Result of documented JAX-RS code

Figure 1.3. Result of documented JAXB code

Result of documented JAXB code

2. Running the jax-doclets

The jax-doclets are run by JavaDoc either as standalone or via ant.

Since the JAX-RS supports links to JAXB documentation, you should first run the JAXB doclet, then the JAX-RS doclet using the -link parameter.

2.1 Running jax-doclets in standalone

JAXB doclet

You can use the following command to run the JAXB doclet on your code:

Figure 2.1. Running the JAXB doclet

javadoc -doclet com.lunatech.doclets.jax.jaxb.JAXBDoclet -docletpath lib/jax-doclets-0.7.jar com.lunatech.doclets.jax.test

JAX-RS doclet

You can use the following command to run the JAX-RS doclet on your code:

Figure 2.2. Running the JAX-RS doclet

javadoc -doclet com.lunatech.doclets.jax.jaxrs.JAXRSDoclet -docletpath lib/jax-doclets-0.7.jar com.lunatech.doclets.jax.test

2.2 Running jax-doclets in ant

JAXB doclet

You can use the following ant XML to run the JAXB doclet on your code:

Figure 2.3. Ant XML for running the JAXB doclet


	<target name="doc-jaxb" depends="jars" description="Run the JAXB doclet">
		<javadoc doclet="com.lunatech.doclets.jax.jaxb.JAXBDoclet"
			docletpath="lib/jax-doclets-0.7.jar">
			<package name="com.lunatech.doclets.jax.test.*"/>
		</javadoc>
	</target>


JAX-RS doclet

You can use the following ant XML to run the JAX-RS doclet on your code:

Figure 2.4. Ant XML for running the JAX-RS doclet


	<target name="doc-jaxrs" depends="jars" description="Run the JAXRS doclet">
		<javadoc doclet="com.lunatech.doclets.jax.jaxrs.JAXRSDoclet" 
			docletpath="lib/jax-doclets-0.7.jar">
			<package name="com.lunatech.doclets.jax.test.*"/>
		</javadoc>
	</target>


2.3 Doclet parameters

Generic parameters

These parameters are valid for all jax-doclets

Table 2.1. jax-doclet generic parameters
Parameter Function
-stylesheet The CSS stylesheet to copy and use.
-header The header which is inserted on every page header.
-footer The footer which is inserted on every page footer.
-charset The charset to use for source files and produced HTML documentation.
-link Path to another JavaDoc documentation. This is used to produce links to other package's documentation, either regular JavaDoc or to JAXB documentation in the case of the JAX-RS doclet.

JAX-RS doclet parameters

These parameters are only valid for the JAX-RS doclet

Table 2.2. JAX-RS doclet parameters
Parameter Function
-jaxrscontext The URL path to your RESTful API, if there is a prefix prepended to it on your deploy site.

3. JAX-RS doclet documentation

The JAX-RS doclet generates documentation for your RESTful service based on JAX-RS annotations and JavaDoc comments on your JAX-RS resource methods.

3.1 Where should you write JavaDoc

JavaDoc is read either on the JAX-RS resource methods, or their interface. Only method-level JavaDoc is used. Documentation for a given RESTful URL is taken from the method annotated with @GET, @HEAD, @POST, @PUT or @DELETE for that URL (in order of preference).

JAX-RS resource locators are supported.

Since the JAX-RS supports links to JAXB documentation, you should first run the JAXB doclet, then the JAX-RS doclet using the -link parameter.

3.2 Supported standard JavaDoc tags

The following standard JavaDoc tags are supported on resource methods:

Table 3.1. Standard JavaDoc tags
Tag Function
@param {name} {doc} This is used to document the corresponding resource method parameters annotated with @PathParam, @QueryParam or @MatrixParam. Can be used at most once per parameter name.
@return {doc} Documents the entity returned from this resource method. Can only be used once.

3.3 Supported specific JavaDoc tags

The following specific JavaDoc tags are supported on resource methods:

Table 3.2. Specific JavaDoc tags
Tag Function
@HTTP {code} {doc} This is used to document the codes that the method can return. Can be used multiple times.
@inputWrapped {fq-classname} Specifies the real type of input when declared as a String parameter. Can only be used once.
@returnWrapped {fq-classname} {doc} Used in place of @return when output type is String, void or Response to specify the real type of output and documentation for each possible type. Can be used multiple times.
@RequestHeader {header} {doc} This is used to document HTTP request headers. Can be used multiple times.
@ResponseHeader {header} {doc} This is used to document HTTP response headers. Can be used multiple times.

3.4 Supported JAX-RS annotations

The following standard JAX-RS annotations are supported on resource methods or classes:

Figure 3.1. Standard JAX-RS annotations

  • @Path
  • @PathParam
  • @FormParam
  • @CookieParam
  • @HeaderParam
  • @QueryParam
  • @MatrixParam
  • @Produces
  • @Consumes
  • @Context (ignored)

3.5 Supported RESTEasy JAX-RS extension annotations

The following RESTEasy annotations are supported on resource methods or classes:

Figure 3.2. RESTEasy annotations

  • @Form

4. JAXB doclet documentation

The JAXB doclet generates documentation for your XML schema based on JAXB annotations and JavaDoc comments on your JAXB classes.

4.1 Where should we write JavaDoc

JavaDoc is read either on the JAXB properties (getter methods or fields), or their interface (only for the getters) as well as on the JAXB classes.

Since the JAX-RS supports links to JAXB documentation, you should first run the JAXB doclet, then the JAX-RS doclet using the -link parameter.

4.2 Supported standard JavaDoc tags

There are no standard JavaDoc tags supported. Everything comes from JavaDoc comments.

4.3 Supported specific JavaDoc tags

There are no specific JavaDoc tags supported.

4.4 Supported JAXB annotations

The following standard JAXB annotations are supported on properties or classes:

Figure 4.1. Standard JAXB annotations

  • @XmlAccessorType
  • @XmlRootElement
  • @XmlElement
  • @XmlElementWrapper
  • @XmlAttribute
  • @XmlValue
  • @XmlID
  • @XmlIDREF
  • @XmlTransient (ignored)

4.5 Mapping Java types to XML tpes

The following Java types have a special mapping in XML:

Table 4.1. Standard Java types mapping to XML
Type XML mapping
java.lang.String xsd:string
java.lang.Character, char xsd:string
java.lang.Date xsd:datetime
java.lang.Integer, int xsd:int
java.lang.Long, long xsd:long
java.lang.Short, short xsd:short
java.lang.Byte, byte xsd:byte
java.lang.Float, float xsd:float
java.lang.Double, double xsd:double
java.lang.Boolean, boolean xsd:boolean
java.lang.Object xsd:any
java.lang.Enum List of enum values
java.util.Collection xsd:list

Any other type is taken to be either a Java type or a JAXB type, for whom proper links will be generated.

5. License

jax-doclets is distributed under the LGPL license. It does not distribute any thirdparty libraries that are GPL. It does ship thirdparty libraries licensed under Apache ASL 2.0 and LGPL.