|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.jostraca.Generator
A utility class that you can use inside your own applications for generating code.
You will need to include jostraca.jar
(found in the lib folder of the distribution)
in your classpath.
The simplest example is:
Generator g = new Generator();
g.generate( "template.jtm" );
You can specify the template using a String file path or a File object.
Generator uses the default internal configuration so that it will
work without any configuration files. To use Jostraca configuration files,
specify a configuration folder using the constructors Generator(File)
or Generator(String).
You can also specify the settings to use when generating by passing in a
PropertySet object, with your required settings.
For example:
Generator g = new Generator();
PropertySet ps = new PropertySet();
ps.set( "main.MakeBackup", "no" );
g.setCmdPropertySet( ps );
g.generate( "template.jtm" );
For a complete list of all configuration settings see the
Configuration Settings reference.
To generate more than one template, use the generate(String[])
and generate(File[]) methods.
You can use the same Generator object multiple times.
If the template you are generating only generates one output file, you
can retrieve the result of the generation by calling Template.getResult() on the
Template object that is returned by the generate methods.
Note that this only works when you are using Java as the template script, and when you
execute the template CodeWriter internally (this is the default).
To gain access to any error messages use the getUserMessageHandler() method.
This returns a RecordingUserMessageHandler object by default,
which you will need to cast from the UserMessageHandler interface returned by getUserMessageHandler.
To use your own UserMessageHandler,
use the method generate(String,UserMessageHandler) and its equivalents.
To send output to STDOUT, use the CommandLineUserMessageHandler
as the UserMessageHandler parameter.
| Constructor Summary | |
Generator()
Create a new Generator with the default configuration. |
|
Generator(java.io.File pConfigFolder)
Create a new Generator with configuration files in the specified configuration folder. |
|
Generator(java.lang.String pConfigFolder)
Create a new Generator with configuration files in the specified configuration folder. |
|
| Method Summary | |
Template |
generate(java.io.File pTemplate)
Generate the specified template. |
Template[] |
generate(java.io.File[] pTemplates)
Generate more than one template. |
Template[] |
generate(java.io.File[] pTemplates,
UserMessageHandler pUserMessageHandler)
Generate more than one template. |
Template |
generate(java.io.File pTemplate,
UserMessageHandler pUserMessageHandler)
Generate the specified template. |
java.util.List |
generate(java.util.List pTemplatePaths)
Generate more than one template. |
java.util.List |
generate(java.util.List pTemplatePaths,
UserMessageHandler pUserMessageHandler)
Generate more than one template. |
Template |
generate(java.lang.String pTemplate)
Generate the specified template. |
Template[] |
generate(java.lang.String[] pTemplates)
Generate more than one template. |
Template[] |
generate(java.lang.String[] pTemplates,
UserMessageHandler pUserMessageHandler)
Generate more than one template. |
Template |
generate(java.lang.String pTemplate,
UserMessageHandler pUserMessageHandler)
Generate the specified template. |
Template |
generate(TemplatePath pTemplatePath)
Generate the specified template. |
Template |
generate(TemplatePath pTemplatePath,
UserMessageHandler pUserMessageHandler)
Generate the specified template. |
Service |
getService()
Return the internal instance of the Service object used to perform the generation. |
UserMessageHandler |
getUserMessageHandler()
Return the UserMessageHandler used during generation. |
protected void |
init(java.io.File pConfigFolder)
Initialise from config folder. |
void |
setAlwaysGenerate(boolean pAlwaysGenerate)
Always generate template, even if up-to-date (default: true). |
void |
setCmdPropertySet(PropertySet pCmdPropertySet)
Specifically set some configuration properties. |
void |
setContext(java.lang.Object pContext)
Set a context object (which can be anything) for the template. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Generator()
public Generator(java.lang.String pConfigFolder)
pConfigFolder - folder pathpublic Generator(java.io.File pConfigFolder)
pConfigFolder - config folderGenerator(String)| Method Detail |
protected void init(java.io.File pConfigFolder)
pConfigFolder - config folderpublic void setCmdPropertySet(PropertySet pCmdPropertySet)
public void setContext(java.lang.Object pContext)
Set a context object (which can be anything) for the template. This object is then available directly to the template by calling _getContext.
NOTE: this will only work if the template scripting lanaguage is Java and the template is generated internally (this is the default).
public void setAlwaysGenerate(boolean pAlwaysGenerate)
true).
Set this to false is you do not wish to regenerate templates
that are up-to-date. Note that this means that some templates may not return
any results from the the Template.getResult() method as they will not have
been executed.
If you set
main.ExecuteCodeWriter directly using setCmdPropertySet(org.jostraca.util.PropertySet) then that setting has precedence and this option is ignored.
pAlwaysGenerate - always generate templatepublic Template generate(java.io.File pTemplate)
pTemplate - template file path
public Template generate(java.io.File pTemplate,
UserMessageHandler pUserMessageHandler)
UserMessageHandler.
pTemplate - template file pathpUserMessageHandler - UserMessageHandler implementationpublic Template[] generate(java.io.File[] pTemplates)
generate(File)
public Template[] generate(java.io.File[] pTemplates,
UserMessageHandler pUserMessageHandler)
generate(File,UserMessageHandler)public Template generate(java.lang.String pTemplate)
pTemplate - template file path
public Template generate(java.lang.String pTemplate,
UserMessageHandler pUserMessageHandler)
UserMessageHandler.
pTemplate - template file pathpUserMessageHandler - UserMessageHandler implementationpublic Template[] generate(java.lang.String[] pTemplates)
generate(String)
public Template[] generate(java.lang.String[] pTemplates,
UserMessageHandler pUserMessageHandler)
generate(String,UserMessageHandler)public Template generate(TemplatePath pTemplatePath)
TemplatePath.
pTemplatePath - template file pathgenerate(File)
public Template generate(TemplatePath pTemplatePath,
UserMessageHandler pUserMessageHandler)
UserMessageHandler.
pTemplatePath - template file pathpUserMessageHandler - UserMessageHandler implementationgenerate(TemplatePath)public java.util.List generate(java.util.List pTemplatePaths)
generate(TemplatePath)
public java.util.List generate(java.util.List pTemplatePaths,
UserMessageHandler pUserMessageHandler)
generate(TemplatePath,UserMessageHandler)public UserMessageHandler getUserMessageHandler()
UserMessageHandler used during generation.
By default this is a RecordingUserMessageHandler, unless you
have provided your own via a method such as generate(File,UserMessageHandler).
Use the toString methods to gain access to the error message Strings.
public Service getService()
Service object used to perform the generation.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||