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.
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 application mentioned in Chapter 11. The format of the configuration file will be determined by the attributes available in each of the nodes. Heres an example of the output:
<?xml version="1.0" encoding="UTF-8"?> <deployment> <attributes> <parameter name="raid" value="boolean"/> <parameter name="popularity" value="integer"/> <parameter name="cost" units="perMB"/> <parameter name="search" 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" paramName="name"/>" </name> <type> "<XDtClass:classTagValue tagName="tdss.type" paramName="type"/>" </type> <XDtClass:ifClassTagValueEquals tagName="tdss.type" paramName="client" value="local"> <parameter name="cost" units="<XDtClass:classTagValue tagName="tdss.cost" paramName="value"/>" /> <parameter name="search" value="<XDtClass:classTagValue tagName="tdss.search" paramName="class"/>" /> </XDtClass:ifClassTagValueEquals> <XDtClass:ifClassTagValueEquals tagName="tdss.type" paramName="client" value="remote"> <parameter name="raid" value="<XDtClass:classTagValue tagName="tdss.raid" paramName="class"/>" /> <parameter name="popularity" value="<XDtClass:classTagValue tagName="tdss.popularity" paramName="class"/>" /> <db> "<XDtClass:classTagValue tagName="tdss.db" paramName="class"/>" </db? </XDtClass:ifClassTagValueEquals> </XDtClass:forAllClasses> </deployment>
The template looks for a few custom tags:
@tdss.raid class=value: Defines the type of class to use for raid.
@tdss.popularity class =value: Defines the type of class to use for popularity.
@tdss.cost value=string: Defines the type of cost structure.
@tdss.search class = value: Defines the type of class to use for search.
@tdss.type client=remote/local: Defines if the node type is local or remote.
@tdss.name name=value: Defines the name of the node.
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 application.