Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Custom Generators Using XDoclet (1.2)

 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now that my architecture has solidified for the most part I am seeing opportunities for generating a lot of code. I have seen examples of creating custom templates (.xdt) and creating my own tags, but there will be some cases where I need to munge values, e.g. turning "userId" into "getUserId" or "USER_ID". Does XDoclet provide some basic munging functions, or is this the point where I need to create an actual module?
 
Author
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the type of thing you do with XDoclet (template) tags. You'll be somewhat disappointed to know that there's an awful lot you can't do with the existing tags. If you were in the context of getFoo() method, you could use XDtMethod:setMethod to get the "setFoo" name, but you'll find tags of a more general nature to be rather sparse.
The general approach in 1.2 is create custom tags. It's MUCH simpler than righting JSP taglibs. Basically, you create one single class that is your tag handler and can implement each tag as a single method on the tag handle. Something like this:

You could assign this handler to "MyTags" and generate "USER_ID" with:


I don't have any tags on this machine to cut and paste here, but the above looks right. Refer to chapter 12 of XDoclet in Action for a real example...

Oh, and no you don't have to create a full module (I assume by that you mean task/subtask/tags jar) to use a tag handler in your scripts. You can package it up or declare it using XDtTagDef...
 
author
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Harkness:
Now that my architecture has solidified for the most part I am seeing opportunities for generating a lot of code. I have seen examples of creating custom templates (.xdt) and creating my own tags, but there will be some cases where I need to munge values, e.g. turning "userId" into "getUserId" or "USER_ID". Does XDoclet provide some basic munging functions, or is this the point where I need to create an actual module?


You may be in luck! The XDT template language comes with some stuff to do something similar to what you described.
For example, the <XDtMethod ropertyName> tag converts the name of the current method into a property name, effectively stripping set/get from the beginning and converting the first character after that to lowercase.
I don't know about going from "userId" to "USER_ID". There may be something like this already, but I don't recall seeing it. If the name munging you need isn't already available, it's easy to add by writing your own tag handler class. The example below gives a skeleton of such a tag handler (I've left the actual name munging as an exercise for the reader).
 
Craig Walls
author
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UBB misinterpreted part of my last post to have a smiley...oops. That was supposed to be <XDtMethod: propertyName> (I put a space in this time...maybe it'll work better?)
It looks like Norm and I answered at the same time. Good answers, either way.
[ December 11, 2003: Message edited by: Craig Walls ]
 
norman richards
Author
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, that should be:
<XDtMyTags:underscoreName property="userId">
[ December 11, 2003: Message edited by: norman richards ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent! Thanks to you both. Indeed, tag handlers will be a piece of cake. Once I've picked the first test case for code generation I'll post back to this thread with my results and summary (no ETA at this time, though, as we're in the QA cycle).
 
reply
    Bookmark Topic Watch Topic
  • New Topic