jax-doclets

JavaDoc doclets for Java Extension APIs

Stéphane Épardaud

0.10.0

Abstract

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


Preface
1. Overview
1.1. Information
1.2. Example
2. Running the jax-doclets
2.1. Running jax-doclets in standalone
2.1.1. JAXB doclet
2.1.2. JAX-RS doclet
2.1.3. JPA doclet
2.2. Running jax-doclets in ant
2.2.1. JAXB doclet
2.2.2. JAX-RS doclet
2.2.3. JPA doclet
2.3. Running jax-doclets in Maven
2.3.1. JAXB doclet
2.3.2. JAX-RS doclet
2.3.3. JPA doclet
2.4. Doclet parameters
2.4.1. Generic parameters
2.4.2. JAX-RS doclet parameters
2.4.3. JAXB doclet parameters
2.4.4. JPA doclet parameters
2.5. About stylesheets
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. JPA doclet documentation
5.1. Supported standard JavaDoc tags
5.2. Supported specific JavaDoc tags
5.3. Supported JPA annotations
5.4. Supported Hibernate JPA extension annotations
6. License

Preface

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

This book is produced by the Wikbook tool. Wikbook is an open source project for converting wiki files into a set of docbook files.

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

  • JPA: the Java Persistence API

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

1.1 Information

jax-doclets is an open-source project maintained by Lunatech Labs.

1.2 Example

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

Example 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.1. Result of documented JAX-RS code

Result of documented JAX-RS code


Figure 1.2. Result of documented JAXB code

Result of documented JAXB code


Here is an example of documented JPA code:

Example 1.2. Example of documented JPA code

package com.lunatech.doclets.jax.test.jpa;

import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

/**
 * This is the order type.
 * 
 * @author stephane
 */
@Entity
public class Order {

  /**
   * This is my ID and I love it
   */
  @Id
  @GeneratedValue
  public Long id;

  /**
   * Column with an explicit name
   */
  @Column(name = "column_with_name")
  public String columnWithName;

  /**
   * Column with an annotation
   */
  @Column
  public String columnWithAnnotation;

  /**
   * Column with no annotation
   */
  public String columnWithoutAnnotation;

  /**
   * Transient property
   */
  public transient String transientColumn;

  /**
   * Transient property
   */
  @Transient
  public String transientAnnotatedColumn;

  /**
   * A Bill
   */
  @JoinColumn(name = "bill_id")
  @OneToOne
  public Bill bill;

  /**
   * A list of Orderlines
   */
  @OneToMany(mappedBy = "order")
  public List<Orderline> orderlineList;

  /**
   * A set of Orderlines
   */
  @OneToMany(mappedBy = "order")
  public Set<Orderline> orderlineSet;

  /**
   * A set of Items, via a link table
   */
  @JoinTable(name = "order2item", 
             joinColumns = @JoinColumn(name = "item_id"),
             inverseJoinColumns = @JoinColumn(name = "order_id"))
  @ManyToMany
  public Set<Item> itemSet;
}


Figure 1.3. Result of documented JPA code

Result of documented JPA code


2. Running the jax-doclets

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

[Note]Note

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

2.1.1 JAXB doclet

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

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

2.1.2 JAX-RS doclet

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

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

2.1.3 JPA doclet

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

javadoc -doclet com.lunatech.doclets.jax.jpa.JPADoclet \
-docletpath lib/jax-doclets-0.10.0.jar \
com.lunatech.doclets.jax.test

2.2 Running jax-doclets in ant

2.2.1 JAXB doclet

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

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

2.2.2 JAX-RS doclet

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

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

2.2.3 JPA doclet

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

<target depends="jars" description="Run the JPA doclet" name="doc-jpa">
 <javadoc doclet="com.lunatech.doclets.jax.jpa.JPADoclet" docletpath="lib/jax-doclets-0.10.0.jar">
  <package name="com.lunatech.doclets.jax.test.*"/>
 </javadoc>
</target>

2.3 Running jax-doclets in Maven

2.3.1 JAXB doclet

You can use the following Maven POM extract to run the JAXB doclet on your code:

<reporting>
 <plugins>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-javadoc-plugin</artifactId>
   <version>2.7</version>
   <reportSets>
    <reportSet>
     <id>jaxb</id>
     <configuration>
      <doclet>com.lunatech.doclets.jax.jaxb.JAXBDoclet</doclet>
      <docletArtifacts>
       <docletArtifact>
        <groupId>com.lunatech.jax-doclets</groupId>
        <artifactId>doclets</artifactId>
        <version>0.10.0</version>
       </docletArtifact>
      </docletArtifacts>
     </configuration>
     <reports>
      <report>javadoc</report>
     </reports>
    </reportSet>
   </reportSets>
  </plugin>
 </plugins>
