Generator Implementation
When running the generator, the datamodel specification file is first parsed into an appropriate representation using class DmGenInputParser. The root of that representation is an instance of class DataModel. All references between parts of the data model, e.g. foreign key references, members of the import / export key, etc. are first recorded, and then in a second step resolved. Thus, the order of the different instances in the specification file is completely free.
The generator itself consists of two kinds of generator classes:
- File Generators generate individual source code files, e.g. given some particular entity
- Concept Generators are responsible for generating all source code files for one particular concept, e.g. all dto files; in other words it triggers the file generator at hand one time for each source code file it is supposed to generate.
As currently, only Java source files are generated, all concept generators inherit from AbstractJavaConceptGenerator, and all file generators from AbstractJavaFileGenerator. The latter offers a writer for the generated file and contains several helper methods for generating Java source code. In particular, it keeps track of the current indendation level, i.e. using the methods increasePrefix, decreasePrefix and writePrefix one can easily keep track of the indentation. Other helper methods include writing end of blocks, return statements, class declarations, setters and getters, and so on. Imports are generated by first adding all needed imports to a Set of Strings, possibly applying some logic for determining which imports are needed, and then using the corresponding helper methods for actually writing the imports.