You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Max Rydahl Andersen <ma...@acure.dk> on 2003/09/24 15:12:42 UTC

Lazy writing in middle of output ?

Hi!

Is there any good way to lazy insert contents that can only be calulated 
after the file has been processed ?

My usecase is for a codegenerator (hbm2java in Hibernate) which 
optimizes the import statements in top of the file during the generation 
of the class body.

So something like this (pseudo code)

package $class.packageName

$class.lazyGeneratedImportStatements

class $class.className extends .... {

...
...
   $class.getReducedType($field.type) #add FQN of type to 
importStatements and return the shortest possible type

}


Previously I did this by hand in my hbm2java by writing the stuff in two 
writers and just combine the stuff afterwards.

And ideas ?

/max




---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Lazy writing in middle of output ?

Posted by Mike Kienenberger <mk...@alaska.net>.
Max Rydahl Andersen <ma...@acure.dk> wrote:
> Is there any good way to lazy insert contents that can only be calulated 
> after the file has been processed ?
> 
> My usecase is for a codegenerator (hbm2java in Hibernate) which 
> optimizes the import statements in top of the file during the generation 
> of the class body.

I recommend iterating through your data model's attributes and relationships 
at the top of the file, then outputing the import statements based on what 
you find.   That's what I do these days with Cayenne and Velocity, and it's 
what I've done with WebObjects/EOF/Toplink and MiscMerge in the past.

Yes, it's "inefficient" and duplicates code, but it's not like you're going 
to notice the performance hit.  Some code duplication has to be expected to 
generate data models into java classes with a template.

There's no need to make it a two-step process.

-Mike

Re: Lazy writing in middle of output ?

Posted by Mike Kienenberger <mk...@alaska.net>.
Max Rydahl Andersen <ma...@acure.dk> wrote:
> Is there any good way to lazy insert contents that can only be calulated 
> after the file has been processed ?
> 
> My usecase is for a codegenerator (hbm2java in Hibernate) which 
> optimizes the import statements in top of the file during the generation 
> of the class body.

I recommend iterating through your data model's attributes and relationships 
at the top of the file, then outputing the import statements based on what 
you find.   That's what I do these days with Cayenne and Velocity, and it's 
what I've done with WebObjects/EOF/Toplink and MiscMerge in the past.

Yes, it's "inefficient" and duplicates code, but it's not like you're going 
to notice the performance hit.  Some code duplication has to be expected to 
generate data models into java classes with a template.

There's no need to make it a two-step process.

-Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org