Glossary |
| Term | Description |
|---|
CodeWriter
[ top ] |
The CodeWriter program is the main mechanism of
the Jostraca code generation process. Each template is compiled into
a CodeWriter program. This program is then
executed to generate the final output files.
template -> CodeWriter -> generated files
The CodeWriter program is created by merging a
WriterFormat file and the template. The
template text and script are converted to the appropriate functions
calls in the template script langauge. These function calls are
then inserted into the appropriate parts of the
WriterFormat to create the
CodeWriter program source code. The
CodeWriter source code file is then compiled
and executed.
Note: the CodeWriter program can be named using the
main.CodeWriter configuration option. By default,
the CodeWriter program is named by suffixing the
name of the template with Writer.ext, where ext
is the standard extension for the template script language.
See:
WriterFormat
|
WriterFormat
[ top ] |
The WriterFormat source code file provides a program
framework in the template script language. Typically this framework
provides implementations of the template service methods and the
actual output file creation functions.
The WriterFormat source code uses a special syntax to
indicate where template text and script sections from the template
are to be inserted. Settings may also be inserted using this
mechanism.
Example:
!<foo> // insert contents of section 'foo'
$<bar> // insert value of setting 'bar'
See:
CodeWriter
|
file name prefix
[ top ] |
Text string placed before the name of the generated file. This useful
when generating more than one file from the same template, when the
generated files have a common file name prefix.
See:
file name root
|
file name root
[ top ] |
When you are generating only one file with Jostraca, you can use
_setFullFileName method in the init section of the template to set the name of
the generated file. When generating more than one file, you can use
_setFullFileNames to set the list of
files to generate.
It is often the case that you want to generate serveral files at the
same time. For example, a series of .java files, or a
series of .xml files. In this case, it is easier to
use _setFileNameSuffix to set the file
name extension, and _setFileNameRoots to
set the list of file names (without the extension). This can be very
useful when you want to use the file names to index an external data
structure, without polluting that data structure with file name
extensions. Use the _getFileNameRoot
method to get the file name root value.
As an example, let's say we want to generate Java classes for the
each of the following entities, specified in an XML file:
<data-structure>
<entity name="Red" size="small" />
<entity name="Green" size="medium" />
<entity name="Blue" size="large" />
</data-structure>
Assume that we have loaded this XML data and created a Hashtable for
the size attribute, indexed by the name of the
entity. Then to generate our Java clasess we can use the following
template
...
<% init!
...
// loadSizeTable returns the Hashtable:
// { "Red"=>"small", "Green"=>"medium", "Blue"=>"large" }
Hashtable sizeTable = loadSizeTable( XmlFile );
// getEntityNames returns the array { "Red", "Green", "Blue" }
_setFileNameRoots( getEntityNames( XmlFile ) );
_setFileNameSuffix( ".java" );
%>
<% String entityName = _getFileNameRoot(); %>
public class <%=entityName%> {
public static final String SIZE = "<%=sizeTable.get( entityName )%>";
}
...
|
file name suffix
[ top ] |
Text string placed after the name of the generated file. This useful
when generating more than one file from the same template, when the
generated files have a common file name suffix. In particular, this
can be used to set the file name extension for each file.
See:
file name root
|
output folder
[ top ] |
Jostraca places generated files in an output folder specified by the
command line option -o.
Jostraca uses the CodeWriter
program to create the generated files and to save them in the output
folder. This program must itself be saved somewhere and it is normally
saved in the same output folder as the generated files themselves.
If you want to place the CodeWriter
program in a different folder, you can use the -w
option to specify the work folder separately from
the output folder.
Thus we have the pattern:
template -> CodeWriter -> generated files
current folder -> work folder -> output folder
|
work folder
[ top ] |
The folder where Jostraca saves additional work files.
See:
output folder
|
metadata folder
[ top ] |
The folder where Jostraca saves template metadata.
See:
work folder
|
backup folder
[ top ] |
Jostraca automatically backs up old versions of generated files to a
separate folder. This backup folder can be specified on
the command line using the -b option. You
can also disable backups using the -B
option.
|
template service method
[ top ] |
Jostraca templates can control exactly how they are to be used. The
definition of which files to generate, where to save these files and with
what names, can all be specified using the specially provided
template service methods such as _setFileNameRoot and _setOutputFolder.
Additional methods are provided for laying out text (_left), controlling backups (_setBackupFolder), getting the values of
command line arguments (_getFirstUserArg()), and getting the current
status of the file generation operation (_getFileIndex()).
|