There are 2 kind of files that are used as input for the beenerator:
- the driver script (a beanshell script so the typical extension is .bsh)
- the templates (at the moment only beanshell templates are supported so the extension is .bsht)
- For a quick start first download the newest -app.jar from the projectpage
.
- create a simple driver.bsh as described below.
- create the right template.bsht.
- java -jar beenerator-app-x.x.jar driver.bsh executes the driverscript.
- the beenerator should generate some outputfiles as described in the driver script.
- A typically driverscript first constructs one or more templates with the templater.
- template = templater.getTemplate(new FileReader("src/beenerator/gettersetter.bsht"));
- then it prepares the input for the template
- Then it applies the template to this object and saves the resulting file
- engine.applyTemplate(name, template, "output.txt");
- in the template differnt types of input can be written (someone who knows jsp will recognize the affinity).
- normal text without special signs ... this goes straight to the output (remember to escape the french quotation marks with a backslash).
- beanshell code within the french quotation marks. this can be used to form loops or everything else that must be done with the context. you can use the identifier context to access the object from the driver-script.
- beanshell output within french marks starting with =. the value of the object is printed into the result
Example:
«
for (int i=0; i<10; i++) {
»
Hallo «=context»
«
}
»
would result in a file with 10 times Hallo John Doe
- includes within french marks starting with a # (analog to c). following the # is a filename. the content of this file is inserted at the position of the include. Example:
«#test.bsht»
would include the file test.bsht.
- dynamicincludes within french marks starting with @. other templates can be included into the template. instead of being a normal include this is a little bit more like a methodcall into another template. the construct is called dynamic because you must use an expression to specify the filename. in the simplest case this is a string-expression like "test.bsht", but you can also use arbitrarly expresions to calculate the name or use a variable to specify the include. this construct comes in two tastes:
- real include «@"include.bsht"()» calls the other template with the whole context of the script passed to the other template. as a sequence every local variable is visible in the other template (methods or other structures are not visible).
- parametrized include «@"include.bsht"(localVariable>otherName)» maps the object localVariable to the name otherName in the included template. other local variables or methods are not visible in the included template.
Next