In this introduction, it will be shown how to generate code
- using the Torque generation framework (torque-gf).
+ using the Torque generator.
Maven 2 is used as a build tool (although the example can
also be run using plain java),
a xml source file is used as input for generation and
@@ -37,7 +37,7 @@
are described; and detailed by a simple example: We have a properties file
and want to create a java enum which contains the keys as constants.
The sample files can be found in the src/test/site/gettingStarted
- directory of the torque-gf sources.
+ directory of the torque-generator sources.
In our example, from the source
@@ -97,7 +97,8 @@
Create a root folder for your project. In the root folder, create a
src/main/torque-gf folder. This is where all the files for
- torque-gf go. In the torque-gf folder, create a "conf" subdirectory
+ the torque generator go.
+ In the torque-gf folder, create a "conf" subdirectory
(this is where the main configuration goes), a "templates" subdirectory
(for the velocity templates), a "generatorDefs" subdirectory
(for the definition of the generators) and a "src" directory
@@ -112,7 +113,7 @@
As a starting point, create the source file which keeps the information
you need to generate the output (to MDA addicts,
this is known as the "Metamodel instance". There is no explicit metamodel
- needel, it is defined implicitly by the templates.).
+ needed, it is defined implicitly by the templates.).
In our example, the source will be the property file listed above.
@@ -177,15 +178,16 @@
$torqueGf.mergepoint("methods")##
}
]]>
- As mentioned above, velocity is used
- as template language. This introduction does not cover the velocity
- template language itself; if you are not familiar with velocity,
- look at the velocity documentation.
+ As mentioned above, velocity
+ is used as template language.
+ This introduction does not cover the velocity template language itself;
+ if you are not familiar with velocity, look at
+ the velocity documentation.
The interesting part in the template is the call of the mergepoint method
of the torqueGf Object. The torqueGf object is placed into the velocity
- context by torque-gf and contains methods for defining mergepoints
- and accessing the source, options and variables. See
+ context by the torque generator and contains methods for defining
+ mergepoints and accessing the source, options and variables. See
its javadoc
for the available methods.
@@ -195,8 +197,8 @@
source file. For outputting simple data, this is simple:
The velocity construct "${key}" accesses the object named "key"
in the velocity context. The "key" object is put in the velocity
- context by torque-gf, which by default puts all attributes of the
- current source element into the velocity context.
+ context by the torque generator, which by default puts all attributes
+ of the current source element into the velocity context.
For the name of the constant, the key would also be used, but it needs
to be processed in some way (capitalized, underscores added).
For this processing we will use a built-in java generator, which
@@ -204,7 +206,7 @@
Finally, we need a comma after each definition, except for the last
definition, where we need a semicolon. To decide whether to render the
comma or the semicolon, we fetch the current source element from
- torgue-gf (${torqueGf.getSourceElement()) and ask it whether it
+ torgueGf (${torqueGf.getSourceElement()) and ask it whether it
has following siblings (i.e. source elements with the same parent
and the same name) (see
the RichSourceElementImpl javadoc
@@ -294,8 +296,9 @@
tag inside the "output" tag.
- Each "output" tag needs a "source" tag which tells torque-gf which source
- file to use. If you want to create more than one output file per "output"
+ Each "output" tag needs a "source" tag which tells the torque generator
+ which source file to use.
+ If you want to create more than one output file per "output"
tag, use the "elements" attribute of the "source" tag to select the
root elements for the different output files.
Now that we have created the templates and defined our input and output,
we must plug the templates into each other.
- Torque-gf encapsulates each template in a concept named
+ The torque generator encapsulates each template in a concept named
"generator". Each generator acts on a source element and produces a
String output from it. Also, a generator can define so-called
"mergepoints" where it can call insert the output of other generators.
@@ -506,8 +511,8 @@
}
}]]>
- Add all the dependencies of torque-gf into the classpath, and
- start this java program in the root directory of your project.
+ Add all the dependencies of the torquegenerator into the classpath,
+ and start this java program in the root directory of your project.
The generated source will show up in the target/generated-sources
subdirectory.
Modified: db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/modules/generator/index.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/modules/generator/index.xml?rev=917974&r1=917973&r2=917974&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/modules/generator/index.xml (original)
+++ db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/modules/generator/index.xml Tue Mar 2 11:25:23 2010
@@ -21,20 +21,32 @@
- Torque Generation Framework
+ Torque Generator
- The Torque Generation Framework is a framework for generation of code.
- It is intended to make code generation easy and provides all necessary
- ingredients like reading in the sources, possibly transforming the
- sources before generation, applying templates, writing the output files,
- and plugging code generation into your build process. Of course, you still
- need to write the generation templates and possibly transformators,
- link them together and define which templates are used for which output
- file.
+
+ The Torque generator is a general-purpose code generator.
+ It is intended to make code generation easy and provides all necessary
+ ingredients like reading in the sources, possibly transforming the
+ sources before generation, applying templates, writing the output files,
+ and plugging code generation into your build process. Of course, you still
+ need to write the generation templates and possibly transformators,
+ link them together and define which templates are used for which output
+ file.
+
+
+
+
+ The Torque generator is also used to generate the OM Classes and SQL
+ for the Torque persistence framework. This part, however, is not covered
+ in the documentation of the generator, but in the documentation of
+ the templates.
+
- The maven 2 torque-gf plugin provides the maven 2 integration of the
- torque-gf Code generation Framework.
+ The Torque maven 2 plugin provides the maven 2 integration of the
+ Torque generator.
- The only goal this plugin offers is the "generate" goal, which
- starts the torque-gf generation process.
+ The only goal this plugin offers corrently is the "generate" goal, which
+ starts the torque generator.
A basic configuration for using pre-defined templates would be