How can I customize XDoclet to generate what I want?

Ara Abrahamian

XDoclet is designed with extensibility in mind. You can modify the way it works in various ways:

  • You can set a modified template file as the template used by a sub-task. All the output is generated based on template files which have a .j extension and are based on XDoclet's own template engine. You can make a copy of the relevant template file, modify it, and make the sub-task use your copy of the template by the templateFile attribute available for all sub-tasks.
    Example: <remoteInterface templateFile="c:mytemplatesmyremote.j"/>
  • Many of the sub-tasks have some customization merge points in them. You can use these merge points to plug in your special piece of template into the standard templates.
    Example: Say you want to provide a toXml() method in all EJB data-object classes. By looking at dataobject's documentation you find out that it supports a customization merge point called dataobject-custom.j. So you create a dataobject-custom.j file, put it in the folder which is pointed to be mergeDir attribute of the subtask/task. dataobject will pick your merge files and merge it in. XDoclet assumes the content of that file is a template, so it parses it. This means you can write a templatelet (!) in it and use XDoclet's built-in template tags (such as <XDtPersistent:forAllPersistenceFields .../> to loop over all persistence fields and generate XML based on each field).
  • Let's say you want to add some stub generation facility to <entitycmp/> sub-task so that a SOAP stub is generated for the EJB. You can define a MyEntityCmpSubTask class derived from xdoclet's xdoclet.ejb.EntityCmpSubTask and override relevant methods (generateForClass for example). Then you should let XDoclet know about this customized <entitycmp/> sub-task. you do so by using the subTaskClassName attribute of the subtask. Remember the customized class should be in XDoclet's classpath.
    Example: <entitycmp subTaskClassName="com.foobar.MyEntityCmpSubTask"/>
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact