org.jostraca
Class Generator

java.lang.Object
  extended byorg.jostraca.Generator

public class Generator
extends java.lang.Object

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

Generator

public Generator()
Create a new Generator with the default configuration.


Generator

public Generator(java.lang.String pConfigFolder)
Create a new Generator with configuration files in the specified configuration folder. Jostraca stores configuration files in the conf folder of the distribution, so you can use these to get the defautl behaviour.

Parameters:
pConfigFolder - folder path

Generator

public Generator(java.io.File pConfigFolder)
Create a new Generator with configuration files in the specified configuration folder.

Parameters:
pConfigFolder - config folder
See Also:
Generator(String)
Method Detail

init

protected void init(java.io.File pConfigFolder)
Initialise from config folder.

Parameters:
pConfigFolder - config folder

setCmdPropertySet

public void setCmdPropertySet(PropertySet pCmdPropertySet)
Specifically set some configuration properties. These settings are handled equivalently to command line options.

See Also:
Configuration Settings

setContext

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).


setAlwaysGenerate

public void setAlwaysGenerate(boolean pAlwaysGenerate)
Always generate template, even if up-to-date (default: 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.

Parameters:
pAlwaysGenerate - always generate template

generate

public Template generate(java.io.File pTemplate)
Generate the specified template.

Parameters:
pTemplate - template file path

generate

public Template generate(java.io.File pTemplate,
                         UserMessageHandler pUserMessageHandler)
Generate the specified template. Messages are sent to the specified UserMessageHandler.

Parameters:
pTemplate - template file path
pUserMessageHandler - UserMessageHandler implementation

generate

public Template[] generate(java.io.File[] pTemplates)
Generate more than one template.

See Also:
generate(File)

generate

public Template[] generate(java.io.File[] pTemplates,
                           UserMessageHandler pUserMessageHandler)
Generate more than one template.

See Also:
generate(File,UserMessageHandler)

generate

public Template generate(java.lang.String pTemplate)
Generate the specified template.

Parameters:
pTemplate - template file path

generate

public Template generate(java.lang.String pTemplate,
                         UserMessageHandler pUserMessageHandler)
Generate the specified template. Messages are sent to the specified UserMessageHandler.

Parameters:
pTemplate - template file path
pUserMessageHandler - UserMessageHandler implementation

generate

public Template[] generate(java.lang.String[] pTemplates)
Generate more than one template.

See Also:
generate(String)

generate

public Template[] generate(java.lang.String[] pTemplates,
                           UserMessageHandler pUserMessageHandler)
Generate more than one template.

See Also:
generate(String,UserMessageHandler)

generate

public Template generate(TemplatePath pTemplatePath)
Generate the specified template. The template is specified by using the abstract template path description TemplatePath.

Parameters:
pTemplatePath - template file path
See Also:
generate(File)

generate

public Template generate(TemplatePath pTemplatePath,
                         UserMessageHandler pUserMessageHandler)
Generate the specified template. Messages are sent to the specified UserMessageHandler.

Parameters:
pTemplatePath - template file path
pUserMessageHandler - UserMessageHandler implementation
See Also:
generate(TemplatePath)

generate

public java.util.List generate(java.util.List pTemplatePaths)
Generate more than one template.

Returns:
List of Template objects
See Also:
generate(TemplatePath)

generate

public java.util.List generate(java.util.List pTemplatePaths,
                               UserMessageHandler pUserMessageHandler)
Generate more than one template.

Returns:
List of Template objects
See Also:
generate(TemplatePath,UserMessageHandler)

getUserMessageHandler

public UserMessageHandler getUserMessageHandler()
Return the 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.


getService

public Service getService()
Return the internal instance of the Service object used to perform the generation.



Copyright © 2000-2002 Richard Rodger