|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectijgen.generator.engine.TemplateGenerator
public abstract class TemplateGenerator
Abstract class representing a generator working on a set of template files.
Field Summary | |
---|---|
protected java.util.List<ClassDefinition> |
classDefinitions
Class definitions which will be passed to the abstract doGenerate() method |
protected java.lang.String |
customLine
Contains the string describing that file is already customized and should not be overriden by the generator. |
protected java.lang.String |
fileFilter
Holds the extension that is used for filter which templates has to be proccessed by generator. |
protected java.lang.String |
generatedExtension
Specifies the extension for generated artifacts. |
protected java.lang.String |
outputPath
Variable specifying the output path for the generated artifacts |
Constructor Summary | |
---|---|
protected |
TemplateGenerator()
Default constructor. |
Method Summary | |
---|---|
protected abstract void |
doGenerate(java.util.Map<java.lang.String,java.io.File> templates,
java.util.List<ClassDefinition> classDefinitions)
Abstract method that should be overridden by all child classes. |
void |
generate()
Template method that prepares the parameters and run the actual implementation of doGenerate() with these parameters. |
protected abstract java.lang.String |
getCustomLine()
Abstract method that forces successors of this class to specify the custom line which indicates that the artifact is already customized and should not be generated anymore. |
protected abstract java.lang.String |
getFileFilter()
Abstract method that forces successors of this class to specify extension of the template files that has to be processed. |
protected abstract java.lang.String |
getGeneratedExtension()
Abstract method that forces successors of this class to specify the file extension which will be received by the generated artifacts. |
java.lang.String |
getOutputPath()
Gets the path to the directory where generated artifacts will be stored. |
protected java.util.Map<java.lang.String,java.io.File> |
getTemplateFiles()
Gets cached instance of template files. |
protected org.apache.velocity.Template |
getVelocityTemplate(java.io.File templateFile)
Creates a velocity template from the specified file which contains the path to the actual resource containing the template. |
protected org.apache.velocity.VelocityContext |
prepareContext(java.lang.String templateName)
Prepares instance of VelocityContext and populates it with the standard attributes |
protected java.lang.String |
readFirstFileLine(java.lang.String filePath)
Simple utility method that just reads the first line of the file specified as a parameter. |
protected void |
setClassDefinitions(java.util.List<ClassDefinition> classDefinitions)
Sets list of model definitions that will be processed by the generator. |
void |
setCustomLine(java.lang.String customLine)
Sets the string which indicates that file is customized and should not be overridden. |
void |
setFileFilter(java.lang.String fileFilter)
Sets the extension of template files that should be processed by this generator. |
void |
setGeneratedExtension(java.lang.String generatedExtension)
Sets the extension of files produced by this generator. |
void |
setGlobalSettings(GlobalSettings globalSettings)
Sets the global settings object. |
void |
setOutputPath(java.lang.String outputPath)
Sets the path to the directory where generated artifacts will be stored. |
void |
setTemplatesCache(java.util.Map<java.lang.String,java.io.File> templatesCache)
Sets the cache with template files. |
protected void |
writeToFile(ClassDefinition classDefinition,
java.lang.String layer,
boolean appendPackage,
byte[] content)
Writes to a physical file produced artifact by the generator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String outputPath
protected java.util.List<ClassDefinition> classDefinitions
protected java.lang.String customLine
protected java.lang.String fileFilter
protected java.lang.String generatedExtension
Constructor Detail |
---|
protected TemplateGenerator()
Method Detail |
---|
public void setGlobalSettings(GlobalSettings globalSettings)
globalSettings
- globalSettingspublic final void setCustomLine(java.lang.String customLine)
customLine
- custom stringpublic final void setFileFilter(java.lang.String fileFilter)
fileFilter
- public final void setGeneratedExtension(java.lang.String generatedExtension)
generatedExtension
- name of the extensionpublic final void setTemplatesCache(java.util.Map<java.lang.String,java.io.File> templatesCache)
templatesCache
- template files cachepublic final java.lang.String getOutputPath()
public final void setOutputPath(java.lang.String outputPath)
outputPath
- output directoryprotected final void setClassDefinitions(java.util.List<ClassDefinition> classDefinitions)
classDefinition
- class definitionsprotected abstract void doGenerate(java.util.Map<java.lang.String,java.io.File> templates, java.util.List<ClassDefinition> classDefinitions) throws java.lang.Exception
templates
- map containing a cache with template filesclassDefinitions
- model definitions
java.lang.Exception
protected abstract java.lang.String getFileFilter()
protected abstract java.lang.String getCustomLine()
protected abstract java.lang.String getGeneratedExtension()
public final void generate()
protected final java.util.Map<java.lang.String,java.io.File> getTemplateFiles()
protected final void writeToFile(ClassDefinition classDefinition, java.lang.String layer, boolean appendPackage, byte[] content) throws java.io.IOException
classDefinition
- ClassDefinition object used to produce the artifactlayer
- name of the layer/template used for generation of the artifactappendPackage
- true if package has to be considered as a directory structurecontent
- content that has to be written in the file
java.io.IOException
- if something goes wrong in the IO operationsprotected final java.lang.String readFirstFileLine(java.lang.String filePath) throws java.io.IOException
filePath
- path to the file
java.io.IOException
protected final org.apache.velocity.Template getVelocityTemplate(java.io.File templateFile) throws java.lang.Exception
templateFile
- File object containing the path to the velocity template file
java.lang.Exception
- if some problem occursprotected final org.apache.velocity.VelocityContext prepareContext(java.lang.String templateName)
templateName
- name of the templates that is being currently processed
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |