Class FWSimComponentCodeGen
FWSimComponent from the template
codegen/FWSimComponent.javatemplate (class path) and a component definition. Supported definitions are
a tab separated CSV file (generateCodeCSV(Vector)), a simple XML file (generateCodeXML(Element)), an
AMEI model unit (generateCodeAmeiXML(Element, File)) and the first FWSimpleSimComponent of a solution
(
invalid reference
#generateCodeSimpleSimComponent(File)
The template contains placeholders (${classname}, ${package}, ${author},
${javadoc_class}, ${process}) and lines starting with FOR(constant),
FOR(input), FOR(out), FOR(state) or FOR(rate), which are repeated
for every variable of that content type. The process code of the definition is rewritten to access the generated
fields (assignments become setValue calls, variable reads getValue() calls).
An instance works on a single copy of the template, so it can generate only one class. The result is written with
writeCodeToFile(String).
- Author:
- Andreas Enders
-
Constructor Summary
ConstructorsConstructorDescriptionFWSimComponentCodeGen(File aJavaSourcePath) Creates the generator and loads the Java template. -
Method Summary
Modifier and TypeMethodDescriptionstatic FWSimVariable<?> createSimVariable(org.jdom2.Element aVarElement) Creates a typedFWSimVariablefrom an AMEI-style variable element.generateCodeAmeiXML(org.jdom2.Element aConfigElement, File aSourcePath) Generates the class from an AMEI model unit.generateCodeCSV(Vector<String> aConfigStrings) Generates the class from a tab separated definition.generateCodeSimpleSimComponent(File aSolutionFile, String aComponentId) Generates a class from aFWSimpleSimComponentof a solution, chosen by its id, with all its rules translated to Java (seeFWSimpleSimComponentCodeGen, package "net.simplace.usermodules").generateCodeXML(org.jdom2.Element aConfigElement) Generates the class from a simple XML definition: attributeclassholds the full class name, the optional childrenauthor,processandjavadoc-classthe respective texts, and the childvariablesthe variable elements (seecreateSimVariable(Element)).static voidEntry point: generates the class intosimplace_modules/srcfrom a definition file.writeCodeToFile(String aContentOfFile) Writes the generated code to the Java file determined by the lastgenerateCode...call.
-
Constructor Details
-
FWSimComponentCodeGen
Creates the generator and loads the Java template.- Parameters:
aJavaSourcePath- source folder the generated class is written to (the package path is appended)- Throws:
IOException- if the source folder does not exist or the template cannot be read
-
-
Method Details
-
generateCodeCSV
Generates the class from a tab separated definition. The lines are grouped in sections, each introduced by a line starting with#and ended by an empty line:#classname: full class name including package#author: author text#javadoc_class: lines of the class JavaDoc#process: lines of the process code- a header line containing
contenttype(e.g.#id contenttype datatype ...): the column names, followed by one line per variable. The column names are used as placeholders (${id},${unit}, ...) in theFOR(...)lines of the template.
- Parameters:
aConfigStrings- lines of the definition file- Returns:
- the content of the generated class
-
generateCodeSimpleSimComponent
public String generateCodeSimpleSimComponent(File aSolutionFile, String aComponentId) throws IOException Generates a class from aFWSimpleSimComponentof a solution, chosen by its id, with all its rules translated to Java (seeFWSimpleSimComponentCodeGen, package "net.simplace.usermodules"). Thesimcomponentelement replacing the simple component is logged.- Parameters:
aSolutionFile- solution file (.sol.xml)aComponentId- id of the simple component- Returns:
- the content of the generated class
- Throws:
IOException- if the solution cannot be loaded
-
generateCodeAmeiXML
public String generateCodeAmeiXML(org.jdom2.Element aConfigElement, File aSourcePath) throws IOException Generates the class from an AMEI model unit. The class name is taken from attributename, the package from attributemodelid(without its last part), author and class JavaDoc from theDescriptionchild (Authors, Institution, Abstract, Reference). The children ofInputsandOutputsbecome the variables (seecreateSimVariable(Element)). The process code is taken from theAlgorithmelement withlanguage="java", either from its text or, if empty, from the file given in its attributefilename.- Parameters:
aConfigElement- the model unit elementaSourcePath- directory the algorithm file name is resolved against- Returns:
- the content of the generated class
- Throws:
IOException- if the algorithm file cannot be read
-
generateCodeXML
Generates the class from a simple XML definition: attributeclassholds the full class name, the optional childrenauthor,processandjavadoc-classthe respective texts, and the childvariablesthe variable elements (seecreateSimVariable(Element)).- Parameters:
aConfigElement- root element of the definition- Returns:
- the content of the generated class
-
createSimVariable
Creates a typedFWSimVariablefrom an AMEI-style variable element.Evaluated attributes:
name,description,unit,format,datatype(aFWSimVariable.DATA_TYPEname or one of the AMEI namesSTRING,DOUBLELIST,INTLIST,STRINGLIST,DATELIST),min,max,defaultandmode(only for output-like content types). The value is taken from the element text or, for array types, fromvaluechildren.The content type is
outfor elements namedOutput, otherwiseinput. It is refined byinputtype="variable"withvariablecategorystateorrate(auxiliarykeeps the default)inputtype="parameter":privatforparametercategory="private", otherwiseconstant(constant, species, genotypic, soil)
- Parameters:
aVarElement- the variable element- Returns:
- the new variable
-
writeCodeToFile
-
main
Entry point: generates the class intosimplace_modules/srcfrom a definition file. The generator is chosen by the file name:.sol.xml(simple component of a solution),.unit.xml(AMEI model unit), other.xml(simple XML definition), otherwise CSV.- Parameters:
aStringArray- optional: path of the definition file; without argument a file dialog asks for it
-