4.2. Model Reference
MetaFactory supports both XML (recommended) and Yammel to contain the model data. This document describes the required structure of the file and its child elements.
To learn more on how to access and manipulate this file from within your code instructions, please check the Model API reference.
4.2.1. Model structure
The MetaFactory model file contains a ‘model’ element as root, which has one or more packages that are used to group data objects (entities). Every object can have attributes and references to other objects inside the model, which is equivalent in functionality to Java’s entity properties.
By using the model and code instructions, MetaFactory is able to generate (‘to MetaFactor’) the code for all the entities of the model. While executing code instructions MetaFactory reads the model by iterating through the element hierarchy. During these iterations the code instructions and model data are combined to create the actual output code. The hierarchy of the model data file is fixed and looks as follows in XML, which file would be ‘model.xml’.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<model> <metadata> <someproperty>property1</someproperty> </metadata> <package name="bookstore"> <metadata>...</metadata> <object name="book"> <attribute name="title" type="String" notnull="false"> <metadata>...</metadata> </attribute> <reference name="author" type="Person"> <metadata>...</metadata> </reference> </object> <object name="Person">...</object> </package> </model>
The required namespaces to use are shown in the example below:
1 2 3 4 5 6 7 8 9
<?xml version="1.0" encoding="UTF-8"?> <model xmlns="https://metafactory.io/xsd/v1/model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://metafactory.io/xsd/v1/model https://metafactory.io/xsd/v1/model.xsd"> ... </model>
The code instructions’ logic decides whether and how to use the attributes, references, and metadata of each object (entity). Quite often you may want to define code instructions with logic that requires extra information from the entities. You can add this meta-data to the model as ‘metadata’ that belong to either the package, object or attribute/reference level. With the metadata the code instructions can make decisions for how, when or in which case to generate code. Different code instructions are thus able to interpret the model differently.
For example one pattern might generate the java POJO’s (back-end) while the second pattern would generate the front-end in order to visualize and manipulate the data in the back-end. All these code instructions use the same model.