[prev in list] [next in list] [prev in thread] [next in thread] 

List:       velocity-user
Subject:    Re: DVSL
From:       "Geir Magnusson Jr." <geirm () optonline ! net>
Date:       2002-01-31 15:13:37
[Download RAW message or body]

On 1/31/02 9:51 AM, "AFASA Corneil du Plessis" <Corneil@afa.co.za> wrote:

> I am busy developing a Toolbox addin for DVSL to help with source
> generation.
> I have an interesting problem that leads me to ask the question, if you
> consider the following sample, when will Writer.write be called on the
> Writer that was passed into dvsl.transform
> 
> I am passing in a class derived from Writer that will determine which
> Writer to invoke and the .write only gets called after
> $context.toolbox.cg.close()
> if I remove that line it works like expected for one file, if I open a
> second file all output is written to the last file.
> 
> 
> ========================================
> #match("DICT")
> #set( $outputdirectory = "Musk134" )
> #set( $outpackage = "musk" )
> $context.toolbox.cg.setdir("Musk134/musk")
> $context.toolbox.cg.output("POIModelInfo.java")
> package ${outpackage};
> /**
>       CLASS:POIModelInfo
> */
> public class POIModelInfo {
>   public static final String DATABASE_NAME = "${attrib.name}";
>   public static final int MODEL_NUMBER = "${attrib.model}";
>   public static final int DATABASE_VERSION = "${attrib.version}";
>   public static final boolean Check() {
>       return poi.POIJava.GetModelNumber() == MODEL_NUMBER &&
>           poi.POIJava.GetDatabaseVersion() == DATABASE_VERSION &&
>           poi.POIJava.GetDatabaseName().equals(DATABASE_NAME);
>   }
>   public static String GetDatabaseName() {
>       return DATABASE_NAME;
>   }
>   public static int GetDatabaseVersion() {
>       return DATABASE_VERSION;
>   }
>   public static int GetModelNumber() {
>       return MODEL_NUMBER;
>   }
> }
> $context.toolbox.cg.close()
> #end
> =========================================
> 
> This makes me think that there is some kind of delay before rendering
> completes, do you have some kind of internal stack of elements.

Yes, there is a stack of elements, but not sure how that applies.

Just to be clear - you are trying to switch the writer underneath?

You might be able to get the same effect if you did something like :


#macro( whatever $attrib )
/**
        CLASS:POIModelInfo
*/
public class POIModelInfo {
    public static final String DATABASE_NAME = "${attrib.name}";
    public static final int MODEL_NUMBER = "${attrib.model}";
    public static final int DATABASE_VERSION = "${attrib.version}";
    public static final boolean Check() {
        return poi.POIJava.GetModelNumber() == MODEL_NUMBER &&
            poi.POIJava.GetDatabaseVersion() == DATABASE_VERSION &&
            poi.POIJava.GetDatabaseName().equals(DATABASE_NAME);
    }
    public static String GetDatabaseName() {
        return DATABASE_NAME;
    }
    public static int GetDatabaseVersion() {
        return DATABASE_VERSION;
    }
    public static int GetModelNumber() {
        return MODEL_NUMBER;
    }
}

#end

#match("DICT")
#set( $outputdirectory = "Musk134" )
#set( $outpackage = "musk" )
$context.toolbox.cg.setdir("Musk134/musk")
$context.toolbox.cg.output("POIModelInfo.java")
$context.toolbbox.cg.write("package ${outpackage};")
$context.toolbox.cg.write("#whatever( $attrib )" )
$context.toolbox.cg.close()
#end


:)


-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic