JaVa
   

Building an XDoclet Template

In the previous section we saw how to create a simple template using a couple template tags. In this section of the chapter, we will develop a template that is a little more complex. The most important part of the template is deciding on the block and content tags that will produce the necessary output. A complete list of tags can be found in the installation directory of XDoclet: C:\\xdoclet-1.2\docs\ templates\index.html. You will find hundreds of block and content tags ready to be used. The output of the documentation is the familiar Javadoc output as shown in the following figure.

Java Click To expand

For our example template, we need to decide what the output is suppose to look like and then work backwards to the template and ultimately the tags that will be added to the source code. We are going to create a ficticous configuration for the TDSS app mentioned in . The format of the configuration file will be determined by the attributes available in each of the nodes. Here’s an example of the output:

<?xml version="1.0" encoding="UTF-8"?>
<deployment>
 <attributes>
<parameter value="boolean"/>
<parameter value="integer"/>
<parameter units="perMB"/>
<parameter value="string"/>
 </attributes>
 <name>
 Name
 </name>
 <type>
 Remote
 </type>
 <db>
 mysql
 </db> </deployment>


This information will be pulled from the source code of the individual node source code. The next listing shows an example of the template which will build the deployment file.

<?xml version="1.0" encoding="UTF-8"?>
 <deployment>
 <XDtClass:forAllClasses type="AbstractNode">
 <name>
 "<XDtClass:classTagValue tagName="tdss.name" param />" </name>
 <type>
 "<XDtClass:classTagValue tagName="tdss.type" param />" </type>
 <XDtClass:ifClassTagValueEquals tagName="tdss.type" 
 param 
 value="local">
 <parameter 
 units="<XDtClass:classTagValue tagName="tdss.cost"
 param />"
 />
 <parameter 
 value="<XDtClass:classTagValue
 tagName="tdss.search"
 param />"
 />
 </XDtClass:ifClassTagValueEquals>
 <XDtClass:ifClassTagValueEquals tagName="tdss.type"
 param 
 value="remote">
 <parameter 
 value="<XDtClass:classTagValue
 tagName="tdss.raid"
 param />"
 />
 <parameter 
 value="<XDtClass:classTagValue
 tagName="tdss.popularity"
 param />"
 />
 <db>
"<XDtClass:classTagValue
 tagName="tdss.db"
 param />"
 </db?
 </XDtClass:ifClassTagValueEquals>
 </XDtClass:forAllClasses>
</deployment>


The template looks for a few custom tags:

For example:

/**
* @tdss.type client = "local"
*
* @tdss.raid class = "boolean"
*
* @tdss.popularity class = "integer" *
* @tdss.cost value = "perMD" *
* @tdss.search class = "string"
*
* @tdss.db class "mysql"
*/


The XDoclet engine will encounter the attribute tags and use them with the template in the third listing of this chapter to produce the deployment file needed for the app.


JaVa
   
Comments