- A model that describe your application - you don't need to define it yourself, you can use XMI or XML schema as the reference model. The only problem is how you parse them to the object model.
- A template engine - Velocity or Freemaker are good template engines in Java.
- Templates that corresponding to the model - Generate code Java, PHP, C#, etc.
- A configuration of templates - There would be configurations for desktop app, web app, RIA, or web services, etc.
- A parser that parse the configuration - If the configuration is an XML file, Apache's commons-digester library can help.
- A driver to glue up everthing.
- Optionally, a validator for the template is good - JavaCC or ANTRL for syntax validation. For the extreme, use a compiler to verify the correctness of the generated code.
- CodeGenerator - the parser of the configuration file and the driver gluing up everything.
- TemplateConfiguration - an list of template that can stores the properties specified in the XML file.
- Template - a class representing the state of a template.
- TemplateProcessor - processor that may perform validation or beautification of the generated code.
Example configuration XML:
<profile>The required attributes are
<property key="asdf" value="1" />
<property key="templateDir" value="x ${asdf}" />
<template class="org.sf.codejen.test.TestTemplate" a="${templateDir}">
<postProcessorFactory class="org.sf.codejen.test.TestProcessorFactory" b="jkl;" />
</template>
</profile>
- profile/property - key and value
- profile/template - class
- profile/template/postProcessorFactory - class
Also, if you are familiar with ANT, you can use ${propKey} style to access the property value.
No comments:
Post a Comment