-
Notifications
You must be signed in to change notification settings - Fork 0
Manifest
- Manifest list
- Manifest description
- Manifest Person example
The list of all your manifests must be referenced in an XML file.
The path to this file must be defined in the file config.json with the key manifestList (see [Installation] (https://github.com/jeanphilippe-p/ObjectManagerLib/wiki/Installation) page for more informations).
File look like :
<list>
<manifest type="person">relative/path/to/person/manifest.xml</manifest>
<manifest type="house">relative/path/to/house/manifest.xml</manifest>
<manifest type="town">relative/path/to/town/manifest.xml</manifest>
</list>
Each manifest node must have an attribut type (name of your model) and the path where we can found this manifest. The path must be relative to the folder that contain this XML file.
A Manifest is simply a list of properties
<manifest>
<properties>
...
</properties>
</manifest>
for the following explanations we will build a manifest Person like example.
There are two kind of properties : property and foreign property.
- A property is defined by the node
<property>, has a name and a type - A Foreign property is defined by the node
<foreignProperty>, has a name, a type, and refer another Object that has an existence elsewhere. For example, modelPersoncan have a foreign propertymother. A random person 'John' has a mother 'Jane' and 'Jane' can exist without 'John'.
<manifest>
<properties>
<property type="string">firstName</property>
<foreignProperty type="person">mother</foreignProperty>
</properties>
</manifest>
We want an id to find easily a person, so we need to add an id property.
An id property is a part of a model id. Commonly models have only one id property but you can define several id properties.
To define a property as id property, you just have to add an attribut id with value "1" (foreign properties can not be id)
<manifest>
<properties>
<property type="string" id="1">id</property>
</properties>
</manifest>
We want to have a property sex and this property can have only 2 values : male or female. So we must define an enumeration. (enumeration type must be a simple model)
<manifest>
<properties>
<property type="string">
<name>sex</name>
<enum>
<value>male</value>
<value>female</value>
</enum>
</property>
</properties>
</manifest>
We want to have a property middleNames. actually a person can have a second name, third name...
so we can define an array property to store these names.
<manifest>
<properties>
<property type="array">
<name>middleNames</name>
<values type="string" name="middleName"/>
</property>
</properties>
</manifest>
Now we want to have a property children, and a child is a person that can exists elsewhere so we can build an foreign property array.
<manifest>
<properties>
<foreignProperty type="array">
<name>children</name>
<values type="person" name="child"/>
</foreignProperty>
</properties>
</manifest>
We want to add a propery tatoos. A tatoo is not a simple thing, we must define a model to define it. But where define this model ? In manifestList.xml ? no because a tatoo exists only on Person body (on domestic animal too but to simply we ignore it). So we define a local property type (a local property type can contain another one).
<manifest>
<types>
<type id="tatoo">
<properties>
<property type="string">type</property>
<property type="string">bodyPart</property>
<foreignProperty type="person">tatooArtist</foreignProperty>
</properties>
</type>
<type id="example">
<properties>
<property type="string">thing</property>
<property type="tatoo">tatoo</property>
<properties>
</type>
</types>
<properties>
<property type="array">
<name>tatoos</name>
<values type="tatoo" name="tatoo"/>
</property>
<property type="example">example</property>
</properties>
</manifest>
If you have a large number of complex local models and they are not always used, you can define them in others manifests files.
- advantages :
- simplify the current manifest
- load local model only if needed (saving time when load current manifest)
- disadvantages :
- open manifest file to load local model when needed (one time by local model)
<manifest>
<manifests>
<manifest type="localThing">relative/path/to/local/manifest.xml</manifest>
<manifest type="localAnotherThing">relative/path/to/another/local/manifest.xml</manifest>
</manifests>
<properties>
<property type="localThing">thing</property>
<property type="localAnotherThing">anotherThing</property>
</properties>
</manifest>
<manifest>
<types>
<type id="tatoo">
<properties>
<property type="string">type</property>
<property type="string">bodyPart</property>
<foreignProperty type="person">tatooArtist</foreignProperty>
</properties>
</type>
</types>
<manifests/>
<properties>
<property type="string" id="1">id</property>
<property type="string">firstName</property>
<property type="string">lastName</property>
<property type="integer">age</property>
<foreignProperty type="place">birthPlace</foreignProperty>
<property type="string">
<name>sex</name>
<enum>
<value>male</value>
<value>female</value>
</enum>
</property>
<property type="array">
<name>tatoos</name>
<values type="tatoo" name="tatoo"/>
</property>
<foreignProperty type="person">father</foreignProperty>
<foreignProperty type="person">mother</foreignProperty>
<foreignProperty type="array">
<name>children</name>
<values type="person" name="child"/>
</foreignProperty>
<foreignProperty type="array">
<name>homes</name>
<values type="home" name="home"/>
</foreignProperty>
</properties>
</manifest>