1.7. MetaFactory Project Structure

../_images/ProjectStructure.02.png

Fig. 1.9 Essential components of the Project structure

1.7.1. Project configuration

The project file is the central file for a MetaFactory project. It determines the name and location of the source files as well as the ones that will be generated. Among other things:

  • Name and location of the MetaModel file

  • Name and location of the Code Instruction file

  • Name and location of the Property file(s)

  • Locations of the output files

Once you have set up the project file, there will be very few changes afterwards.

1.7.2. MetaModel

The MetaModel file contains a tree with all data objects (entities). There is only one MetaModel file for the project which, for a large project with many objects, can lead to a huge file.

Each object can have attributes and references to other objects (the equivalent of Java’s entity properties). A Code Instruction can read out all objects and generate code for each of them, depending on the characteristics of the object with its attributes and references.

Loupe M MetaModel Reference

Metadata: MetaModel - Code Instruction interaction

To enhance the versatility of Code Instructions, Metadata can be added to the MetaModel. At generation time a Code Instruction iterates through the MetaModel and reads the metadata. Depending on the metadata and their value the Code Instruction may instruct the generation process differently.

Since any name and any type is allowed for metadata it is almost impossible for a developer to keep track of all metadata that can be used for a combination of any MetaModel and a number of Code Instructions.

Eye M MetaFactory solves this as follows:

  • A Code Instruction ignores all metadata, that it does not use.

  • If a MetaModel does not contain a metadatum that is needed by the Code Instruction, the Code Instruction will add that metadatum to the MetaModel. So then the Code Instruction actively modifies the MetaModel. Default value for the new metadatum is true.

    After the first time generation with the MetaModel-Code Instruction combination the developer checks the results and desides which of the new metadata are kept to true and which are to be set to false. After the second run the results should be as desired.

Loupe M Metadata

1.7.3. Code instructions

The project file mentions one Code Instruction file that serves as the root of a tree of Code Instructions. A Code Instruction can refer to other Code Instructions, within the project or in (external) libraries. For more advanced templating features a Code Instruction can refer to Freemarker or Velocity snippets.

Eye S For now MetaFactory provides an xml structure for the generation of Java and TypeScript code.

If you choose to generate other languages, you can still define the structure of your code inside a Freemarker/Velocity snippet that you use straight in the <body> element of your Code Instruction file.

Glasses M Code Instructions in XML contains all details regarding code instruction use.

1.7.4. Properties (optional)

Properties are a very versatile means for indirections and settings:

  • Project bound properties (often in a file like ‘template.properties’)

  • Local properties (often in a file like ‘local.properties’). This enables a user to use his/her own settings that overrule global project settings without changing them.

1.7.5. Naming

MetaFactory does not predefine any file or folder name. You are free to define them yourself in the project file.

Even the name of the project file is free to choose. MetaFactory will recognize it by its namespace.

BestPractice M Best Practice

Although you are free to choose, we recommend to use standard names. At MetaFactory generally we use:

Type

Name

Project file

metafactory.xml

MetaModel file

MetaModel.xml

Code Instruction file

codeinstruction.xml

Property files

template.properties (project)

local.properties (local)