You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jonathan Carlson <jo...@yahoo.com> on 2002/02/01 16:17:11 UTC
Re: DVSL writer
Geir, Is your suggestion below an implemented solution that I could use
right now? Or were you just suggesting how to implement the ability to
switch where the output goes?
This appears to be exactly what I would want for code generation.
Jonathan
--
Jonathan Carlson
joncrlsn@users.sf.net
Minneapolis, Minnesota
Geir Magnusson Jr. wrote:
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
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: DVSL writer (custom output location)
Posted by Jonathan Carlson <jo...@yahoo.com>.
Here's some example DVSL code to use the tool below:
#*
==========================================================================
*#
#match ("class")
#set ( $filename = "D:/play/dvsl/bld/src/play/${attrib.class-name}.java" )
$context.toolbox.mywriter.setFile( $filename )
$context.toolbox.mywriter.write("#classMacro() ")
$context.toolbox.mywriter.close()
#end
#macro ( classMacro )
public class ${attrib.class-name}()
{
// code here
}
#end
Here's the mywriter tool (it's awful simple, but that's a positive):
--------------------------------------------------------------------------------
import java.io.IOException;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
/** Custom output tool for DVSL */
public class MyWriter
{
private File currentFile = null;
private Writer currentWriter = null;
/**
* Write output to current open file
*
* @param str a String to be immediately written to the current writer
*/
public void write(String str)
throws IOException
{
if (currentWriter != null)
{
System.out.println("Writing to file: " + currentFile.getPath());
currentWriter.write(str);
}
}
/**
* Sets the File attribute of the MyWriter object
*
* @param str The new File path
*/
public void setFile(String str)
throws IOException
{
if (currentWriter != null)
{
close();
}
System.out.println("Setting output file to: " + str);
currentFile = new File(str);
currentWriter = new FileWriter(currentFile);
}
/** Close the current writer. */
public void close()
throws IOException
{
if (currentWriter != null)
{
currentWriter.close();
currentWriter = null;
}
}
}
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: DVSL writer
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 2/1/02 5:58 PM, "Jonathan Carlson" <jo...@yahoo.com> wrote:
> Everything works great. Thanks! If you want the working code, I can
> post it (not that you couldn't recreate it in a few minutes). I'm very
> excited.
Post it. Put your name on it :) We'll find a home for it.
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
"Now what do we do?"
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: DVSL writer
Posted by Jonathan Carlson <jo...@yahoo.com>.
Everything works great. Thanks! If you want the working code, I can
post it (not that you couldn't recreate it in a few minutes). I'm very
excited.
Jonathan
--
Jonathan Carlson
joncrlsn@users.sf.net
Minneapolis, Minnesota
Geir Magnusson Jr. wrote:
>On 2/1/02 5:03 PM, "Jonathan Carlson" <jo...@yahoo.com> wrote:
>
>>Thanks! I made it a lot harder than it needed to be.
>>
>>When I call a #macro from inside a #match block will it have access to
>>the $node and $attrib objects just like it was inside a #match block?
>>
>
>Yes, I think so. It's just anormal template to Velocity.
>
>I hope. Try it :)
>
>geir
>
>>Jonathan
>>
>>Geir Magnusson Jr. wrote:
>>
>>>On 2/1/02 3:33 PM, "Jonathan Carlson" <jo...@yahoo.com> wrote:
>>>
>>>>I'm not sure I understand the underworkings of DVSL or Velocity enough
>>>>yet to write it, so if you would, that would be great. I'll do some
>>>>looking around and if I decide to stab at it I'll let you know.
>>>>
>>>>Jonathan
>>>>
>>>You don't need to know *anything* about DVSL or Velocity to do this. (Unless
>>>I am so wrong about this....) Here goes - this won't compile - if it does,
>>>I doubt it will work. I am typing this into the mail message. Add
>>>corrections and import statements.
>>>
>>>public class Thingy
>>>{
>>> private File currentFile = null;
>>> private Writer currentWriter = null;
>>>
>>> /**
>>> * write output to current open file
>>> */
>>> public void write( String str )
>>> {
>>> if ( currentWriter != null)
>>> {
>>> currentWriter.writer( str );
>>> }
>>> }
>>>
>>> public void setFile(String str )
>>> {
>>> if( currentWriter != null)
>>> {
>>> close();
>>> }
>>>
>>> currentFile = new File( str );
>>>
>>> currentWriter = new FileWriter( currentFile );
>>> }
>>>
>>> public void close()
>>> {
>>> if (currentWriter != null)
>>> {
>>> currentWriter.close();
>>> currentFile.close();
>>> }
>>> }
>>>}
>>>
>>>To use :
>>>
>>>Fix, compile, place in context
>>>
>>>Then
>>>
>>>#macro( mycode $classname)
>>>public class $classname
>>>{
>>> private int I;
>>>}
>>>#end
>>>
>>>#set($classname = 'Foo')
>>>$tool.setFile( "/tmp/$classname.java" )
>>>$tool.write("#mycode( $classname )" )
>>>$tool.close()
>>>
>>>
>>>That *should* work. No promises, but should. :)
>>>
>>
>>
>>
>>_________________________________________________________
>>
>>Do You Yahoo!?
>>
>>Get your free @yahoo.com address at http://mail.yahoo.com
>>
>>
>>
>>
>>--
>>To unsubscribe, e-mail:
>><ma...@jakarta.apache.org>
>>For additional commands, e-mail:
>><ma...@jakarta.apache.org>
>>
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: DVSL writer
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 2/1/02 5:03 PM, "Jonathan Carlson" <jo...@yahoo.com> wrote:
> Thanks! I made it a lot harder than it needed to be.
>
> When I call a #macro from inside a #match block will it have access to
> the $node and $attrib objects just like it was inside a #match block?
Yes, I think so. It's just anormal template to Velocity.
I hope. Try it :)
geir
>
> Jonathan
>
> Geir Magnusson Jr. wrote:
>
>> On 2/1/02 3:33 PM, "Jonathan Carlson" <jo...@yahoo.com> wrote:
>>
>>> I'm not sure I understand the underworkings of DVSL or Velocity enough
>>> yet to write it, so if you would, that would be great. I'll do some
>>> looking around and if I decide to stab at it I'll let you know.
>>>
>>> Jonathan
>>>
>>
>> You don't need to know *anything* about DVSL or Velocity to do this. (Unless
>> I am so wrong about this....) Here goes - this won't compile - if it does,
>> I doubt it will work. I am typing this into the mail message. Add
>> corrections and import statements.
>>
>> public class Thingy
>> {
>> private File currentFile = null;
>> private Writer currentWriter = null;
>>
>> /**
>> * write output to current open file
>> */
>> public void write( String str )
>> {
>> if ( currentWriter != null)
>> {
>> currentWriter.writer( str );
>> }
>> }
>>
>> public void setFile(String str )
>> {
>> if( currentWriter != null)
>> {
>> close();
>> }
>>
>> currentFile = new File( str );
>>
>> currentWriter = new FileWriter( currentFile );
>> }
>>
>> public void close()
>> {
>> if (currentWriter != null)
>> {
>> currentWriter.close();
>> currentFile.close();
>> }
>> }
>> }
>>
>> To use :
>>
>> Fix, compile, place in context
>>
>> Then
>>
>> #macro( mycode $classname)
>> public class $classname
>> {
>> private int I;
>> }
>> #end
>>
>> #set($classname = 'Foo')
>> $tool.setFile( "/tmp/$classname.java" )
>> $tool.write("#mycode( $classname )" )
>> $tool.close()
>>
>>
>> That *should* work. No promises, but should. :)
>>
>
>
>
>
> _________________________________________________________
>
> Do You Yahoo!?
>
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
POC lives!
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: DVSL writer
Posted by Jonathan Carlson <jo...@yahoo.com>.
Thanks! I made it a lot harder than it needed to be.
When I call a #macro from inside a #match block will it have access to
the $node and $attrib objects just like it was inside a #match block?
Jonathan
Geir Magnusson Jr. wrote:
>On 2/1/02 3:33 PM, "Jonathan Carlson" <jo...@yahoo.com> wrote:
>
>>I'm not sure I understand the underworkings of DVSL or Velocity enough
>>yet to write it, so if you would, that would be great. I'll do some
>>looking around and if I decide to stab at it I'll let you know.
>>
>>Jonathan
>>
>
>You don't need to know *anything* about DVSL or Velocity to do this. (Unless
>I am so wrong about this....) Here goes - this won't compile - if it does,
>I doubt it will work. I am typing this into the mail message. Add
>corrections and import statements.
>
>public class Thingy
>{
> private File currentFile = null;
> private Writer currentWriter = null;
>
> /**
> * write output to current open file
> */
> public void write( String str )
> {
> if ( currentWriter != null)
> {
> currentWriter.writer( str );
> }
> }
>
> public void setFile(String str )
> {
> if( currentWriter != null)
> {
> close();
> }
>
> currentFile = new File( str );
>
> currentWriter = new FileWriter( currentFile );
> }
>
> public void close()
> {
> if (currentWriter != null)
> {
> currentWriter.close();
> currentFile.close();
> }
> }
>}
>
>To use :
>
>Fix, compile, place in context
>
>Then
>
>#macro( mycode $classname)
>public class $classname
>{
> private int I;
>}
>#end
>
>#set($classname = 'Foo')
>$tool.setFile( "/tmp/$classname.java" )
>$tool.write("#mycode( $classname )" )
>$tool.close()
>
>
>That *should* work. No promises, but should. :)
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: DVSL writer
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 2/1/02 3:33 PM, "Jonathan Carlson" <jo...@yahoo.com> wrote:
> I'm not sure I understand the underworkings of DVSL or Velocity enough
> yet to write it, so if you would, that would be great. I'll do some
> looking around and if I decide to stab at it I'll let you know.
>
> Jonathan
You don't need to know *anything* about DVSL or Velocity to do this. (Unless
I am so wrong about this....) Here goes - this won't compile - if it does,
I doubt it will work. I am typing this into the mail message. Add
corrections and import statements.
public class Thingy
{
private File currentFile = null;
private Writer currentWriter = null;
/**
* write output to current open file
*/
public void write( String str )
{
if ( currentWriter != null)
{
currentWriter.writer( str );
}
}
public void setFile(String str )
{
if( currentWriter != null)
{
close();
}
currentFile = new File( str );
currentWriter = new FileWriter( currentFile );
}
public void close()
{
if (currentWriter != null)
{
currentWriter.close();
currentFile.close();
}
}
}
To use :
Fix, compile, place in context
Then
#macro( mycode $classname)
public class $classname
{
private int I;
}
#end
#set($classname = 'Foo')
$tool.setFile( "/tmp/$classname.java" )
$tool.write("#mycode( $classname )" )
$tool.close()
That *should* work. No promises, but should. :)
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: DVSL writer
Posted by Jonathan Carlson <jo...@yahoo.com>.
I'm not sure I understand the underworkings of DVSL or Velocity enough
yet to write it, so if you would, that would be great. I'll do some
looking around and if I decide to stab at it I'll let you know.
Jonathan
--
Jonathan Carlson
joncrlsn@users.sf.net
Minneapolis, Minnesota
Geir Magnusson Jr. wrote:
>On 2/1/02 10:17 AM, "Jonathan Carlson" <jo...@yahoo.com> wrote:
>
>>Geir, Is your suggestion below an implemented solution that I could use
>>right now? Or were you just suggesting how to implement the ability to
>>switch where the output goes?
>>
>
>If you have that object and it works as it appears (and you add the
>'write()' method, I can't see why it won't work.
>
>It's just Velocity at this point - nothing magical.
>
>I can try to cough up a tool to do this - it can't be that hard. Or you can
>take a shot...
>
>>This appears to be exactly what I would want for code generation.
>>
>
>It seems like a cool trick - as you get Velocity to do the templating, DVSL
>for the XML handling, and your tool (or in this case, Corneil's :) to manage
>the output.
>
>The problem is getting Velocity to complete a render, which it has to do for
>something like
>
> $foo.bar( "Render $this")
>
>which is not conceptually different than
>
> $foo.bar( "#whatever( $arg )")
>
>Let us know if you try it.
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: DVSL writer
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 2/1/02 10:17 AM, "Jonathan Carlson" <jo...@yahoo.com> wrote:
> Geir, Is your suggestion below an implemented solution that I could use
> right now? Or were you just suggesting how to implement the ability to
> switch where the output goes?
>
If you have that object and it works as it appears (and you add the
'write()' method, I can't see why it won't work.
It's just Velocity at this point - nothing magical.
I can try to cough up a tool to do this - it can't be that hard. Or you can
take a shot...
> This appears to be exactly what I would want for code generation.
It seems like a cool trick - as you get Velocity to do the templating, DVSL
for the XML handling, and your tool (or in this case, Corneil's :) to manage
the output.
The problem is getting Velocity to complete a render, which it has to do for
something like
$foo.bar( "Render $this")
which is not conceptually different than
$foo.bar( "#whatever( $arg )")
Let us know if you try it.
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>