</reporting>

Which you run with:

$ mvn site

2.3.2 JAX-RS doclet

You can use the following Maven POM extract to run the JAX-RS doclet on your code:

<reporting>
 <plugins>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-javadoc-plugin</artifactId>
   <version>2.7</version>
   <reportSets>
    <reportSet>
     <configuration>
      <doclet>com.lunatech.doclets.jax.jaxrs.JAXRSDoclet</doclet>
      <docletArtifacts>
       <docletArtifact>
        <groupId>com.lunatech.jax-doclets</groupId>
        <artifactId>doclets</artifactId>
        <version>0.10.0</version>
       </docletArtifact>
      </docletArtifacts>
     </configuration>
     <reports>
      <report>javadoc</report>
     </reports>
    </reportSet>
   </reportSets>
  </plugin>
 </plugins>
</reporting>

Which you run with:

$ mvn site

2.3.3 JPA doclet

You can use the following Maven POM extract to run the JPA doclet on your code:

<reporting>
 <plugins>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-javadoc-plugin</artifactId>
   <version>2.7</version>
   <reportSets>
    <reportSet>
     <id>jpa</id>
     <configuration>
      <doclet>com.lunatech.doclets.jax.jpa.JPADoclet</doclet>
      <docletArtifacts>
       <docletArtifact>
        <groupId>com.lunatech.jax-doclets</groupId>
        <artifactId>doclets</artifactId>
        <version>0.10.0</version>
       </docletArtifact>
      </docletArtifacts>
     </configuration>
     <reports>
      <report>javadoc</report>
     </reports>
    </reportSet>
   </reportSets>
  </plugin>
 </plugins>
</reporting>

Which you run with:

$ mvn site

2.4 Doclet parameters

2.4.1 Generic parameters

These parameters are valid for all jax-doclets

ParameterFunction
-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.

2.4.2 JAX-RS doclet parameters

These parameters are only valid for the JAX-RS doclet

ParameterFunction
-jaxrscontext url The URL path to your RESTful API, if there is a prefix prepended to it on your deploy site.
-disablehttpexample Disables the generated HTTP examples.
-disablejavascriptexample Disables the generated JavaScript examples.

2.4.3 JAXB doclet parameters

These parameters are only valid for the JAXB doclet

ParameterFunction
-disablejsontypename If you want to hide the serialised type name from the JSON examples.
-disablexmlexample Disables the generated XML examples.
-disablejsonexample Disables the generated JSON examples.

2.4.4 JPA doclet parameters

There are currently no special parameters for the JPA doclet.

2.5 About stylesheets

If you do not specify a stylesheet, one will be provided for you that closely matches the default JavaDoc style. If you do specify a stylesheet with the -stylesheet parameter, it will be copied to the stylesheet named doclet.css and the default JavaDoc stylesheet will be available as default-doclets.css which means you can write your stylesheet like this to extend the default stylesheet without having to restyle everything:

@IMPORT url("default-doclet.css");

table.info .TableCaption, td.NavBarCell1 {
 background: #EEEEEE;
}

td.NavBarCell1 table th.selected {
 background-color: #61911B;
}

img.logo {
 margin: 1em;
 border: none;
}

a {
 color: #61911B;
}

a:visited {
 color: #3F5E12;
}

Note that wherever possible we´ve stuck with the JavaDoc CSS class names so you can reuse your existing JavaDoc stylesheets.

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.

[Note]Note

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:

TagFunction
@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:

TagFunction
@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.
@include file Includes the specified relative file in the resource documentation. Can be used multiple times.

3.4 Supported JAX-RS annotations

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

  • @Path

  • @PathParam

  • @FormParam

  • @CookieParam

  • @HeaderParam

  • @QueryParam

  • @MatrixParam

  • @Produces

  • @Consumes

  • @Context (ignored)

3.5 Supported RESTEasy JAX-RS extension annotations

If the optional RESTEasy dependency is present, the following RESTEasy annotations are supported on resource methods or classes:

  • @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.

[Note]Note

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:

  • @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:

TypeXML 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. JPA doclet documentation

The JPA doclet generates documentation for your data model based on JPA annotations and JavaDoc comments on your JPA classes.

5.1 Supported standard JavaDoc tags

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

5.2 Supported specific JavaDoc tags

There are no specific JavaDoc tags supported.

5.3 Supported JPA annotations

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

  • @Entity

  • @Id

  • @ManyToMany

  • @OneToMany

  • @ManyToOne

  • @OneToOne

  • @Table

  • @Transient

  • @GeneratedValue

  • @Id

  • @Lob

5.4 Supported Hibernate JPA extension annotations

If the optional Hibernate dependency is present, the following Hibernate annotations are supported on classes or properties:

  • @GenericGenerator

6. 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.