I've built some changes in andromda-hibernate cartridge and I want to
share one idea I had...
Now in my case every time a property tag value starts with
"@hibernate.property." the following text is used as a XDoclet parameter
na and the tag value is used as the parameter value. I think it could be
good all times we need to set a XDoclet parameter value (struts, ejb,
hibernate, etc.).

Example:

Tag [EMAIL PROTECTED]
Tag value=40

Result: 

    * @hibernate.property
    *     length="40"


The velocity code:

    // --------------- attributes ---------------------
##walter - inicio
#set($hibPropPrefix="@hibernate.property.")
#set($hibPropPrefixLen=$hibPropPrefix.length())
#set($hibColPrefix="@hibernate.column.")
#set($hibColPrefixLen=$hibColPrefix.length())
##walter - fim
#foreach ( $att in $class.attributes )
##walter - inicio
#set($propLength="")
##walter - fim
#set ($atttypename = $transform.findFullyQualifiedName($att.type))

    private $atttypename ${att.name};
   
   /**
#generateDocumentation ($att "    ")
    *
#set ($attcolumnname = $str.toDatabaseAttributeName(${att.name}, "_"))
#set ($attjdbctype   = $transform.findAttributeJDBCType($att))
#set ($attsqltype    = $transform.findAttributeSQLType($att))
#if ($transform.getStereotype($att.id) == "PrimaryKey")
    * @hibernate.id 
    *     generator-class="uuid.hex"
##walter - inicio
        *     length="32"
#set ($propLength="32")
##walter - fim
#else
    * @hibernate.property
##walter - inicio
#foreach ( $tgv in $att.taggedValues )
##
#if($tgv.tag.startsWith($hibPropPrefix))
#if($tgv.tag.substring($hibPropPrefixLen) == "length")
#set($propLength=$tgv.value)
#end
    *     ${tgv.tag.substring($hibPropPrefixLen)}="$tgv.value"
#end
#end###foreach ( $tgv in $att.taggedValues )
##walter - fim
#end
    *     column="$attcolumnname"
    *
    * @hibernate.column
    *     name="$attcolumnname"
##walter - inicio
##    *     sql-type="$attsqltype"
##    *
#set ($colLength=$propLength)
#foreach ( $tgv in $att.taggedValues )
##
#if($tgv.tag.startsWith($hibColPrefix))
#if($tgv.tag.substring($hibColPrefixLen) == "length")
#set ($colLength=$tgv.value)
#else
    *     ${tgv.tag.substring($hibColPrefixLen)}="$tgv.value"
#end
#end
##
#if ($attsqltype == "VARCHAR" || $attsqltype == "CHAR") ## que mais ?
#if ($colLength == "")
    *     sql-type="$attsqltype(255)"
#else
    *     sql-type="$attsqltype($colLength)"
#end###if ($colLength == "")
#else
    *     sql-type="$attsqltype"
#end###if ($attsqltype == "VARCHAR" || $attsqltype == "CHAR") ## que mais ?
##
#end###foreach ( $tgv in $att.taggedValues )
        *       
##walter - fim

** for non-portugese speaking people ;-)
- when you see: "##walter - inicio" it means "##walter - start"
- when you see: "##walter - fim" it means "##walter - end"

------------------------------------------------------

To be honest, I'm using this idea to insert validation code too...

Comments ?


Walter



Attachment: HibernateEntity.vsl
Description: Binary data

Reply via email to