Hi Stefan,
What you need to do here is something along the lines of the
following, in your plugin class:
public Date getSomeDate() {
return new Date();
}
and in your velocity to template, you'll be able to access this date
with ${someDate}
(or $someDate, in this case brackets shouldn't matter, I think). - No
need for velocity-tools here. (You might want to apply some formatting
to your date and return it as a String instead, maybe, I'll leave that
up to you. Also, if you need precision, you'll want to reuse the same
Date instead, altough i don't expect any plugin to run for more than a
second ;))
The "metadata" object you tried to access is something totally
different. Generama uses it to access its input. In the specific case
of xdoclet, this means your source files. (Or their parsed content)
Hope this helps,
greg
On 14/12/05, Stefan Undorf <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I'm just making my first steps with XDoclet(2). First thanks for sharing
> this tool.
>
> I tried to to output the creation date in my generated files. The first
> attempt was to add velocity-tools-1.2.jar to my classpath and generate -
> without any results. The $date tag in the 2nd line of the script is simply
> ignored. This is my velocity script:
>
> *** start velocity script ***
> #set( $class = $metadata )
> //Created on $date
> //Created on $date.format('medium',$myObjectName)
>
>
> public class ${class.getName()} extends ${class.getName()}Standard {}
> *** end velocity script ***
>
> Then I thought about providing a date object from my java class to the
> script which could be used in line 3 of the velocity script. This is my java
> class:
>
> *** start java class ***
> import java.util.Date;
>
> import org.generama.QDoxCapableMetadataProvider;
> import org.generama.VelocityTemplateEngine;
> import org.generama.WriterMapper;
> import org.generama.defaults.JavaGeneratingPlugin;
>
> public class EntityClassImplPlugin extends JavaGeneratingPlugin {
>
> public EntityClassImplPlugin(VelocityTemplateEngine
> velocityTemplateEngine,
> QDoxCapableMetadataProvider metadataProvider,
> WriterMapper writerMapper)
> throws ClassNotFoundException {
>
> super(velocityTemplateEngine, metadataProvider, writerMapper);
> //metadataProvider.getMetadata().add("myDate", new Date());
> setMultioutput(true);
> }
> }
> *** end java class ***
>
> In line 16 I tried to provide my data object. Of course this is not
> possible. Is there an alternative?
>
> Thanks in advance,
> Stefan
>
>