Creating a Template File
Problem
You want to
create a new template file
(.xdt
) that uses the
JUnitPerfTagHandler
class created in the previous
recipe.
Solution
Create a template file called junitperf.xdt
.
Discussion
XDoclet template files mix snippets of Java code and XML-style tags. These tags refer to XDoclet tag handler classes.
Instead of jumping directly into the completed example, it is best if we walk through each step of how the example template file is created. This example can be modified if your coding conventions differ or if you want to add extra functionality.
First, the template creates the package statement:
package <XDtPackage:packageName/>;
Tip
XDoclet prefixes
all namespaces with
“XDt”, and is not part of the
actual namespace specified in the xdoclet.xml
file. In order to reference the
“Perf” namespace, you would use
“XDtPerf”. This is simply a
convention that XDoclet uses.
Next, we add the import statements.
import com.clarkware.junitperf.*; import junit.framework.*;
These are the only import statements that we need. Here is how to include import statements from the class being parsed (if you need them):
<XDtClass:importedList currentClass="<XDtClass:className/>"/>
Tip
It’s not a strict requirement to use entity
references such as <
and
>
when nesting greater-than and less-than
symbols, but it does make the file easier to read, in our opinion.
You are free to write this too:
currentClass="<XDtClass:className/>
"
For fun, any class comments are copied from the JUnit ...
Get Java Extreme Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.